From d2564c1eee23acf36c6d4ac2b880989a5a63fb7c Mon Sep 17 00:00:00 2001
From: luxcem <af@laquadrature.net>
Date: Thu, 19 Mar 2015 14:47:42 +0100
Subject: [PATCH] renames app "memopol_representatives" to "legislature", this
 app handle representatives, committee, groups, mandates etc, unified urls

---
 core/templates/core/blocks/navigation.haml    |  2 +-
 .../__init__.py                               |  0
 .../admin.py                                  |  0
 .../management/__init__.py                    |  0
 .../management/commands/__init__.py           |  0
 .../commands/fix_mandates_active.py           |  0
 .../models.py                                 |  0
 .../templates/legislature}/__init__.py        |  0
 .../templates/legislature/group_list.haml     |  6 +++
 .../legislature/representative_block.haml     |  8 ++++
 .../legislature/representative_view.html      |  2 -
 .../legislature/representatives_list.haml     |  4 +-
 .../templates/legislature}/search.html        |  0
 .../templatetags/__init__.py                  |  0
 .../templatetags/by_mandate_url.py            |  2 +-
 .../tests.py                                  |  0
 legislature/urls.py                           | 32 +++++++++++++++
 .../views.py                                  | 39 +++++++++++++++----
 memopol/urls.py                               |  2 +-
 .../representative_block.haml                 | 13 -------
 .../representative_block.html                 | 11 ------
 memopol_representatives/urls.py               | 11 ------
 22 files changed, 82 insertions(+), 50 deletions(-)
 rename {memopol_representatives => legislature}/__init__.py (100%)
 rename {memopol_representatives => legislature}/admin.py (100%)
 rename {memopol_representatives => legislature}/management/__init__.py (100%)
 rename {memopol_representatives => legislature}/management/commands/__init__.py (100%)
 rename {memopol_representatives => legislature}/management/commands/fix_mandates_active.py (100%)
 rename {memopol_representatives => legislature}/models.py (100%)
 rename {memopol_representatives/templates/memopol_representatives => legislature/templates/legislature}/__init__.py (100%)
 create mode 100644 legislature/templates/legislature/group_list.haml
 create mode 100644 legislature/templates/legislature/representative_block.haml
 rename memopol_representatives/templates/memopol_representatives/view.html => legislature/templates/legislature/representative_view.html (96%)
 rename memopol_representatives/templates/memopol_representatives/list.haml => legislature/templates/legislature/representatives_list.haml (82%)
 rename {memopol_representatives/templates/memopol_representatives => legislature/templates/legislature}/search.html (100%)
 rename {memopol_representatives => legislature}/templatetags/__init__.py (100%)
 rename {memopol_representatives => legislature}/templatetags/by_mandate_url.py (88%)
 rename {memopol_representatives => legislature}/tests.py (100%)
 create mode 100644 legislature/urls.py
 rename {memopol_representatives => legislature}/views.py (75%)
 delete mode 100644 memopol_representatives/templates/memopol_representatives/representative_block.haml
 delete mode 100644 memopol_representatives/templates/memopol_representatives/representative_block.html
 delete mode 100644 memopol_representatives/urls.py

diff --git a/core/templates/core/blocks/navigation.haml b/core/templates/core/blocks/navigation.haml
index 34b2686f..e61bcbd5 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 00000000..cdee98bd
--- /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 00000000..99d7a2c3
--- /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 680c5ba5..c2ccec43 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 b32776f3..6008a379 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 eeab1cd4..fef504ee 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 00000000..ede93472
--- /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 70f2d52a..c00c8372 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 10363734..045a2133 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 a4922706..00000000
--- 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 f6325558..00000000
--- 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 }}&nbsp;[{{ representative.country.code }}]
-  </a>
-</td>
-
diff --git a/memopol_representatives/urls.py b/memopol_representatives/urls.py
deleted file mode 100644
index ec698a4e..00000000
--- 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'),
-)
-- 
GitLab