generated from mwc/lab_server
	Checkpoint 3!
I wrote views so that all the specified routes work. I still have to implement the exceptions though. Stay tuned!
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								poem_server/.DS_Store
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								poem_server/.DS_Store
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -6,3 +6,29 @@ 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_random_line_about(params):
 | 
			
		||||
    return {'line': Line.objects.filter(clean_text__contains=params['topic']).random().text}
 | 
			
		||||
 | 
			
		||||
@route_get('lines/rhyme',args={'rhyme': str})
 | 
			
		||||
def get_random_line_that_rhymes_with(params):
 | 
			
		||||
    return {'line': Rhyme.get_rhyme_for_word(params['rhyme']).lines.exclude(clean_text__endswith=params['rhyme']).random().text}
 | 
			
		||||
 | 
			
		||||
@route_get('couplets/random',args={})
 | 
			
		||||
def get_random_couplet(params):
 | 
			
		||||
    first_line=Line.objects.random()
 | 
			
		||||
    second_line=first_line.rhyming_lines().random()
 | 
			
		||||
    return {'lines': [first_line.text,second_line.text]}
 | 
			
		||||
 | 
			
		||||
@route_get('couplets/about',args={'topic': str})
 | 
			
		||||
def get_random_couplet_about(params):
 | 
			
		||||
    first_line=Line.objects.filter(clean_text__contains=params['topic']).random()
 | 
			
		||||
    second_line=first_line.rhyming_lines().random()
 | 
			
		||||
    return {'lines': [first_line.text,second_line.text]}
 | 
			
		||||
 | 
			
		||||
@route_get('couplets/rhyme',args={'rhyme': str})
 | 
			
		||||
def get_random_couplet_that_rhymes_with(params):
 | 
			
		||||
    first_line = Rhyme.get_rhyme_for_word(params['rhyme']).lines.exclude(clean_text__endswith=params['rhyme']).random()
 | 
			
		||||
    second_line = first_line.rhyming_lines().random()
 | 
			
		||||
    return {'lines': [first_line.text,second_line.text]}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user