diff --git a/memopol/filters.py b/memopol/filters.py index 453731b72b5e0a6ba6271f8da455e716ae09c59a..9fdbdbe6380807e81fef186dc0eafcb385b4e7c8 100644 --- a/memopol/filters.py +++ b/memopol/filters.py @@ -10,6 +10,7 @@ from django.utils.text import slugify from django_filters import FilterSet, MethodFilter, ModelChoiceFilter from representatives.models import Chamber, Group, Representative +from representatives_votes.models import Dossier def chamber_filter(qs, value): @@ -53,3 +54,19 @@ class RepresentativeFilter(FilterSet): return qs return qs.filter(slug__icontains=slugify(value)) + + +class DossierFilter(FilterSet): + + search = MethodFilter(action='search_filter') + + class Meta: + model = Dossier + fields = ['search'] + + def search_filter(self, qs, value): + if len(value) == 0: + return qs + + return qs.filter(Q(title__icontains=value) | + Q(reference__icontains=value)) diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_list.content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_list.content index 8cd7c395b33d83d6fcb74e6a983fbebc0c770556..55ca037de79f696768ef41bb2aaeffbcc0ed16ac 100644 --- a/memopol/tests/response_fixtures/DossiersTest.test_dossier_list.content +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_list.content @@ -14,6 +14,10 @@ <script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script> <script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script> + + + + </head> <body > <!-- -load memopol_tags cache --> @@ -78,37 +82,113 @@ <div class="container-fluid main-container"> - <h1> - Dossiers - </h1> - <table class='table'> - <tr> - <th> - Title - </th> - <th> - Recommendations - </th> - <th> - Reference - - </th> - </tr> + + + + + +<form class='filter-form' action='/votes/dossier/' method='get'> + + <div class="form-group has-success"><label class="control-label" for="id_search">Search</label><input class="form-control" id="id_search" name="search" placeholder="Search" title="Filter" type="text" /><span class="help-block">Filter +</span></div> + + <div class="form-group"> + <button class='btn btn-primary' type='submit'> + <span class="glyphicon glyphicon-filter"></span> Filter + </button> + </div> + + + +</form> + + + + + + + <div class='pagination-block'> + + <nav> + <ul class='pagination pagination-sm'> + + + + </ul> + </nav> + <div class='count'> + Number of results : 1 + + + <br /> + Number of displayed results : + 12 + ( + + <a href='?&paginate_by=12'> + 12 + </a> + + / + + + <a href='?&paginate_by=24'> + 24 + </a> + + / + + + <a href='?&paginate_by=48'> + 48 + </a> + + / + + <a href='?&paginate_by=96'> + 96 + </a> + + + ) + + </div> +</div> + + + <h1> + Dossiers + + </h1> + <table class='table'> <tr> - <td> - <a href='/votes/dossier/28147/'> - Resolution on the Anti-Counterfeiting Trade Agreement (ACTA) - </a> - </td> - <td>3</td> - <td>2010/2935(RSP)</td> + <th> + Title + </th> + <th> + Recommendations + </th> + <th> + Reference + </th> </tr> - - </table> - <div class='pagination-block'> + + <tr> + <td> + <a href='/votes/dossier/28147/'> + Resolution on the Anti-Counterfeiting Trade Agreement (ACTA) + </a> + </td> + <td>3</td> + <td>2010/2935(RSP)</td> + + </tr> + + </table> + <div class='pagination-block'> <nav> <ul class='pagination pagination-sm'> @@ -158,6 +238,8 @@ </div> + + </div> diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.content new file mode 100644 index 0000000000000000000000000000000000000000..53a787512a878c15ec1d9ab533d9e47975fb996a --- /dev/null +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.content @@ -0,0 +1,277 @@ +<!DOCTYPE html> +<html class="no-js" lang="en"> <!--<![endif]--> + <head> + <meta charset="utf-8" /> + <link rel="icon" type="image/png" href="/static/collected/img/favicon.ico" /> + <!-- Set the viewport width to device width for mobile --> + <meta name="viewport" content="width=device-width" /> + <title> + Home + - The Political Memory of </title> + + + <link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" /> + <script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script> +<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script> + + + + + + </head> + <body > + <!-- -load memopol_tags cache --> + + + + +<div id='header' class='container-fluid'> + <a id='logo' href='/'> + <img src='/static/collected/images/logo.png' /> + </a> + <h1> + <a id='header_banner' href='/'> + Political Memory + </a> + </h1> + <p class='organization'> + + + </p> +</div> +<div id='nav' class='container-fluid'> + <ul class='nav'> + <li> + <a href='/legislature/representative/'> + Representatives + </a> + </li> + <li> + <a href='/legislature/group/country/'> + Countries + </a> + </li> + <li> + <a href='/legislature/group/chamber/'> + Chambers + </a> + </li> + <li> + <a href='/legislature/group/group/'> + Parties + </a> + </li> + <li> + <a href='/legislature/group/delegation/'> + Delegations + </a> + </li> + <li> + <a href='/legislature/group/committee/'> + Committees + </a> + </li> + <li> + <a href='/votes/dossier/'> + Dossiers + + </a> + </li> + </ul> +</div> + + <div class="container-fluid main-container"> + + + + + + + +<form class='filter-form' action='/votes/dossier/' method='get'> + + <div class="form-group has-success"><label class="control-label" for="id_search">Search</label><input class="form-control" id="id_search" name="search" placeholder="Search" title="Filter" type="text" value="acta" /><span class="help-block">Filter +</span></div> + + <div class="form-group"> + <button class='btn btn-primary' type='submit'> + <span class="glyphicon glyphicon-filter"></span> Filter + </button> + </div> + + + +</form> + + + + + + + <div class='pagination-block'> + + <nav> + <ul class='pagination pagination-sm'> + + + + </ul> + </nav> + <div class='count'> + Number of results : 1 + + + <br /> + Number of displayed results : + 12 + ( + + <a href='?search=acta&paginate_by=12'> + 12 + </a> + + / + + + <a href='?search=acta&paginate_by=24'> + 24 + </a> + + / + + + <a href='?search=acta&paginate_by=48'> + 48 + </a> + + / + + + <a href='?search=acta&paginate_by=96'> + 96 + </a> + + + ) + + </div> +</div> + + + <h1> + Dossiers + + </h1> + <table class='table'> + <tr> + <th> + Title + </th> + <th> + Recommendations + </th> + <th> + Reference + + </th> + </tr> + + <tr> + <td> + <a href='/votes/dossier/28147/'> + Resolution on the Anti-Counterfeiting Trade Agreement (ACTA) + </a> + </td> + <td>3</td> + <td>2010/2935(RSP)</td> + + </tr> + + </table> + <div class='pagination-block'> + + <nav> + <ul class='pagination pagination-sm'> + + + + </ul> + </nav> + <div class='count'> + Number of results : 1 + + + <br /> + Number of displayed results : + 12 + ( + + <a href='?search=acta&paginate_by=12'> + 12 + </a> + + / + + + <a href='?search=acta&paginate_by=24'> + 24 + </a> + + / + + + <a href='?search=acta&paginate_by=48'> + 48 + </a> + + / + + + <a href='?search=acta&paginate_by=96'> + 96 + </a> + + + ) + + </div> +</div> + + + + + + </div> + + +<div id='footer' class='container-fluid'> + <div class='license-links'> + + Memopol is + <a href='https://github.com/political-memory/political_memory'>free software</a> + released under the terms of the + <a href='http://www.gnu.org/licenses/agpl.html'>GNU aGPLV3+</a> + + </div> + <div class='footer-link'> + <a href='https://github.com/political-memory/political_memory/issues/new'>Report a bug</a> + </div> + <div class='footer-link'> + <a href='http://www.memopol.org/'>Blog</a> + </div> + <div class='footer-link'> + <a href='http://memopol.readthedocs.io/en/master/'>Documentation</a> + </div> + <div class='footer-separator'></div> + <div class='footer-link'> + Developed by + <a href='http://www.laquadrature.net/'>La Quadrature du Net</a> + </div> + <div class='footer-link'> + EP data provided by + <a href='http://parltrack.euwiki.org/'>Parltrack</a> + </div> +</div> + + </body> +</html> diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.metadata b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.metadata new file mode 100644 index 0000000000000000000000000000000000000000..a2e0a6921bc4a7d94e1887a6eab7a49889fc3ace --- /dev/null +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.content new file mode 100644 index 0000000000000000000000000000000000000000..f0af4090d2b9130bb32f3707ffccfdd36a71ce11 --- /dev/null +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.content @@ -0,0 +1,149 @@ +<!DOCTYPE html> +<html class="no-js" lang="en"> <!--<![endif]--> + <head> + <meta charset="utf-8" /> + <link rel="icon" type="image/png" href="/static/collected/img/favicon.ico" /> + <!-- Set the viewport width to device width for mobile --> + <meta name="viewport" content="width=device-width" /> + <title> + Home + - The Political Memory of </title> + + + <link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" /> + <script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script> +<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script> + + + + + + </head> + <body > + <!-- -load memopol_tags cache --> + + + + +<div id='header' class='container-fluid'> + <a id='logo' href='/'> + <img src='/static/collected/images/logo.png' /> + </a> + <h1> + <a id='header_banner' href='/'> + Political Memory + </a> + </h1> + <p class='organization'> + + + </p> +</div> +<div id='nav' class='container-fluid'> + <ul class='nav'> + <li> + <a href='/legislature/representative/'> + Representatives + </a> + </li> + <li> + <a href='/legislature/group/country/'> + Countries + </a> + </li> + <li> + <a href='/legislature/group/chamber/'> + Chambers + </a> + </li> + <li> + <a href='/legislature/group/group/'> + Parties + </a> + </li> + <li> + <a href='/legislature/group/delegation/'> + Delegations + </a> + </li> + <li> + <a href='/legislature/group/committee/'> + Committees + </a> + </li> + <li> + <a href='/votes/dossier/'> + Dossiers + + </a> + </li> + </ul> +</div> + + <div class="container-fluid main-container"> + + + + + + + +<form class='filter-form' action='/votes/dossier/' method='get'> + + <div class="form-group has-success"><label class="control-label" for="id_search">Search</label><input class="form-control" id="id_search" name="search" placeholder="Search" title="Filter" type="text" value="no-dossier-will-have-that-title-ever" /><span class="help-block">Filter +</span></div> + + <div class="form-group"> + <button class='btn btn-primary' type='submit'> + <span class="glyphicon glyphicon-filter"></span> Filter + </button> + </div> + + + +</form> + + + + + + + <div class='no-results'>No matching dossiers found :(</div> + + + + + </div> + + +<div id='footer' class='container-fluid'> + <div class='license-links'> + + Memopol is + <a href='https://github.com/political-memory/political_memory'>free software</a> + released under the terms of the + <a href='http://www.gnu.org/licenses/agpl.html'>GNU aGPLV3+</a> + + </div> + <div class='footer-link'> + <a href='https://github.com/political-memory/political_memory/issues/new'>Report a bug</a> + </div> + <div class='footer-link'> + <a href='http://www.memopol.org/'>Blog</a> + </div> + <div class='footer-link'> + <a href='http://memopol.readthedocs.io/en/master/'>Documentation</a> + </div> + <div class='footer-separator'></div> + <div class='footer-link'> + Developed by + <a href='http://www.laquadrature.net/'>La Quadrature du Net</a> + </div> + <div class='footer-link'> + EP data provided by + <a href='http://parltrack.euwiki.org/'>Parltrack</a> + </div> +</div> + + </body> +</html> diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.metadata b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.metadata new file mode 100644 index 0000000000000000000000000000000000000000..a2e0a6921bc4a7d94e1887a6eab7a49889fc3ace --- /dev/null +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_chamber.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_chamber.content index d14620b62367b03b1ccc9d4333cbeda65d696743..3b8d4aafc3c3cda0b566962cc31d169da4666ef4 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_chamber.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_chamber.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_country.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_country.content index 4d3da60e7ab8c39db99aac6c24dacc5e6d563abe..9e224a3cb585ffa25318a41fba0934b35dbb7134 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_country.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_country.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_group.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_group.content index 2143b3648b0f9a4779a428f086b43d84748f864c..5847dc711110e1d57790db4087650b21c8c11535 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_group.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_group.content @@ -145,11 +145,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_multiple.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_multiple.content index 17175fa144ab88fd5f33c1fd6e83036a2d4e7f7c..0227de1f82854d3da495854c82a8c6144828310c 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_multiple.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_multiple.content @@ -145,11 +145,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_notfound.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_notfound.content index 36bed4ed779cbafbb7e83e6dc42cb05f7cfdf5a0..34952f62d551b34b764cc3c5ee3f7086fc339f93 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_notfound.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_notfound.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> @@ -157,7 +161,7 @@ - <div class='no-results'>No matching representatives found :(</div> + <div class='no-results'>No matching representatives found :(</div> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_search.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_search.content index 5f6741576f83ea2af8c85c8812ec42d1bab3e63c..6a06bf965eb851dda496fded99f70e64d3f1b175 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_search.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_search.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_active_displaylist.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_active_displaylist.content index 0dd2bb83ff3f4c2a01f8f5c2769305ccef9a4222..447cf065fceb62cf769b09cd3e9ffe2f3707a295 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_active_displaylist.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_active_displaylist.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_all_displaylist.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_all_displaylist.content index ffc0e5d15999a2785c8587aa575f3e6d8030ddbe..1d5289ed96ad8c3ad259568d8848d8672867dcc2 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_all_displaylist.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_all_displaylist.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_displaylist_searchjoly.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_displaylist_searchjoly.content index d9984e38c18eac8ace05c0e371e0bba77e5d6e97..a15221a2c2ebbb2913f63ec0ff5e36f22d5e84f4 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_displaylist_searchjoly.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby12_displaylist_searchjoly.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby24_active_displaygrid.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby24_active_displaygrid.content index 8b02937834b55278e107acb4b95546e3e78e13b6..705b0ca49a0a97e6414e2aca9565484232c7caa5 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby24_active_displaygrid.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby24_active_displaygrid.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby24_all_displaygrid.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby24_all_displaygrid.content index 552426394d4ca7dd0d335dd6400d78244ed9e6da..d1f118bfba005eb01cd4dc713f6c1eae5c73b997 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby24_all_displaygrid.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page1_paginateby24_all_displaygrid.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby12_displaylist.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby12_displaylist.content index cb897b6b600d34e4d8660783baf68043a881c1ab..633034f1f4f185498a380f68695ed3a45ef1f232 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby12_displaylist.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby12_displaylist.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby24_displaylist.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby24_displaylist.content index b6cb3a318c114113da3d7f6d9814030a60cac77d..0245b8912d16ae3a3d800a5769df1ac82098e347 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby24_displaylist.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby24_displaylist.content @@ -144,11 +144,15 @@ </button> </div> - <div class="form-group"> - <button class='btn btn-default' type='submit' name='csv'> - <span class="glyphicon glyphicon-download-alt"></span> Download as CSV - </button> - </div> + + + <div class="form-group"> + <button class='btn btn-default' type='submit' name='csv'> + <span class="glyphicon glyphicon-download-alt"></span> Download as CSV + </button> + </div> + + </form> diff --git a/memopol/tests/test_dossiers.py b/memopol/tests/test_dossiers.py index f88f99188c1e2ce3c57d851a82a22bfd2aee6e77..d9aa167007ab3ffc0fcab229542abc969d6c2491 100644 --- a/memopol/tests/test_dossiers.py +++ b/memopol/tests/test_dossiers.py @@ -20,6 +20,26 @@ class DossiersTest(ResponseDiffMixin, TestCase): # 1 query for recommendations self.responsediff_test('/votes/dossier/', 4) + def test_dossier_search(self): + # session setup + self.client.get('/votes/dossier/') + + # 1 query for dossier count + # 1 query for dossiers + # 1 query for proposals + # 1 query for recommendations + q = 'acta' + self.responsediff_test('/votes/dossier/?search=%s' % q, 4) + + def test_dossier_search_noresults(self): + # session setup + self.client.get('/votes/dossier/') + + # 1 query for dossier count + # nothing else since count = 0 + q = 'no-dossier-will-have-that-title-ever' + self.responsediff_test('/votes/dossier/?search=%s' % q, 1) + def test_dossier_detail(self): # Get 1st dossier in dataset dossier = Dossier.objects.order_by('pk')[0] diff --git a/memopol/views/dossier_list.py b/memopol/views/dossier_list.py index 63335b9997b43a25a4865a306d6875999a9c8f34..48087409ed42aa50a454d981b17ce071f4cd094f 100644 --- a/memopol/views/dossier_list.py +++ b/memopol/views/dossier_list.py @@ -7,12 +7,30 @@ from django.views import generic from representatives_votes.models import Dossier +from ..filters import DossierFilter + class DossierList(PaginationMixin, generic.ListView): + current_filter = None queryset = Dossier.objects.prefetch_related( 'proposals', 'proposals__recommendation' ).annotate( nb_recomm=Count('proposals__recommendation') ).order_by('-nb_recomm', '-reference') + + def dossier_filter(self, qs): + f = DossierFilter(self.request.GET, queryset=qs) + self.current_filter = f + return f.qs + + def get_queryset(self): + qs = super(DossierList, self).get_queryset() + qs = self.dossier_filter(qs) + return qs + + def get_context_data(self, **kwargs): + c = super(DossierList, self).get_context_data(**kwargs) + c['filter'] = self.current_filter + return c diff --git a/templates/representatives/_filter_form.haml b/templates/_filter_form.haml similarity index 60% rename from templates/representatives/_filter_form.haml rename to templates/_filter_form.haml index cebb07f28b8f3f8e735d8e0ac65c7070f6d36052..92c7f3c135f8c88211c78b3e7ae26970ddafe92d 100644 --- a/templates/representatives/_filter_form.haml +++ b/templates/_filter_form.haml @@ -9,7 +9,9 @@ {% bootstrap_icon "filter" %} Filter - endbuttons - - buttons - %button{'type': 'submit', 'name': 'csv', 'class': 'btn btn-default'} - {% bootstrap_icon "download-alt" %} Download as CSV - - endbuttons + - if csv + + - buttons + %button{'type': 'submit', 'name': 'csv', 'class': 'btn btn-default'} + {% bootstrap_icon "download-alt" %} Download as CSV + - endbuttons diff --git a/templates/representatives/representative_list.haml b/templates/representatives/representative_list.haml index d745a7b8c7b28fdf727c4d37126cebdf98ca89d0..2b58ae1a065aef38a52c15e31c2fce5436ff366c 100644 --- a/templates/representatives/representative_list.haml +++ b/templates/representatives/representative_list.haml @@ -13,11 +13,11 @@ - block search {% url 'representative-list' as action_url %} - - include 'representatives/_filter_form.html' with action=action_url form=filter.form qs=request.GET.urlencode + - include '_filter_form.html' with action=action_url form=filter.form qs=request.GET.urlencode csv=True - if object_list|length == 0 - .no-results="No matching representatives found :(" + .no-results="No matching representatives found :(" - else diff --git a/templates/representatives_votes/dossier_list.haml b/templates/representatives_votes/dossier_list.haml index 4bc5df7eb54cf04310e8559f19db5dbf301ca47f..aed6045f9c499799fca2b68cc54d947077a0a55e 100644 --- a/templates/representatives_votes/dossier_list.haml +++ b/templates/representatives_votes/dossier_list.haml @@ -1,25 +1,43 @@ - extends "base.html" - load i18n +- block head + + {{ filter.form.media }} + - block content - %h1 - - trans "Dossiers" - - %table.table - %tr - %th - - trans "Title" - %th - - trans "Recommendations" - %th - - trans "Reference" - - - for dossier in object_list + + - block search + + {% url 'dossier-list' as action_url %} + - include '_filter_form.html' with action=action_url form=filter.form qs=request.GET.urlencode + + - if object_list|length == 0 + + .no-results="No matching dossiers found :(" + + - else + + - include 'core/blocks/pagination.html' + + %h1 + - trans "Dossiers" + + %table.table %tr - %td - %a{'href': "{% url 'dossier-detail' dossier.pk %}"} - {{ dossier.title }} - %td= dossier.nb_recomm - %td= dossier.reference + %th + - trans "Title" + %th + - trans "Recommendations" + %th + - trans "Reference" + + - for dossier in object_list + %tr + %td + %a{'href': "{% url 'dossier-detail' dossier.pk %}"} + {{ dossier.title }} + %td= dossier.nb_recomm + %td= dossier.reference - - include "core/blocks/pagination.html" + - include "core/blocks/pagination.html"