Skip to content

Commit

Permalink
Empêche de trouver des billets avec une recherche depuis la bibliothèque
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Gliech <[email protected]>
  • Loading branch information
gcodeur authored and sandhose committed Sep 2, 2017
1 parent bdb747a commit a577c1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions templates/tutorialv2/view/base_categories.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ <h2 class="has-separator">Parcourir</h2>
<label for="id_q" class="control-label">Recherche</label>
<input id="id_q" maxlength="150" name="q" required="required" type="search" placeholder="{% trans 'dans' %} {% if subcategory %}{{ subcategory.title|lower }}{% elif category %}{{ category.title|lower }}{% else %}{% trans 'la bibliothèque' %}{% endif %}…">
<input type="hidden" name="models" value="content">
<input type="hidden" name="from_library" value="on">
{% if category %}
<input type="hidden" name="category" value="{{ category.slug }}">
{% if subcategory %}
Expand Down
4 changes: 3 additions & 1 deletion zds/searchv2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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')
)
8 changes: 8 additions & 0 deletions zds/searchv2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a577c1d

Please sign in to comment.