From 5bc7f37040bb341689e634e6449c8aa7470a3f93 Mon Sep 17 00:00:00 2001 From: Sylvain Boissel Date: Sun, 7 Aug 2016 18:34:55 +0200 Subject: [PATCH] Separate representative details into subpages --- README.md | 2 +- .../test_mandates_display.html | 921 -------------- .../test_positions_display.html | 36 - .../test_votes_display.html | 67 - memopol/tests/base.py | 1 + ...veDetailTest.test_mandates_display.content | 1085 +++++++++++++++++ ...eDetailTest.test_mandates_display.metadata | 3 + ...eDetailTest.test_positions_display.content | 274 +++++ ...DetailTest.test_positions_display.metadata | 3 + ...ativeDetailTest.test_votes_display.content | 270 ++++ ...tiveDetailTest.test_votes_display.metadata | 3 + memopol/tests/test_representatives_detail.py | 28 +- memopol/urls.py | 19 + memopol/views/representative_detail.py | 19 - memopol/views/representative_mandates.py | 29 + memopol/views/representative_positions.py | 40 + memopol/views/representative_votes.py | 42 + .../representatives/_representative_menu.haml | 15 + .../representative_detail.haml | 68 +- .../representative_mandates.haml | 35 + .../representative_positions.haml | 32 + .../representatives/representative_votes.haml | 41 + 22 files changed, 1918 insertions(+), 1115 deletions(-) delete mode 100644 memopol/tests/RepresentativeDetailTest/test_mandates_display.html delete mode 100644 memopol/tests/RepresentativeDetailTest/test_positions_display.html delete mode 100644 memopol/tests/RepresentativeDetailTest/test_votes_display.html create mode 100644 memopol/tests/response_fixtures/RepresentativeDetailTest.test_mandates_display.content create mode 100644 memopol/tests/response_fixtures/RepresentativeDetailTest.test_mandates_display.metadata create mode 100644 memopol/tests/response_fixtures/RepresentativeDetailTest.test_positions_display.content create mode 100644 memopol/tests/response_fixtures/RepresentativeDetailTest.test_positions_display.metadata create mode 100644 memopol/tests/response_fixtures/RepresentativeDetailTest.test_votes_display.content create mode 100644 memopol/tests/response_fixtures/RepresentativeDetailTest.test_votes_display.metadata create mode 100644 memopol/views/representative_mandates.py create mode 100644 memopol/views/representative_positions.py create mode 100644 memopol/views/representative_votes.py create mode 100644 templates/representatives/_representative_menu.haml create mode 100644 templates/representatives/representative_mandates.haml create mode 100644 templates/representatives/representative_positions.haml create mode 100644 templates/representatives/representative_votes.haml diff --git a/README.md b/README.md index 3d2ad46..c78eb63 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ [![Build Status](https://travis-ci.org/political-memory/political_memory.svg?branch=master)](https://travis-ci.org/political-memory/political_memory) [![codecov.io](https://codecov.io/github/political-memory/political_memory/coverage.svg?branch=master)](https://codecov.io/github/political-memory/political_memory?branch=master) -[Manual](http://memopol.readthedocs.io/en/master/index.html) +[Manual](http://memopol.readthedocs.io/en/master/index.html) \ No newline at end of file diff --git a/memopol/tests/RepresentativeDetailTest/test_mandates_display.html b/memopol/tests/RepresentativeDetailTest/test_mandates_display.html deleted file mode 100644 index 1fae20a..0000000 --- a/memopol/tests/RepresentativeDetailTest/test_mandates_display.html +++ /dev/null @@ -1,921 +0,0 @@ -

Mandates

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Substitute - - Delegation for relations with Palestine - - - - - 14/07/2014 - - - - present - - European Parliament
Member - - Delegation for relations with South Africa - - - - - 14/07/2014 - - - - present - - European Parliament
Member - - Delegation to the Parliamentary Assembly of the Union for the Mediterranean - - - - - 14/07/2014 - - - - present - - European Parliament
Substitute - - Committee on Culture and Education - - CULT - - - - - 08/07/2014 - - - - present - - European Parliament
Member - - Committee on Legal Affairs - - JURI - - - - - 01/07/2014 - - - - present - - European Parliament
Member - - Committee on Women's Rights and Gender Equality - - FEMM - - - - - 01/07/2014 - - - - present - - European Parliament
- - United Kingdom - - GB - - - - - 01/07/2014 - - - - present - - Labour Party
Member - - Group of the Progressive Alliance of Socialists and Democrats in the European Parliament - - SD - - - - - 01/07/2014 - - - - present - - European Parliament
Member - - Committee on Culture and Education - - CULT - - - - - 19/01/2012 - - - - 30/06/2014 - - European Parliament
Substitute - - Committee on Legal Affairs - - JURI - - - - - 19/01/2012 - - - - 30/06/2014 - - European Parliament
Member - - Committee on Women's Rights and Gender Equality - - FEMM - - - - - 19/01/2012 - - - - 30/06/2014 - - European Parliament
Substitute - - Delegation for relations with Canada - - - - - 16/09/2009 - - - - 30/06/2014 - - European Parliament
- - United Kingdom - - GB - - - - - 14/07/2009 - - - - 30/06/2014 - - Labour Party
Member - - Group of the Progressive Alliance of Socialists and Democrats in the European Parliament - - SD - - - - - 14/07/2009 - - - - 30/06/2014 - - European Parliament
Substitute - - Committee on Legal Affairs - - JURI - - - - - 20/09/2010 - - - - 18/01/2012 - - European Parliament
Member - - Committee on Culture and Education - - CULT - - - - - 16/07/2009 - - - - 18/01/2012 - - European Parliament
Member - - Committee on Women's Rights and Gender Equality - - FEMM - - - - - 16/07/2009 - - - - 18/01/2012 - - European Parliament
Substitute - - Committee on Regional Development - - REGI - - - - - 16/07/2009 - - - - 19/09/2010 - - European Parliament
Substitute - - Committee on Culture and Education - - CULT - - - - - 31/01/2007 - - - - 13/07/2009 - - European Parliament
Member - - Committee on Industry, Research and Energy - - ITRE - - - - - 31/01/2007 - - - - 13/07/2009 - - European Parliament
Substitute - - Committee on Women's Rights and Gender Equality - - FEMM - - - - - 31/01/2007 - - - - 13/07/2009 - - European Parliament
Member - - Delegation to the EU-Former Yugoslav Republic of Macedonia Joint Parliamentary Committee - - - - - 15/09/2004 - - - - 13/07/2009 - - European Parliament
Substitute - - Delegation to the Euro-Mediterranean Parliamentary Assembly - - - - - 15/09/2004 - - - - 13/07/2009 - - European Parliament
Substitute - - Delegation to the EU-Turkey Joint Parliamentary Committee - - - - - 15/09/2004 - - - - 13/07/2009 - - European Parliament
- - United Kingdom - - GB - - - - - 20/07/2004 - - - - 13/07/2009 - - Labour Party
Member - - Socialist Group in the European Parliament - - PSE - - - - - 20/07/2004 - - - - 13/07/2009 - - European Parliament
Substitute - - Committee on Culture and Education - - CULT - - - - - 15/01/2007 - - - - 30/01/2007 - - European Parliament
Member - - Committee on the Environment, Public Health and Food Safety - - ENVI - - - - - 15/01/2007 - - - - 30/01/2007 - - European Parliament
Substitute - - Committee on Women's Rights and Gender Equality - - FEMM - - - - - 15/01/2007 - - - - 30/01/2007 - - European Parliament
Substitute - - Committee on Culture and Education - - CULT - - - - - 21/07/2004 - - - - 14/01/2007 - - European Parliament
Member - - Committee on the Environment, Public Health and Food Safety - - ENVI - - - - - 21/07/2004 - - - - 14/01/2007 - - European Parliament
Substitute - - Committee on Women's Rights and Gender Equality - - FEMM - - - - - 21/07/2004 - - - - 14/01/2007 - - European Parliament
Member - - Committee on Economic and Monetary Affairs - - ECON - - - - - 17/01/2002 - - - - 19/07/2004 - - European Parliament
- - United Kingdom - - GB - - - - - 17/02/2000 - - - - 19/07/2004 - - Labour Party
Member - - Group of the Party of European Socialists - - PSE - - - - - 17/02/2000 - - - - 19/07/2004 - - European Parliament
Member - - Delegation to the EU-Cyprus Joint Parliamentary Committee - - - - - 07/02/2002 - - - - 30/04/2004 - - European Parliament
Substitute - - Delegation to the EU-Malta Joint Parliamentary Committee - - - - - 07/02/2002 - - - - 30/04/2004 - - European Parliament
Member - - Delegation to the EU-Cyprus Joint Parliamentary Committee - - - - - 11/04/2000 - - - - 14/01/2002 - - European Parliament
Substitute - - Committee on Employment and Social Affairs - - EMPL - - - - - 01/03/2000 - - - - 14/01/2002 - - European Parliament
diff --git a/memopol/tests/RepresentativeDetailTest/test_positions_display.html b/memopol/tests/RepresentativeDetailTest/test_positions_display.html deleted file mode 100644 index 4713105..0000000 --- a/memopol/tests/RepresentativeDetailTest/test_positions_display.html +++ /dev/null @@ -1,36 +0,0 @@ -
-

Public positions

- - - - - - - - - - - - - - - - diff --git a/memopol/tests/RepresentativeDetailTest/test_votes_display.html b/memopol/tests/RepresentativeDetailTest/test_votes_display.html deleted file mode 100644 index 5767ab5..0000000 --- a/memopol/tests/RepresentativeDetailTest/test_votes_display.html +++ /dev/null @@ -1,67 +0,0 @@ -

Votes

- -
24/11/2010 - - first-validated - - - - http://example.com/first-validated - - -
24/11/2010 - - other-validated - - - - http://example.com/second-validated - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TitleDate - Memopol recommendation - - Representative vote - - Score - -
Stop acta !Nov.24,2010 - - - - - -6 - - -
Stop acta !Nov.24,2010 - - - - - -5 - - -
Stop acta !Nov.24,2010 - - - - - 4 - - -
diff --git a/memopol/tests/base.py b/memopol/tests/base.py index f1e39db..0a08f04 100644 --- a/memopol/tests/base.py +++ b/memopol/tests/base.py @@ -42,6 +42,7 @@ class UrlGetTestMixin(object): class ResponseDiffMixin(object): def responsediff_test(self, url, numQueries): + self.client.cookies['csrftoken'] = 'csrftoken' with self.assertNumQueries(numQueries): response = self.client.get(url) diff --git a/memopol/tests/response_fixtures/RepresentativeDetailTest.test_mandates_display.content b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_mandates_display.content new file mode 100644 index 0000000..3c083ae --- /dev/null +++ b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_mandates_display.content @@ -0,0 +1,1085 @@ + + + + + + + + Home - Political Memory + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +

Mary HONEYBALL

+
+
+

+
+
+ + + + + + + + + + + + + + + + + + + + + +
Score + -7 +
Chamber + European Parliament +
Country + United Kingdom +
Party + Member of Group of the Progressive Alliance of Socialists and Democrats in the European Parliament +
BiographyBorn in Weymouth the + 12/11/1952 + (F)
+
+
+
+ + +
+
+ + + + + +
+

Mandates

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Substitute + + Delegation for relations with Palestine + + + + + 14/07/2014 + + + + present + + European Parliament
Member + + Delegation for relations with South Africa + + + + + 14/07/2014 + + + + present + + European Parliament
Member + + Delegation to the Parliamentary Assembly of the Union for the Mediterranean + + + + + 14/07/2014 + + + + present + + European Parliament
Substitute + + Committee on Culture and Education + + CULT + + + + + 08/07/2014 + + + + present + + European Parliament
Member + + Committee on Legal Affairs + + JURI + + + + + 01/07/2014 + + + + present + + European Parliament
Member + + Committee on Women's Rights and Gender Equality + + FEMM + + + + + 01/07/2014 + + + + present + + European Parliament
+ + United Kingdom + + GB + + + + + 01/07/2014 + + + + present + + Labour Party
Member + + Group of the Progressive Alliance of Socialists and Democrats in the European Parliament + + SD + + + + + 01/07/2014 + + + + present + + European Parliament
Member + + Committee on Culture and Education + + CULT + + + + + 19/01/2012 + + + + 30/06/2014 + + European Parliament
Substitute + + Committee on Legal Affairs + + JURI + + + + + 19/01/2012 + + + + 30/06/2014 + + European Parliament
Member + + Committee on Women's Rights and Gender Equality + + FEMM + + + + + 19/01/2012 + + + + 30/06/2014 + + European Parliament
Substitute + + Delegation for relations with Canada + + + + + 16/09/2009 + + + + 30/06/2014 + + European Parliament
+ + United Kingdom + + GB + + + + + 14/07/2009 + + + + 30/06/2014 + + Labour Party
Member + + Group of the Progressive Alliance of Socialists and Democrats in the European Parliament + + SD + + + + + 14/07/2009 + + + + 30/06/2014 + + European Parliament
Substitute + + Committee on Legal Affairs + + JURI + + + + + 20/09/2010 + + + + 18/01/2012 + + European Parliament
Member + + Committee on Culture and Education + + CULT + + + + + 16/07/2009 + + + + 18/01/2012 + + European Parliament
Member + + Committee on Women's Rights and Gender Equality + + FEMM + + + + + 16/07/2009 + + + + 18/01/2012 + + European Parliament
Substitute + + Committee on Regional Development + + REGI + + + + + 16/07/2009 + + + + 19/09/2010 + + European Parliament
Substitute + + Committee on Culture and Education + + CULT + + + + + 31/01/2007 + + + + 13/07/2009 + + European Parliament
Member + + Committee on Industry, Research and Energy + + ITRE + + + + + 31/01/2007 + + + + 13/07/2009 + + European Parliament
Substitute + + Committee on Women's Rights and Gender Equality + + FEMM + + + + + 31/01/2007 + + + + 13/07/2009 + + European Parliament
Member + + Delegation to the EU-Former Yugoslav Republic of Macedonia Joint Parliamentary Committee + + + + + 15/09/2004 + + + + 13/07/2009 + + European Parliament
Substitute + + Delegation to the Euro-Mediterranean Parliamentary Assembly + + + + + 15/09/2004 + + + + 13/07/2009 + + European Parliament
Substitute + + Delegation to the EU-Turkey Joint Parliamentary Committee + + + + + 15/09/2004 + + + + 13/07/2009 + + European Parliament
+ + United Kingdom + + GB + + + + + 20/07/2004 + + + + 13/07/2009 + + Labour Party
Member + + Socialist Group in the European Parliament + + PSE + + + + + 20/07/2004 + + + + 13/07/2009 + + European Parliament
Substitute + + Committee on Culture and Education + + CULT + + + + + 15/01/2007 + + + + 30/01/2007 + + European Parliament
Member + + Committee on the Environment, Public Health and Food Safety + + ENVI + + + + + 15/01/2007 + + + + 30/01/2007 + + European Parliament
Substitute + + Committee on Women's Rights and Gender Equality + + FEMM + + + + + 15/01/2007 + + + + 30/01/2007 + + European Parliament
Substitute + + Committee on Culture and Education + + CULT + + + + + 21/07/2004 + + + + 14/01/2007 + + European Parliament
Member + + Committee on the Environment, Public Health and Food Safety + + ENVI + + + + + 21/07/2004 + + + + 14/01/2007 + + European Parliament
Substitute + + Committee on Women's Rights and Gender Equality + + FEMM + + + + + 21/07/2004 + + + + 14/01/2007 + + European Parliament
Member + + Committee on Economic and Monetary Affairs + + ECON + + + + + 17/01/2002 + + + + 19/07/2004 + + European Parliament
+ + United Kingdom + + GB + + + + + 17/02/2000 + + + + 19/07/2004 + + Labour Party
Member + + Group of the Party of European Socialists + + PSE + + + + + 17/02/2000 + + + + 19/07/2004 + + European Parliament
Member + + Delegation to the EU-Cyprus Joint Parliamentary Committee + + + + + 07/02/2002 + + + + 30/04/2004 + + European Parliament
Substitute + + Delegation to the EU-Malta Joint Parliamentary Committee + + + + + 07/02/2002 + + + + 30/04/2004 + + European Parliament
Member + + Delegation to the EU-Cyprus Joint Parliamentary Committee + + + + + 11/04/2000 + + + + 14/01/2002 + + European Parliament
Substitute + + Committee on Employment and Social Affairs + + EMPL + + + + + 01/03/2000 + + + + 14/01/2002 + + European Parliament
+
+
+ +
+ + + + + + diff --git a/memopol/tests/response_fixtures/RepresentativeDetailTest.test_mandates_display.metadata b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_mandates_display.metadata new file mode 100644 index 0000000..a2e0a69 --- /dev/null +++ b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_mandates_display.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/response_fixtures/RepresentativeDetailTest.test_positions_display.content b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_positions_display.content new file mode 100644 index 0000000..5b2a9d3 --- /dev/null +++ b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_positions_display.content @@ -0,0 +1,274 @@ + + + + + + + + Home - Political Memory + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +

Mary HONEYBALL

+
+
+

+
+
+ + + + + + + + + + + + + + + + + + + + + +
Score + -7 +
Chamber + European Parliament +
Country + United Kingdom +
Party + Member of Group of the Progressive Alliance of Socialists and Democrats in the European Parliament +
BiographyBorn in Weymouth the + 12/11/1952 + (F)
+
+
+
+ + +
+
+ + + + + +
+
+

Public positions

+ + + + + + + + + + + + + + + +
24/11/2010 + + first-validated + + + + http://example.com/first-validated + + +
24/11/2010 + + other-validated + + + + http://example.com/second-validated + + +
+ + +
+ + +
+
+ + + +
+ +
+
+
+ + +
+ +
+ +
+ + +
+
+
+ +
+ + + + + + diff --git a/memopol/tests/response_fixtures/RepresentativeDetailTest.test_positions_display.metadata b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_positions_display.metadata new file mode 100644 index 0000000..a2e0a69 --- /dev/null +++ b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_positions_display.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/response_fixtures/RepresentativeDetailTest.test_votes_display.content b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_votes_display.content new file mode 100644 index 0000000..381bdb8 --- /dev/null +++ b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_votes_display.content @@ -0,0 +1,270 @@ + + + + + + + + Home - Political Memory + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +

Mary HONEYBALL

+
+
+

+
+
+ + + + + + + + + + + + + + + + + + + + + +
Score + -7 +
Chamber + European Parliament +
Country + United Kingdom +
Party + Member of Group of the Progressive Alliance of Socialists and Democrats in the European Parliament +
BiographyBorn in Weymouth the + 12/11/1952 + (F)
+
+
+
+ + +
+
+ + + + + +
+

Votes

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TitleDate + Memopol recommendation + + Representative vote + + Score + +
Stop acta ! + Nov. 24, 2010 + + + + + + -6 +
Stop acta ! + Nov. 24, 2010 + + + + + + -5 +
Stop acta ! + Nov. 24, 2010 + + + + + + 4 +
+
+
+ +
+ + + + + + diff --git a/memopol/tests/response_fixtures/RepresentativeDetailTest.test_votes_display.metadata b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_votes_display.metadata new file mode 100644 index 0000000..a2e0a69 --- /dev/null +++ b/memopol/tests/response_fixtures/RepresentativeDetailTest.test_votes_display.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/test_representatives_detail.py b/memopol/tests/test_representatives_detail.py index 0600e7a..e0739e2 100644 --- a/memopol/tests/test_representatives_detail.py +++ b/memopol/tests/test_representatives_detail.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- from django.test import TestCase -from .base import UrlGetTestMixin +from .base import UrlGetTestMixin, ResponseDiffMixin -class RepresentativeDetailTest(UrlGetTestMixin, TestCase): +class RepresentativeDetailTest(UrlGetTestMixin, TestCase, ResponseDiffMixin): fixtures = ['one_representative'] url = '/legislature/representative/mary-honeyball-1952-11-12/' @@ -12,7 +12,7 @@ class RepresentativeDetailTest(UrlGetTestMixin, TestCase): # Ensure one-time cached queries occur before the actual test self.client.get(self.url) - with self.assertNumQueries(11): + with self.assertNumQueries(9): """ - One query for chambers - One query for the rep details and foreign key (profile) @@ -21,9 +21,7 @@ class RepresentativeDetailTest(UrlGetTestMixin, TestCase): - One query for reverse relation on emails - Three queries for reverse relation on websites (parliament, social and other) - - One query for reverse relation on votes - One query for reverse relation on mandates - - One query for reverse relation positions """ self.client.get(self.url) @@ -51,10 +49,24 @@ class RepresentativeDetailTest(UrlGetTestMixin, TestCase): self.assertHtmlInResult('Born in Weymouth the 12/11/1952 (F)') def test_votes_display(self): - self.assertExpectedHtmlInResult() + self.responsediff_test(self.url + 'votes/', 3) + """ + - One query for chambers + - One query for the rep details and foreign key (profile) + - One query for reverse relation on votes + """ def test_mandates_display(self): - self.assertExpectedHtmlInResult() + self.responsediff_test(self.url + 'mandates/', 2) + """ + - One query for the rep details and foreign key (profile) + - One query for reverse relation on mandates + """ def test_positions_display(self): - self.assertExpectedHtmlInResult() + self.responsediff_test(self.url + 'positions/', 3) + """ + - One query for chambers + - One query for the rep details and foreign key (profile) + - One query for reverse relation on positions + """ diff --git a/memopol/urls.py b/memopol/urls.py index 57d4c11..7da4214 100644 --- a/memopol/urls.py +++ b/memopol/urls.py @@ -9,6 +9,9 @@ from views.dossier_list import DossierList from views.group_ac import GroupAutocomplete from views.group_list import GroupList from views.representative_detail import RepresentativeDetail +from views.representative_votes import RepresentativeVotes +from views.representative_mandates import RepresentativeMandates +from views.representative_positions import RepresentativePositions from views.representative_list import RepresentativeList from views.redirects import RedirectGroupList, RedirectGroupRepresentativeList from views.theme_detail import ThemeDetail @@ -41,6 +44,22 @@ urlpatterns = [ RepresentativeDetail.as_view(), name='representative-detail' ), + url( + r'^legislature/representative/(?P[-\w]+)/votes/$', + RepresentativeVotes.as_view(), + name='representative-votes' + ), + url( + r'^legislature/representative/(?P[-\w]+)/mandates/$', + RepresentativeMandates.as_view(), + name='representative-mandates' + ), + url( + r'^legislature/representative/(?P[-\w]+)/positions/$', + RepresentativePositions.as_view(), + name='representative-positions' + ), + url( r'^legislature/group/$', GroupList.as_view(), diff --git a/memopol/views/representative_detail.py b/memopol/views/representative_detail.py index 3e6decd..fb1dfa3 100644 --- a/memopol/views/representative_detail.py +++ b/memopol/views/representative_detail.py @@ -5,9 +5,6 @@ from django.views import generic from representatives.models import Chamber, Representative, Address, Phone, \ WebSite -from representatives_positions.forms import PositionForm -from representatives_recommendations.models import VoteScore -from representatives_votes.models import Proposal from .representative_mixin import RepresentativeViewMixin @@ -50,13 +47,6 @@ class RepresentativeDetail(RepresentativeViewMixin, generic.DetailView): models.Prefetch( 'phone_set', queryset=Phone.objects.select_related('address__country') - ), - models.Prefetch( - 'votes', - queryset=VoteScore.objects.filter( - proposal__in=Proposal.objects.exclude(recommendation=None), - ).select_related('proposal__recommendation').order_by( - '-proposal__datetime') ) ) @@ -67,13 +57,4 @@ class RepresentativeDetail(RepresentativeViewMixin, generic.DetailView): self.add_representative_country_and_main_mandate(c['object']) - c['votes'] = c['object'].votes.all() - c['mandates'] = c['object'].mandates.all() - c['positions'] = c['object'].positions.filter(published=True) \ - .order_by('-datetime', 'pk') - - c['position_form'] = PositionForm( - initial={'representative': self.object.pk}) - self.add_representative_country_and_main_mandate(c['object']) - return c diff --git a/memopol/views/representative_mandates.py b/memopol/views/representative_mandates.py new file mode 100644 index 0000000..9235b06 --- /dev/null +++ b/memopol/views/representative_mandates.py @@ -0,0 +1,29 @@ +# coding: utf-8 + +from django.views import generic + +from representatives.models import Representative + +from .representative_mixin import RepresentativeViewMixin + + +class RepresentativeMandates(RepresentativeViewMixin, generic.DetailView): + template_name = 'representatives/representative_mandates' + + queryset = Representative.objects.select_related('score') + + def get_queryset(self): + qs = super(RepresentativeMandates, self).get_queryset() + + qs = self.prefetch_for_representative_country_and_main_mandate(qs) + + return qs + + def get_context_data(self, **kwargs): + c = super(RepresentativeMandates, self).get_context_data(**kwargs) + + self.add_representative_country_and_main_mandate(c['object']) + + c['mandates'] = c['object'].mandates.all() + + return c diff --git a/memopol/views/representative_positions.py b/memopol/views/representative_positions.py new file mode 100644 index 0000000..1400350 --- /dev/null +++ b/memopol/views/representative_positions.py @@ -0,0 +1,40 @@ +# coding: utf-8 + +from django.db import models +from django.views import generic + +from representatives.models import Representative +from representatives_positions.forms import PositionForm +from representatives_positions.models import Position + +from .representative_mixin import RepresentativeViewMixin + + +class RepresentativePositions(RepresentativeViewMixin, generic.DetailView): + template_name = 'representatives/representative_positions' + + queryset = Representative.objects.select_related('score') + + def get_queryset(self): + qs = super(RepresentativePositions, self).get_queryset() + + qs = self.prefetch_for_representative_country_and_main_mandate(qs) + + qs = qs.prefetch_related( + models.Prefetch( + 'positions', + queryset=Position.objects.filter(published=True) + .order_by('-datetime', 'pk') + ) + ) + + return qs + + def get_context_data(self, **kwargs): + c = super(RepresentativePositions, self).get_context_data(**kwargs) + + c['position_form'] = PositionForm( + initial={'representative': self.object.pk}) + self.add_representative_country_and_main_mandate(c['object']) + + return c diff --git a/memopol/views/representative_votes.py b/memopol/views/representative_votes.py new file mode 100644 index 0000000..1343416 --- /dev/null +++ b/memopol/views/representative_votes.py @@ -0,0 +1,42 @@ +# coding: utf-8 + +from django.db import models +from django.views import generic + +from representatives.models import Representative +from representatives_recommendations.models import VoteScore +from representatives_votes.models import Proposal + +from .representative_mixin import RepresentativeViewMixin + + +class RepresentativeVotes(RepresentativeViewMixin, generic.DetailView): + template_name = 'representatives/representative_votes' + + queryset = Representative.objects.select_related('score') + + def get_queryset(self): + qs = super(RepresentativeVotes, self).get_queryset() + + qs = self.prefetch_for_representative_country_and_main_mandate(qs) + + qs = qs.prefetch_related( + models.Prefetch( + 'votes', + queryset=VoteScore.objects.filter( + proposal__in=Proposal.objects.exclude(recommendation=None), + ).select_related('proposal__recommendation').order_by( + '-proposal__datetime') + ) + ) + + return qs + + def get_context_data(self, **kwargs): + c = super(RepresentativeVotes, self).get_context_data(**kwargs) + + self.add_representative_country_and_main_mandate(c['object']) + + c['votes'] = c['object'].votes.all() + + return c diff --git a/templates/representatives/_representative_menu.haml b/templates/representatives/_representative_menu.haml new file mode 100644 index 0000000..7a25ce9 --- /dev/null +++ b/templates/representatives/_representative_menu.haml @@ -0,0 +1,15 @@ +- load i18n + +%ul.nav.nav-pills + %li + %a{href: "{% url 'representative-detail' slug=representative.slug %}"} + - trans 'Contact details' + %li + %a{href: "{% url 'representative-votes' slug=representative.slug %}"} + - trans 'Votes' + %li + %a{href: "{% url 'representative-mandates' slug=representative.slug %}"} + - trans 'Mandates' + %li + %a{href: "{% url 'representative-positions' slug=representative.slug %}"} + - trans 'Public positions' diff --git a/templates/representatives/representative_detail.haml b/templates/representatives/representative_detail.haml index dad16c2..8459d2a 100644 --- a/templates/representatives/representative_detail.haml +++ b/templates/representatives/representative_detail.haml @@ -9,68 +9,10 @@ - block content .row - .col-md-6 - - include 'representatives/_representative_block.html' with representative=representative - - include 'representatives/_representative_contact.html' with representative=representative - - .col-md-6 - %h2#votes Votes - - %table.table.table-condensed.votes - %tr - %th Title - %th Date - %th.icon-cell - Memopol recommendation - %th.icon-cell - Representative vote - %th.icon-cell - Score - - - for vote in votes - %tr - %td= vote.proposal.recommendation.title - %td.date-cell - = vote.proposal.datetime|date:'N j, Y' - %td.icon-cell - = vote.proposal.recommendation.recommendation|position_icon - %td.icon-cell - = vote.position|position_icon - %td.icon-cell - = vote.score|score_label - + - include 'representatives/_representative_block.html' with representative=representative - %h2 Mandates - - %table.table.table-condensed.mandates - - for mandate in mandates - %tr.mandate - %td= mandate.role - %td - %a{:href => "{% group_url mandate.group %}"} - {{ mandate.group.name }} - - if mandate.group.abbreviation - {{ mandate.group.abbreviation }} - %td - - if mandate.begin_date - = mandate.begin_date|mandate_date:'d/m/Y' - %td - - if mandate.end_date - = mandate.end_date|mandate_date:'d/m/Y' - %td= mandate.constituency.name - - .positions - %h2 Public positions - - %table.table.table-condensed - - for position in positions - %tr.position - %td= position.datetime|naturalday:'d/m/Y' - %td - %a{:href => '{{ position.get_absolute_url }}'} - =position.text|truncatewords:8 - %td - %a{:href => '{{ position.link }}'} - = position.link + .row + - include 'representatives/_representative_menu.html' with representative=representative - - include 'representatives_positions/_form.html' with form=position_form + .col-md-6 + - include 'representatives/_representative_contact.html' with representative=representative \ No newline at end of file diff --git a/templates/representatives/representative_mandates.haml b/templates/representatives/representative_mandates.haml new file mode 100644 index 0000000..460b045 --- /dev/null +++ b/templates/representatives/representative_mandates.haml @@ -0,0 +1,35 @@ +- extends 'base.html' + +- load humanize +- load memopol_tags +- load representatives_recommendations_tags + +- block head + {{ position_form.media }} + +- block content + .row + - include 'representatives/_representative_block.html' with representative=representative + + .row + - include 'representatives/_representative_menu.html' with representative=representative + + .col-md-6 + %h2 Mandates + + %table.table.table-condensed.mandates + - for mandate in mandates + %tr.mandate + %td= mandate.role + %td + %a{:href => "{% group_url mandate.group %}"} + {{ mandate.group.name }} + - if mandate.group.abbreviation + {{ mandate.group.abbreviation }} + %td + - if mandate.begin_date + = mandate.begin_date|mandate_date:'d/m/Y' + %td + - if mandate.end_date + = mandate.end_date|mandate_date:'d/m/Y' + %td= mandate.constituency.name \ No newline at end of file diff --git a/templates/representatives/representative_positions.haml b/templates/representatives/representative_positions.haml new file mode 100644 index 0000000..00b4714 --- /dev/null +++ b/templates/representatives/representative_positions.haml @@ -0,0 +1,32 @@ +- extends 'base.html' + +- load humanize +- load memopol_tags +- load representatives_recommendations_tags + +- block head + {{ position_form.media }} + +- block content + .row + - include 'representatives/_representative_block.html' with representative=representative + + .row + - include 'representatives/_representative_menu.html' with representative=representative + + .col-md-6 + .positions + %h2 Public positions + + %table.table.table-condensed + - for position in representative.positions.all + %tr.position + %td= position.datetime|naturalday:'d/m/Y' + %td + %a{:href => '{{ position.get_absolute_url }}'} + =position.text|truncatewords:8 + %td + %a{:href => '{{ position.link }}'} + = position.link + + - include 'representatives_positions/_form.html' with form=position_form diff --git a/templates/representatives/representative_votes.haml b/templates/representatives/representative_votes.haml new file mode 100644 index 0000000..669b54e --- /dev/null +++ b/templates/representatives/representative_votes.haml @@ -0,0 +1,41 @@ +- extends 'base.html' + +- load humanize +- load memopol_tags +- load representatives_recommendations_tags + +- block head + {{ position_form.media }} + +- block content + .row + - include 'representatives/_representative_block.html' with representative=representative + + .row + - include 'representatives/_representative_menu.html' with representative=representative + + .col-md-6 + %h2#votes Votes + + %table.table.table-condensed.votes + %tr + %th Title + %th Date + %th.icon-cell + Memopol recommendation + %th.icon-cell + Representative vote + %th.icon-cell + Score + + - for vote in votes + %tr + %td= vote.proposal.recommendation.title + %td.date-cell + = vote.proposal.datetime|date:'N j, Y' + %td.icon-cell + = vote.proposal.recommendation.recommendation|position_icon + %td.icon-cell + = vote.position|position_icon + %td.icon-cell + = vote.score|score_label \ No newline at end of file -- GitLab