diff --git a/core/templates/core/blocks/navigation.haml b/core/templates/core/blocks/navigation.haml index 34b2686f631af3e694c9a2ebb6620a900a0d31e9..e61bcbd58e2c2706130f1c0aee207652d0922afa 100644 --- a/core/templates/core/blocks/navigation.haml +++ b/core/templates/core/blocks/navigation.haml @@ -1,4 +1,4 @@ %ul.nav-bar %li - %a{href: "{% url 'representatives:index' %}"} + %a{href: "{% url 'legislature:representatives_index' %}"} Representatives diff --git a/memopol_representatives/__init__.py b/legislature/__init__.py similarity index 100% rename from memopol_representatives/__init__.py rename to legislature/__init__.py diff --git a/memopol_representatives/admin.py b/legislature/admin.py similarity index 100% rename from memopol_representatives/admin.py rename to legislature/admin.py diff --git a/memopol_representatives/management/__init__.py b/legislature/management/__init__.py similarity index 100% rename from memopol_representatives/management/__init__.py rename to legislature/management/__init__.py diff --git a/memopol_representatives/management/commands/__init__.py b/legislature/management/commands/__init__.py similarity index 100% rename from memopol_representatives/management/commands/__init__.py rename to legislature/management/commands/__init__.py diff --git a/memopol_representatives/management/commands/fix_mandates_active.py b/legislature/management/commands/fix_mandates_active.py similarity index 100% rename from memopol_representatives/management/commands/fix_mandates_active.py rename to legislature/management/commands/fix_mandates_active.py diff --git a/memopol_representatives/models.py b/legislature/models.py similarity index 100% rename from memopol_representatives/models.py rename to legislature/models.py diff --git a/memopol_representatives/templates/memopol_representatives/__init__.py b/legislature/templates/legislature/__init__.py similarity index 100% rename from memopol_representatives/templates/memopol_representatives/__init__.py rename to legislature/templates/legislature/__init__.py diff --git a/legislature/templates/legislature/group_list.haml b/legislature/templates/legislature/group_list.haml new file mode 100644 index 0000000000000000000000000000000000000000..cdee98bd3735791f6b1ee3ecc0add11cbf623d7e --- /dev/null +++ b/legislature/templates/legislature/group_list.haml @@ -0,0 +1,6 @@ +- extends 'base.html' + +- block content + - for group in groups + {{ group.name }} + %br diff --git a/legislature/templates/legislature/representative_block.haml b/legislature/templates/legislature/representative_block.haml new file mode 100644 index 0000000000000000000000000000000000000000..99d7a2c37200d85a3bdcc804b3dc0a5c2516364e --- /dev/null +++ b/legislature/templates/legislature/representative_block.haml @@ -0,0 +1,8 @@ +%td< + %a{'href': "{% url 'legislature:representative_view_by_name' representative.full_name %}"} + %img{'src':'={representative.photo}'}/ + +%td< + %a{'href': "{% url 'legislature:representative_view_by_name' representative.full_name %}"} + ={representative.full_name}Â [={representative.country.code}] + diff --git a/memopol_representatives/templates/memopol_representatives/view.html b/legislature/templates/legislature/representative_view.html similarity index 96% rename from memopol_representatives/templates/memopol_representatives/view.html rename to legislature/templates/legislature/representative_view.html index 680c5ba5c101885ab71ffb5e3580b89ff14144db..c2ccec43d73a683052f629c5ce8786f4825a994f 100644 --- a/memopol_representatives/templates/memopol_representatives/view.html +++ b/legislature/templates/legislature/representative_view.html @@ -3,8 +3,6 @@ {% block content %} -<a href="{% url 'representatives:index' %}">Back</a> - <p style="float: left"> <img src="{{ representative.photo }}"> </p> diff --git a/memopol_representatives/templates/memopol_representatives/list.haml b/legislature/templates/legislature/representatives_list.haml similarity index 82% rename from memopol_representatives/templates/memopol_representatives/list.haml rename to legislature/templates/legislature/representatives_list.haml index b32776f371c13e0dbf6c3927746deb156e0f94db..6008a379914c9b25efb35e0cec20410b4d340639 100644 --- a/memopol_representatives/templates/memopol_representatives/list.haml +++ b/legislature/templates/legislature/representatives_list.haml @@ -1,7 +1,7 @@ - extends "base.html" - block content - - include 'memopol_representatives/search.html' + - include 'legislature/search.html' %p Number of representatives: {{ representative_num }} @@ -9,7 +9,7 @@ %table - for representative in representatives %tr - - include 'memopol_representatives/representative_block.html' + - include 'legislature/representative_block.html' .pagination %span.step-links diff --git a/memopol_representatives/templates/memopol_representatives/search.html b/legislature/templates/legislature/search.html similarity index 100% rename from memopol_representatives/templates/memopol_representatives/search.html rename to legislature/templates/legislature/search.html diff --git a/memopol_representatives/templatetags/__init__.py b/legislature/templatetags/__init__.py similarity index 100% rename from memopol_representatives/templatetags/__init__.py rename to legislature/templatetags/__init__.py diff --git a/memopol_representatives/templatetags/by_mandate_url.py b/legislature/templatetags/by_mandate_url.py similarity index 88% rename from memopol_representatives/templatetags/by_mandate_url.py rename to legislature/templatetags/by_mandate_url.py index eeab1cd43061c327de5412a0eafc47e882b0cc89..fef504eed63f6c83b02dd4ee8d0505cfb86eb358 100644 --- a/memopol_representatives/templatetags/by_mandate_url.py +++ b/legislature/templatetags/by_mandate_url.py @@ -14,6 +14,6 @@ def by_mandate_url(mandate): kwargs['search'] = mandate.group.name return reverse( - 'representatives:list', + 'legislature:representatives_by_mandate', kwargs=kwargs ) diff --git a/memopol_representatives/tests.py b/legislature/tests.py similarity index 100% rename from memopol_representatives/tests.py rename to legislature/tests.py diff --git a/legislature/urls.py b/legislature/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..ede9347263e0d174da39005cf2931167e0544936 --- /dev/null +++ b/legislature/urls.py @@ -0,0 +1,32 @@ +from django.conf.urls import patterns, url + +from . import views + +urlpatterns = patterns( + '', + url( + r'^representatives/?$', + views.representatives_index, + name='representatives_index' + ), + url( + r'^representatives/view/(?P<num>\d+)$', + views.representative_view, + name='representative_view' + ), + url( + r'^representatives/(?P<mandate_kind>\w+)/(?P<search>.+)$', + views.representatives_by_mandate, + name='representatives_by_mandate' + ), + url( + r'^representatives/(?P<name>.+)$', + views.representative_by_name, + name='representative_view_by_name' + ), + url( + r'^group/(?P<kind>\w+)$', + views.group_by_kind, + name='group_by_kind' + ) +) diff --git a/memopol_representatives/views.py b/legislature/views.py similarity index 75% rename from memopol_representatives/views.py rename to legislature/views.py index 70f2d52a1f9ba786fd09a238ab0331ec230a9b46..c00c83726a10457593a376c57043d677ef894fac 100644 --- a/memopol_representatives/views.py +++ b/legislature/views.py @@ -2,10 +2,10 @@ from django.shortcuts import render, get_object_or_404 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.db.models import Q -from representatives.models import Representative +from representatives.models import Representative, Group -def index(request): +def representatives_index(request): representative_list = _filter_by_search( request, Representative.objects.all() @@ -14,7 +14,28 @@ def index(request): return _render_list(request, representative_list) -def by_mandate(request, mandate_kind, mandate_abbr=None, mandate_name=None, search=None): +def representative_by_name(request, name): + representative = get_object_or_404( + Representative, full_name=name) + return render( + request, + 'legislature/representative_view.html', + {'representative': representative} + ) + + +def representative_view(request, num): + representative = get_object_or_404(Representative, pk=num) + + return render( + request, + 'legislature/representative_view.html', + {'representative': representative} + ) + + +def representatives_by_mandate(request, mandate_kind, mandate_abbr=None, + mandate_name=None, search=None): if mandate_abbr: representative_list = Representative.objects.filter( mandate__group__abbreviation=mandate_abbr, @@ -82,16 +103,18 @@ def _render_list(request, representative_list, num_by_page=50): context['representative_num'] = paginator.count return render( request, - 'memopol_representatives/list.html', + 'legislature/representatives_list.html', context ) -def view(request, num): - representative = get_object_or_404(Representative, pk=num) +def group_by_kind(request, kind): + groups = Group.objects.filter( + kind=kind + ) return render( request, - 'memopol_representatives/view.html', - {'representative': representative} + 'legislature/group_list.html', + {'groups': groups} ) diff --git a/memopol/urls.py b/memopol/urls.py index 10363734fa937d051df263ee2afedcbe22087332..045a2133bcffa157c37bad304bb5eeccc37006db 100644 --- a/memopol/urls.py +++ b/memopol/urls.py @@ -6,7 +6,7 @@ import core.views urlpatterns = patterns('', # Examples: # url(r'^$', 'memopol.views.home', name='home'), - url(r'^representatives/', include('memopol_representatives.urls', namespace='representatives')), url(r'^$', core.views.HomeView.as_view(), name='index'), + url('', include('legislature.urls', namespace='legislature')), url(r'^admin/', include(admin.site.urls)), ) diff --git a/memopol_representatives/templates/memopol_representatives/representative_block.haml b/memopol_representatives/templates/memopol_representatives/representative_block.haml deleted file mode 100644 index a492270663d6b477066013e2f6b32f0e3660d2c4..0000000000000000000000000000000000000000 --- a/memopol_representatives/templates/memopol_representatives/representative_block.haml +++ /dev/null @@ -1,13 +0,0 @@ -%td< - %a{'href': "{% url 'representatives.detail' ={representative.id} %}"} - %img{'src':'={representative.photo}'}/ - -%td< - %a{'href': "{% url 'representatives.detail' ={representative.id} %}"} - ={representative.full_name}Â [={representative.country.code}] - -%td< - - for mandate in representative.mandate_set.all - ={mandate.group.name} - %br/a - diff --git a/memopol_representatives/templates/memopol_representatives/representative_block.html b/memopol_representatives/templates/memopol_representatives/representative_block.html deleted file mode 100644 index f6325558f8d020b4d1b78a183634bc00547d6d2a..0000000000000000000000000000000000000000 --- a/memopol_representatives/templates/memopol_representatives/representative_block.html +++ /dev/null @@ -1,11 +0,0 @@ -<td> - <a href="{% url 'representatives:view' representative.id %}"> - <img src="{{ representative.photo }}" /> - </a> -</td> -<td> - <a href="{% url 'representatives:view' representative.id %}"> - {{ representative.full_name }} [{{ representative.country.code }}] - </a> -</td> - diff --git a/memopol_representatives/urls.py b/memopol_representatives/urls.py deleted file mode 100644 index ec698a4ee6fab31b7e0dd3e353a6c3cd794a2ef6..0000000000000000000000000000000000000000 --- a/memopol_representatives/urls.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.conf.urls import patterns, include, url - -from memopol_representatives import views - -urlpatterns = patterns( - '', - url(r'^$', views.index, name='index'), - url(r'^l/(?P<mandate_kind>\w+)/(?P<search>.+)$', - views.by_mandate, name='list'), - url(r'^view/(?P<num>\d+)$', views.view, name='view'), -)