Skip to content

Commit

Permalink
[#848] tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kardan committed Nov 6, 2014
1 parent de91dd8 commit a0741cc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
15 changes: 13 additions & 2 deletions akvo/rsr/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ class CheckboxMultipleChoiceField(MultipleChoiceField):
widget = widgets.CheckboxSelectMultiple


class ProjectFilter(django_filters.FilterSet):
class Meta:
model = Project
fields = ['primary_location__country__continent']

def __init__(self, *args, **kwargs):
super(ProjectFilter, self).__init__(*args, **kwargs)
# self.filters['primary_location__country__continent'].extra.update(
# {'empty_label': 'All Continents'})


class ProjectFilterSet(django_filters.FilterSet):
def filter_by_org(qs, org):
if org:
Expand Down Expand Up @@ -79,7 +90,7 @@ def __init__(self, *args, **kwargs):

self.filters['title'].field.widget.input_type = 'search'
self.filters['title'].field.widget.attrs = {'results': '5', 'autosave': 'project_search', 'placeholder': _(u'Project title or subtitle')}

choices = [('', _(u'All continents'))]
choices.extend(list(CONTINENTS))
self.filters['continent'].extra.update({'choices': choices})
Expand Down Expand Up @@ -115,7 +126,7 @@ def __init__(self, *args, **kwargs):
# else:
# organisations = Organisation.objects.all()
# self.filters['organisation'].extra.update({'empty_label': _(u'All partners')})

# No request (no partner site)
else:
organisations = Organisation.objects.all()
Expand Down
9 changes: 7 additions & 2 deletions akvo/rsr/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@

import json

from akvo.rsr.filters import remove_empty_querydict_items, ProjectFilterSet
from akvo.rsr.models import Project
from akvo.utils import pagination


from django.shortcuts import get_object_or_404, render


def directory(request):
projects_list = Project.objects.published()
f = ProjectFilterSet(remove_empty_querydict_items(request.GET) or None,
queryset = Project.objects.published())

page = request.GET.get('page')

page, paginator, page_range = pagination(page, projects_list, 10)
page, paginator, page_range = pagination(page, f.qs, 10)

context = {
'filter': f,
'page': page,
'paginator': paginator,
'page_range': page_range,
Expand Down
29 changes: 28 additions & 1 deletion akvo/templates/project_directory.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.html" %}

{% load i18n maps rsr_utils thumbnail humanize %}
{% load i18n maps rsr_utils thumbnail humanize bootstrap3 %}

{% block title %}{% trans 'Projects' %}{% endblock %}

Expand Down Expand Up @@ -180,6 +180,13 @@
</div>

<div id="filter" style="background-color: #383334; padding: 20px;">
<form action="" method="get" accept-charset="utf-8" name="filter_form">
{# csrf_token #}
{% bootstrap_form filter.form %}
<button type="submit" class="btn btn-default">Submit</button>
</form>

{% comment %}
<span style="color: #00AD9F; display: inline; text-transform: uppercase;">
continents</span><br />
<!-- Split button -->
Expand All @@ -201,6 +208,26 @@
<li><a href="#">South America</a></li>
</ul>
</div>
{% endcommnet %}

{% comment %}
<!-- Split button -->
<div class="btn-group">
<button type="button" class="btn">All</button>
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>

<ul class="dropdown-menu" role="menu">
{% for field in filter.form.continent.choices %}
<li><a href="#?continent={{ field }}">{{ field.label_tag }}</a></li>
{% endfor %}

</ul>
</div>
{% endcomment %}

</div>
</section>

Expand Down

0 comments on commit a0741cc

Please sign in to comment.