Set main choice between plat and dessert
This commit is contained in:
		
							parent
							
								
									4172a5f5fe
								
							
						
					
					
						commit
						d7276ca9f0
					
				
					 3 changed files with 15 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -11,16 +11,18 @@ class SearchForm(forms.Form):
 | 
			
		|||
        label="Texte", required=False
 | 
			
		||||
    )
 | 
			
		||||
    saison = forms.ChoiceField(choices=(('all', "Toutes"),) + Recette.SAISON_CHOICES)
 | 
			
		||||
    type_princ = forms.ChoiceField(
 | 
			
		||||
        label='',
 | 
			
		||||
        choices=(('plat', 'Plat principal'), ('dessert', 'Dessert')),
 | 
			
		||||
        widget=forms.RadioSelect
 | 
			
		||||
    )
 | 
			
		||||
    veget = forms.BooleanField(label="Végétarien", required=False)
 | 
			
		||||
    dessert = forms.BooleanField(label="Dessert", required=False)
 | 
			
		||||
 | 
			
		||||
    def search(self):
 | 
			
		||||
        if self.is_valid():
 | 
			
		||||
            qs = Recette.objects.all()
 | 
			
		||||
            qs = Recette.objects.filter(is_dessert=self.cleaned_data['type_princ'] == 'dessert')
 | 
			
		||||
            if self.cleaned_data['veget']:
 | 
			
		||||
                qs = qs.filter(is_veget=True)
 | 
			
		||||
            if self.cleaned_data['dessert']:
 | 
			
		||||
                qs = qs.filter(is_dessert=True)
 | 
			
		||||
            if self.cleaned_data['text']:
 | 
			
		||||
                terms = [t for t in self.cleaned_data['text'].split() if t not in STOP_WORDS]
 | 
			
		||||
                for term in terms:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ from .models import Recette
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
def home(request):
 | 
			
		||||
    form = SearchForm(request.POST or None)
 | 
			
		||||
    form = SearchForm(request.POST or None, initial={'type_princ': 'plat'})
 | 
			
		||||
    recettes = []
 | 
			
		||||
    num_results = None
 | 
			
		||||
    if request.method == 'POST':
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,12 +5,17 @@
 | 
			
		|||
 | 
			
		||||
{% block extrahead %}
 | 
			
		||||
<style>
 | 
			
		||||
ul.results { list-style-type: none; padding: 0; }
 | 
			
		||||
ul { list-style-type: none; padding: 0; }
 | 
			
		||||
input#id_text { padding: 10px 0; }
 | 
			
		||||
form#search-form p, form#search-form ul {
 | 
			
		||||
  display: inline-block;
 | 
			
		||||
  margin-right: 1em;
 | 
			
		||||
  vertical-align: top;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ul.results li { margin: 0; padding: 2px; }
 | 
			
		||||
ul.results li, ul.results li * { vertical-align: middle; }
 | 
			
		||||
ul.results li:nth-child(odd) { background-color: #eee; }
 | 
			
		||||
input#id_text { padding: 10px 0; }
 | 
			
		||||
form#search-form p { display: inline-block; margin-right: 1em; }
 | 
			
		||||
</style>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue