generated from mwc/lab_server
app/views.py
This commit is contained in:
@@ -5,4 +5,32 @@ from random import choice, sample
|
||||
|
||||
@route_get('lines/random', args={})
|
||||
def get_random_line(params):
|
||||
return {'line': Line.objects.random().text}
|
||||
try:
|
||||
return {'line': Line.objects.random().text}
|
||||
except Line.DoesNotExist:
|
||||
raise NotFound("Line not found")
|
||||
|
||||
|
||||
@route_get('lines/about', args={'topic': str})
|
||||
def get_about_line(params):
|
||||
try:
|
||||
topic=params['topic']
|
||||
return {'line': Line.objects.filter(clean_text__contains=topic).random().text, 'topic':topic}
|
||||
except Line.DoesNotExist:
|
||||
raise NotFound("Line not found")
|
||||
except Line.BadRequest:
|
||||
raise BadRequest("Bad request")
|
||||
|
||||
@route_get('lines/rhyme', args={'word': str})
|
||||
def get_rhyme_line(params):
|
||||
try:
|
||||
word=params['word']
|
||||
return {'rhyme': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||
= " " + word).random().text, 'word':word}
|
||||
except Rhyme.DoesNotExist:
|
||||
raise NotFound("Rhyme not found")
|
||||
except Rhyme.BadRequest:
|
||||
raise BadRequest("Bad request")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user