Commit d5337e8e44a8a4fadccbc35da06eb4f5c0d7176d

Authored by Luan
1 parent 2d13baf3

adding cumulative filters to thread lists #24

src/super_archives/templates/message-list.html
... ... @@ -27,9 +27,12 @@
27 27 <h4>{% trans "Lists" %}</h4>
28 28 <ul class="unstyled-list">
29 29 {% for list in lists %}
30   - <li {% if list.name == selected_list %} title="{% trans "Remove filter" %}" class="selected" {% endif %}>
31   - <span class="glyphicon {% if list.name == selected_list %}glyphicon-remove{% else %}glyphicon-chevron-right{% endif %}"></span> <a href="{% ifnotequal list.name selected_list %} {% append_to_get list=list.name p=1 %} {% else %} {% append_to_get list="" p=1 %}
32   - {% endifnotequal %}">{{ list.name }}</a></li>
  30 + {% with list.name|add:" "|add:selected_lists as list_name %}
  31 + <li {% if list.name in selected_lists %} title="{% trans "Remove filter" %}" class="selected" {% endif %}>
  32 + <span class="glyphicon {% if list.name in selected_lists %}glyphicon-remove{% else %}glyphicon-chevron-right{% endif %}"></span>
  33 + <a href="{% if not list.name in selected_lists %}{% append_to_get list=list_name p=1 %}{% else %}{% pop_from_get list=list.name %}{% endif %}">{{ list.name }}</a>
  34 + </li>
  35 + {% endwith %}
33 36 {% endfor %}
34 37 </ul>
35 38 </div>
... ...
src/super_archives/utils/url.py
... ... @@ -19,6 +19,7 @@ def pop_from_get(path, query=None, **kwargs):
19 19 if query_dict[key] == value:
20 20 del query_dict[key]
21 21 continue
22   - if not query_dict:
23   - return u'{}?q='.format(path)
  22 + if value in query_dict[key]:
  23 + aux = query_dict[key].split(value)
  24 + query_dict[key] = u''.join(aux).strip()
24 25 return u'{}?{}'.format(path, urllib.urlencode(query_dict))
... ...
src/super_archives/views.py
... ... @@ -60,8 +60,9 @@ def thread(request, mailinglist, thread_token):
60 60  
61 61  
62 62 def list_messages(request):
63   -
64   - selected_list = request.GET.get('list')
  63 + selected_lists = request.GET.get('list', [])
  64 + if selected_lists:
  65 + selected_lists = selected_lists.split()
65 66  
66 67 order_by = request.GET.get('order')
67 68 if order_by == 'hottest':
... ... @@ -69,9 +70,9 @@ def list_messages(request):
69 70 else:
70 71 threads = queries.get_latest_threads()
71 72  
72   - mail_list = request.GET.get('list')
  73 + mail_list = selected_lists
73 74 if mail_list:
74   - threads = threads.filter(mailinglist__name=mail_list)
  75 + threads = threads.filter(mailinglist__name__in=mail_list)
75 76  
76 77 paginator = Paginator(threads, 16)
77 78 try:
... ... @@ -86,7 +87,7 @@ def list_messages(request):
86 87 'lists': lists,
87 88 'n_results': paginator.count,
88 89 'threads': threads,
89   - 'selected_list': selected_list,
  90 + 'selected_lists': ' '.join(selected_lists) if selected_lists else '',
90 91 'order_data': settings.ORDERING_DATA,
91 92 }
92 93 return render(request, 'message-list.html', template_data)
... ...