From a577c1db536b0e62b91e5af14a26d4948ae835c3 Mon Sep 17 00:00:00 2001 From: gcodeur Date: Thu, 31 Aug 2017 17:30:41 +0200 Subject: [PATCH] =?UTF-8?q?Emp=C3=AAche=20de=20trouver=20des=20billets=20a?= =?UTF-8?q?vec=20une=20recherche=20depuis=20la=20biblioth=C3=A8que?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Quentin Gliech --- templates/tutorialv2/view/base_categories.html | 1 + zds/searchv2/forms.py | 4 +++- zds/searchv2/views.py | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/templates/tutorialv2/view/base_categories.html b/templates/tutorialv2/view/base_categories.html index 01caf0cd5f..b80fbb75b1 100644 --- a/templates/tutorialv2/view/base_categories.html +++ b/templates/tutorialv2/view/base_categories.html @@ -107,6 +107,7 @@

Parcourir

+ {% if category %} {% if subcategory %} diff --git a/zds/searchv2/forms.py b/zds/searchv2/forms.py index e2242d680f..27fe67b10a 100644 --- a/zds/searchv2/forms.py +++ b/zds/searchv2/forms.py @@ -39,6 +39,7 @@ class SearchForm(forms.Form): category = forms.CharField(widget=forms.HiddenInput, required=False) subcategory = forms.CharField(widget=forms.HiddenInput, required=False) + from_library = forms.CharField(widget=forms.HiddenInput, required=False) def __init__(self, *args, **kwargs): @@ -62,5 +63,6 @@ def __init__(self, *args, **kwargs): Field('q'), StrictButton('', type='submit', css_class='ico-after ico-search', title=_(u'Rechercher')), Field('category'), - Field('subcategory') + Field('subcategory'), + Field('from_library') ) diff --git a/zds/searchv2/views.py b/zds/searchv2/views.py index f34f7390c8..139f97d83b 100644 --- a/zds/searchv2/views.py +++ b/zds/searchv2/views.py @@ -127,6 +127,11 @@ def get_queryset(self): if self.search_form.cleaned_data['subcategory']: self.content_subcategory = self.search_form.cleaned_data['subcategory'] + # mark that contents must come from library if required + self.from_library = False + if self.search_form.cleaned_data['from_library'] == 'on': + self.from_library = True + # setting the different querysets (according to the selected models, if any) part_querysets = [] chosen_groups = self.search_form.cleaned_data['models'] @@ -176,6 +181,9 @@ def get_queryset_publishedcontents(self): query=self.search_query, fields=['title', 'description', 'categories', 'subcategories', 'tags', 'text']) + if self.from_library: + query &= Match(content_type='TUTORIAL') | Match(content_type='ARTICLE') + if self.content_category: query &= Match(categories=self.content_category)