generated from mwc/lab_server
Attempts to code /lines/about and /lines/rhyme
This commit is contained in:
@@ -6,3 +6,25 @@ from random import choice, sample
|
||||
@route_get('lines/random', args={})
|
||||
def get_random_line(params):
|
||||
return {'line': Line.objects.random().text}
|
||||
|
||||
@route_get('lines/about', args={'topic': str})
|
||||
def get_line_about_topic(params):
|
||||
try:
|
||||
lines = Line.objects.filter(clean_text__contains=params['topic'])
|
||||
if len(lines) == 1:
|
||||
return {'line' : lines[0], 'topic': params['topic']}
|
||||
else:
|
||||
return {'lines' : lines, 'topic': params['topic']}
|
||||
except Line.DoesNotExist:
|
||||
raise NotFound("No lines with that topic")
|
||||
|
||||
@route_get('lines/rhyme', args={'rhyme': str})
|
||||
def get_line_about_topic(params):
|
||||
try:
|
||||
lines = Rhyme.get_rhyme_for_word(params['rhyme']).lines.exclude(clean_text__endswith=params['rhyme'])
|
||||
if len(lines) == 1:
|
||||
return {'line' : lines[0], 'rhyme': params['rhyme']}
|
||||
else:
|
||||
return {'lines' : lines, 'rhyme': params['rhyme']}
|
||||
except Line.DoesNotExist:
|
||||
raise NotFound("No lines that rhyme")
|
||||
|
||||
Reference in New Issue
Block a user