Commit 4fc3fefd authored by okhin's avatar okhin 🚴

Filtering by flags is now working on the list view

parent ade863dc
Pipeline #2610 passed with stages
in 3 minutes and 11 seconds
......@@ -19,6 +19,52 @@
<div class="row">
<div class="col-md-12 white-bg shadow-effect">
<div class="row">
<div class="col-md-10 offset-1">
<header class="my-4">
<h2 class="header text-center">{{ _("Article flags")|upper }}</h3>
<ul class="nav nav-compressed">
<li class="nav-item col-md-4">
<div class="input-group">
<label for="archive">
{{ _("Archived") }}
</label>
<select name="archive" form="search-form">
<option value="both" {% if archive == "both" %} selected {% endif %}>{{ _("Both") }}</option>
<option value="true" {% if archive == "true" %} selected {% endif %}>{{ _("Yes") }}</option>
<option value="false" {% if archive == "false" %} selected {% endif %}>{{ _("No") }}</option>
</select>
</div>
</li>
<li class="nav-item col-md-4">
<div class="input-group">
<label for="quote">
{{ _("Quoting us") }}
</label>
<select name="quote" form="search-form">
<option value="both" {% if quote == "both" %} selected {% endif %}>{{ _("Both") }}</option>
<option value="true" {% if quote == "true" %} selected {% endif %}>{{ _("Yes") }}</option>
<option value="false" {% if quote == "false" %} selected {% endif %}>{{ _("No") }}</option>
</select>
</div>
</li>
<li class="nav-item col-md-4">
<div class="input-group">
<label for="speak">
{{ _("Speaking of us") }}
</label>
<select name="speak" form="search-form">
<option value="both" {% if speak == "both" %} selected {% endif %}>{{ _("Both") }}</option>
<option value="true" {% if speak == "true" %} selected {% endif %}>{{ _("Yes") }}</option>
<option value="false" {% if speak == "false" %} selected {% endif %}>{{ _("No") }}</option>
</select>
</div>
</li>
</ul>
</header>
</div>
</div>
<div class="row">
<div class="col-md-10 offset-1">
<header class="my-4">
......@@ -65,12 +111,12 @@
{% endif %}
<li class="nav-item ml-auto">
<form method="get" action="{% url 'rp:public-article-list' %}">
<form method="get" action="{% url 'rp:public-article-list' %}" name="search-form" id="search-form">
<div class="input-group">
<input type="search" placeholder="Rechercher" name="q" class="fa fa-search" value="{{ search }}" />
<button type="submit" class="btn btn-default input-group-addon"><i class="fa fa-search"></i></button>
</div>
</form>
</form>
</li>
<li class="nav-item">
......
......@@ -34,9 +34,9 @@ class TestArticle(TestCase):
assert article.status == 'NEW'
assert article.score == 1
article_again = Article.add_new_url(url='https://www.example.org/article')
assert article_again.status == 'NEW'
assert article_again.score == 2
article2 = Article.add_new_url(url='https://www.example.org/article')
assert article2.status == 'NEW'
assert article2.score == 2
def test_flags(self):
assert not self.article.archive
......@@ -126,6 +126,36 @@ class TestArticleViews(TestCase):
r = self.client.get('/rp/', {'q': 'Gargamel was here'})
assert len(r.context['article_list']) == 0
def test_search_view_archived(self):
archive = ArticleFactory(archive=True, lang='FR')
r = self.client.get('/rp/', {'q': '', 'archive': 'true'})
assert len(r.context['article_list']) == 1
assert r.context['article_list'][0] == archive
r = self.client.get('/rp/', {'archive': 'false'})
assert len(r.context['article_list']) == 0
def test_search_view_speakd(self):
speak = ArticleFactory(speak=True, lang='FR')
r = self.client.get('/rp/', {'q': '', 'speak': 'true'})
assert len(r.context['article_list']) == 1
assert r.context['article_list'][0] == speak
r = self.client.get('/rp/', {'speak': 'false'})
assert len(r.context['article_list']) == 0
def test_search_view_quoted(self):
quote = ArticleFactory(quote=True, lang='FR')
r = self.client.get('/rp/', {'q': '', 'quote': 'true'})
assert len(r.context['article_list']) == 1
assert r.context['article_list'][0] == quote
r = self.client.get('/rp/', {'quote': 'false'})
assert len(r.context['article_list']) == 0
def test_detail_view(self):
# Let's find a published article
self.client.force_login(user=self.user)
......
from url import URL
import re
URL_TRACKERS = [
# UTM
......
......@@ -26,8 +26,10 @@ class ArticleList(ListView):
paginate_by = 10
template_name = "rp/article_list_public.html"
filter_lang = None
filter_tag = None
archive = 'false'
quote = 'both'
speak = 'both'
def get_queryset(self):
if self.filter_lang in ["EN", "FR"]:
......@@ -35,6 +37,29 @@ class ArticleList(ListView):
else:
qs = Article.objects.filter()
# Tags filtering
self.quote = self.request.GET.get('quote', self.quote)
self.speak = self.request.GET.get('speak', self.speak)
self.archive = self.request.GET.get('archive', self.archive)
if self.speak != 'both':
if self.speak == 'true':
qs = qs.filter(speak=True)
else:
qs = qs.filter(speak=False)
if self.quote != 'both':
if self.quote == 'true':
qs = qs.filter(quote=True)
else:
qs = qs.filter(quote=False)
if self.archive != 'both':
if self.archive == 'true':
qs = qs.filter(archive=True)
else:
qs = qs.filter(archive=False)
search_keywords = self.request.GET.get('q', '')
if search_keywords != '':
qs = qs.filter(Q(title__icontains=search_keywords)
......@@ -54,6 +79,9 @@ class ArticleList(ListView):
qs = qs.order_by('-num_times')
context["tags"] = qs
context["search"] = self.request.GET.get('q', '')
context["archive"] = self.request.GET.get('archive', self.archive)
context["speak"] = self.request.GET.get('speak', self.speak)
context["quote"] = self.request.GET.get('quote', self.quote)
return context
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment