Skip to content

Commit

Permalink
[#1025 #1075] Merged '1025_document_upload' into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Feb 11, 2015
2 parents 64ab816 + 386a368 commit 634ef3a
Show file tree
Hide file tree
Showing 11 changed files with 4,985 additions and 55 deletions.
28 changes: 18 additions & 10 deletions akvo/rsr/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@


import django_filters
from .models import Project, Organisation, Category, FocusArea, ProjectUpdate
from .models import Project, Organisation, Category, ProjectUpdate
from .iso3166 import CONTINENTS
from .iati.codelists.codelists_v104 import SECTOR_CATEGORY

ANY_CHOICE = (('', 'All'), )


def sectors():
sectors_list = []
for code in SECTOR_CATEGORY:
if Project.objects.filter(sectors__sector_code=code[0]):
code_list = list(code[:2])
code_list[1] = code_list[1].title()
sectors_list.append(tuple(code_list))
return sectors_list


def remove_empty_querydict_items(request_get):
# querydicts are immutable
getvars = request_get.copy()
Expand All @@ -36,14 +47,11 @@ class ProjectFilter(django_filters.FilterSet):
label='location',
name='primary_location__country__continent_code')

# Focus areas
focus_area = django_filters.ChoiceFilter(
choices=([('', 'All')] +
list(FocusArea.objects.all().values_list('id', 'name',
flat=False))[1:]),
label='focus area',
name='categories__focus_area__id',
initial='All')
sector = django_filters.ChoiceFilter(
initial='All',
choices=([('', 'All')] + sectors()),
label='sector',
name='sectors__sector_code')

status = django_filters.ChoiceFilter(
initial='All',
Expand All @@ -68,7 +76,7 @@ def get_orgs():
class Meta:
model = Project
fields = ['status', 'continent', 'organisation', 'category',
'focus_area', 'title', ]
'sector', 'title', ]


class ProjectUpdateFilter(django_filters.FilterSet):
Expand Down
4,279 changes: 4,279 additions & 0 deletions akvo/rsr/iati/codelists/codelists_v201.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions akvo/rsr/iati/iati_codelist_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"1.03": "http://codelists103.archive.iatistandard.org/data/",
"1.04": "http://iatistandard.org/104/codelists/downloads/clv2/",
"1.05": "http://iatistandard.org/105/codelists/downloads/clv2/",
"2.01": "http://iatistandard.org/201/codelists/downloads/clv2/",
}


Expand Down
628 changes: 628 additions & 0 deletions akvo/rsr/migrations/0081_sector_cleanup.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion akvo/rsr/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,4 @@
post_delete.connect(update_project_funding, sender=Invoice)
post_delete.connect(update_project_funding, sender=Partnership)

post_save.connect(create_api_key, sender=User)
post_save.connect(create_api_key, sender=User)
5 changes: 5 additions & 0 deletions akvo/rsr/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ def iati_default_tied_status(self):
else:
return ""

def sector_categories_codes(self):
from .sector import Sector
sector_categories = Sector.objects.filter(project=self, vocabulary='2')
return [sector.iati_sector_codes for sector in sector_categories]

def sector_categories(self):
from .sector import Sector
sector_categories = Sector.objects.filter(project=self, vocabulary='2')
Expand Down
8 changes: 8 additions & 0 deletions akvo/rsr/models/sector.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class Sector(models.Model):
def __unicode__(self):
return self.iati_sector()

def iati_sector_codes(self):
if self.sector_code and (self.vocabulary == '1' or self.vocabulary == 'DAC'):
return self.sector_code, dict([code[:2] for code in codelists.SECTOR])[self.sector_code]
elif self.sector_code and (self.vocabulary == '2' or self.vocabulary == 'DAC-3'):
return self.sector_code, dict([code[:2] for code in codelists.SECTOR_CATEGORY])[self.sector_code]
else:
return "", ""

def iati_sector(self):
if self.sector_code and (self.vocabulary == '1' or self.vocabulary == 'DAC'):
return dict([code[:2] for code in codelists.SECTOR])[self.sector_code]
Expand Down
2 changes: 1 addition & 1 deletion akvo/rsr/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def directory(request):

# Instead of true or false, adhere to bootstrap3 class names to simplify
show_filters = "in"
available_filters = ['continent', 'status', 'organisation', 'focus_area', ]
available_filters = ['continent', 'status', 'organisation', 'sector', ]
if frozenset(qs.keys()).isdisjoint(available_filters):
show_filters = ""

Expand Down
5 changes: 3 additions & 2 deletions akvo/templates/organisation_directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
<a class="btn showFilters menu-toggle"><i class="fa fa-toggle-off"></i> Advanced filters</a>
</div>
</div>
{% if q %}
<div><a href="{% url 'organisation-directory' %}" class="btn"><i class="fa fa-times"></i> Reset all filters</a></div>
{% endif %}
</div>
{#</form>#}
</div>
Expand All @@ -37,11 +39,10 @@
<div class="btn-group">
{% bootstrap_field filter.form.continent %}
</div>
</div>
</div>
<div>
<nav>
<ul class="nav nav-pills nav-stacked">
<li><a href="{% url 'organisation-directory' %}" class="btn btn-default"><i class="fa fa-times"></i> Reset all filters</a></li>
<li><a class="showFilters menu-toggle text-center"><i class="fa fa-toggle-off"></i> Close this</a></li>
</ul>
</nav>
Expand Down
79 changes: 39 additions & 40 deletions akvo/templates/project_directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<section id="map" class="touch-navbar">
{% coll_map page '100%' '100%' %}
</section>
<section id="search-filter">
<form id="filterForm" action="" method="get" accept-charset="uft-8" class="searchContainer">
<form id="filterForm" action="" method="get" accept-charset="uft-8" class="searchContainer">
<section id="search-filter">
<div class="container-fluid">
<div id="search" class="verticalPadding">
<p>{% trans "Refine the project list below by searching by name, organisation or sector" %}</p>
Expand All @@ -20,47 +20,48 @@
</span>
</div>
<a class="btn showFilters menu-toggle"><i class="fa fa-toggle-off"></i> Advanced filters</a>
</div>
</div>
{% if q %}
<div><a href="{% url 'project-directory' %}" class="btn"><i class="fa fa-times"></i> Reset all filters</a></div>
{% endif %}
</div>
</div>
</div>
</section>
<div id="wrapper">
<aside id="sidebar-wrapper" class="{ show_filters }}">
<div id="filter" class="">
<div>
<div class="btn-group">
{% bootstrap_field filter.form.continent %}
</div>
</div>
<div>
<div class="btn-group">
{% bootstrap_field filter.form.status %}
</div>
</div>
<div>
<div class="btn-group">
{% bootstrap_field filter.form.organisation %}
</div>
</div>
<div>
<div class="btn-group">
{% bootstrap_field filter.form.focus_area %}
</section>
<div id="wrapper">
<aside id="sidebar-wrapper" class="{{ show_filters }}">
<div id="filter" class="">
<div>
<div class="btn-group">
{% bootstrap_field filter.form.continent %}
</div>
</div>
<div>
<div class="btn-group">
{% bootstrap_field filter.form.status %}
</div>
</div>
<div>
<div class="btn-group">
{% bootstrap_field filter.form.organisation %}
</div>
</div>
<div>
<div class="btn-group">
{% bootstrap_field filter.form.sector %}
</div>
</div>
<div>
<nav>
<ul class="nav nav-pills nav-stacked">
<li><a class="showFilters menu-toggle text-center"><i class="fa fa-toggle-off"></i> Close this</a></li>
</ul>
</nav>
</div>
</div>
</div>
<div>
<nav>
<ul class="nav nav-pills nav-stacked">
<li><a href="{% url 'project-directory' %}" class="btn btn-default"><i class="fa fa-times"></i> Reset all filters</a></li>
<li><a class="showFilters menu-toggle text-center"><i class="fa fa-toggle-off"></i> Close this</a></li>
</ul>
</nav>
</div>
</aside>
</div>
</aside>
</div>
</form>
</form>

<div class="container-fluid">
<div class="row center-text">
Expand Down Expand Up @@ -102,7 +103,7 @@ <h1><a href="{% url 'project-main' p.id %}">{{p.title}}</a></h1>
<div class="col-sm-3 hidden-xs hidden-sm">
{% if p.sector_categories %}
<h4 class="detailedInfo">{% trans "Sectors" %}</h4>
<p>{% for sector in p.sector_categories %}{% if not forloop.first %}, {% endif %}{{sector|title}}{% endfor %}</p>
<p>{% for sector in p.sector_categories_codes %}{% if not forloop.first %}<br>{% endif %}<a href="{% url 'project-directory' %}?sector={{sector.0}}">{{sector.1|title}}</a>{% endfor %}</p>
{% endif %}
<h4 class="detailedInfo">{% trans "Status" %}</h4>
<p class="complete">{{p.get_status_display}}</p>
Expand All @@ -113,8 +114,6 @@ <h4 class="detailedInfo">{% trans "Finance" %}</h4>
</div>
<div class="col-xs-7 col-xs-offset-5 col-sm-6 col-sm-offset-0 visible-xs-block visible-sm">
<p class="small">
<span class="detailedInfo">{% trans "Focus Areas" %}</span>
{% for area in p.focus_areas %}<a href="#">{{area.name}}</a> {% endfor %}<br>
<span class="detailedInfo">{% trans "Sectors" %}</span> ? <a href="#" class="small">+4 more</a><br>
<span class="detailedInfo">{% trans "Status" %}</span> {{p.get_status_display}}<br>
<span class="detailedInfo">{% trans "Finance" %}</span>
Expand Down
3 changes: 2 additions & 1 deletion akvo/templates/update_directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
</div>
<a class="btn showFilters menu-toggle"><i class="fa fa-toggle-off"></i> Advanced filters</a>
</div>
{% if q %}
<div><a href="{% url 'update-directory' %}" class="btn"><i class="fa fa-times"></i> Reset all filters</a></div>
{% endif %}
</div>
{#</form>#}
</div>
Expand All @@ -39,7 +41,6 @@
<div>
<nav>
<ul class="nav nav-pills nav-stacked">
<li><a href="{% url 'update-directory' %}" class="btn btn-default"><i class="fa fa-times"></i> Reset all filters</a></li>
<li><a class="showFilters menu-toggle text-center"><i class="fa fa-toggle-off"></i> Close this</a></li>
</ul>
</nav>
Expand Down

0 comments on commit 634ef3a

Please sign in to comment.