diff --git a/memopol/filters.py b/memopol/filters.py index 98774e1ac206da3630ec8dd22325af334ca84f81..e88575ced603afb6302bf6e7e9dddb4462fa030a 100644 --- a/memopol/filters.py +++ b/memopol/filters.py @@ -11,6 +11,7 @@ from django_filters import FilterSet, MethodFilter, ModelChoiceFilter from representatives.models import Chamber, Group, Representative from representatives_votes.models import Dossier +from memopol_themes.models import Theme def rep_chamber_filter(qs, value): @@ -77,3 +78,19 @@ class DossierFilter(FilterSet): return qs.filter(Q(title__icontains=value) | Q(reference__icontains=value)) + + +class ThemeFilter(FilterSet): + + search = MethodFilter(action='search_filter') + + class Meta: + model = Theme + fields = ['search'] + + def search_filter(self, qs, value): + if len(value) == 0: + return qs + + return qs.filter(Q(name__icontains=value) | + Q(description__icontains=value)) diff --git a/memopol/fixtures/smaller_sample.json b/memopol/fixtures/smaller_sample.json index cc46610e838596b2ef76a0d21fee1a9abdfa1494..12b993c62a634c7c4bad9fa87d544b314c451414 100644 --- a/memopol/fixtures/smaller_sample.json +++ b/memopol/fixtures/smaller_sample.json @@ -23200,5 +23200,32 @@ }, "model": "representatives_recommendations.recommendation", "pk": 47 +}, +{ + "fields": { + "description": "The Anti-Counterfeiting Trade agreement is a really bad thing, we would like to kill it with fire.", + "positions": [ + ], + "proposals": [ + 5744, 5745, 5746 + ], + "dossiers": [ + 28147 + ], + "slug": "acta", + "name": "acta" + }, + "model": "memopol_themes.theme", + "pk": 1 +}, +{ + "fields": { + "theme": 1, + "datetime": "2008-01-01", + "link": "http://www.laquadrature.net", + "title": "Press release on ACTA from La Quadrature du Net" + }, + "model": "memopol_themes.themelink", + "pk": 1 } ] diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_detail.content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_detail.content index 71cdd4fb0496dc9d1ce401d7eea61b1c41148486..6d788cb55cc1a72b9f35fb6cbf4a9c67ab6f5d59 100644 --- a/memopol/tests/response_fixtures/DossiersTest.test_dossier_detail.content +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_detail.content @@ -65,6 +65,11 @@ Committees +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_list.content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_list.content index 3d510dc3b40429c9ef689f9b9e39e6dbc0a7736c..596ee6bc40bb59cdd7faf021c50b9e92293bbc11 100644 --- a/memopol/tests/response_fixtures/DossiersTest.test_dossier_list.content +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_list.content @@ -69,6 +69,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.content index f7bb8d395f1fa128a27521175d67a5400d37b204..65ad739d70e809df8a94a045ec2cf90c8c4d93c7 100644 --- a/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.content +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search.content @@ -69,6 +69,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.content index 32c24c37bb5c16d8d2f9c8cd7ba0f50684cd96f6..762bad81bb5ffe32cb28b800ed9892b0368d8b36 100644 --- a/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.content +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_search_noresults.content @@ -69,6 +69,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/DossiersTest.test_dossier_sorting.content b/memopol/tests/response_fixtures/DossiersTest.test_dossier_sorting.content index 88b65baf49d1c1809fbbf3bb083dbc1912f99cf0..cd299a8dcabd6f5589702fd3670be07c98a48ff3 100644 --- a/memopol/tests/response_fixtures/DossiersTest.test_dossier_sorting.content +++ b/memopol/tests/response_fixtures/DossiersTest.test_dossier_sorting.content @@ -69,6 +69,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/GroupListTest.test_active_committees.content b/memopol/tests/response_fixtures/GroupListTest.test_active_committees.content index 3d292394b78584ce564d81da6c0b837fafa13c2c..143ad24f5b08c8508967950acd11c8f67e663997 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_active_committees.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_active_committees.content @@ -65,6 +65,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/GroupListTest.test_active_delegations.content b/memopol/tests/response_fixtures/GroupListTest.test_active_delegations.content index 18d46b0e98c5c00dcbf914302c568a8d58c3e503..0b72c118a1f05683ea6be1a0be147bca305e77ec 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_active_delegations.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_active_delegations.content @@ -65,6 +65,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/GroupListTest.test_active_parties.content b/memopol/tests/response_fixtures/GroupListTest.test_active_parties.content index 05c7990b9969ce426f3afe35b8b0333a21eae67e..ea63d76e828b567299d692941ad70147081caa65 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_active_parties.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_active_parties.content @@ -65,6 +65,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/GroupListTest.test_all_committees.content b/memopol/tests/response_fixtures/GroupListTest.test_all_committees.content index ea9f7101f6ebf1415f9573d80b736407712e77ad..88e81cf990844162c4d0f4a21b996bd675cb7aab 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_all_committees.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_all_committees.content @@ -65,6 +65,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/GroupListTest.test_all_delegations.content b/memopol/tests/response_fixtures/GroupListTest.test_all_delegations.content index 4cf059402b33b2c094294d008d7eb59740c7dc4f..c2a47ab77326426f49c11fcf22efcc44686707be 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_all_delegations.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_all_delegations.content @@ -65,6 +65,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/GroupListTest.test_all_parties.content b/memopol/tests/response_fixtures/GroupListTest.test_all_parties.content index 444be53889ba2387b7edac278c486dfee29062cc..d534920ed364d99e6518f4e2fd01ad118e88a9c4 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_all_parties.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_all_parties.content @@ -65,6 +65,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/GroupListTest.test_chambers.content b/memopol/tests/response_fixtures/GroupListTest.test_chambers.content index 914cf3cc08bebd1530235695ef4a9062d69a91b5..ba28cd9142baee4f025b05bf83bf38681ebda22d 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_chambers.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_chambers.content @@ -65,6 +65,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/GroupListTest.test_country.content b/memopol/tests/response_fixtures/GroupListTest.test_country.content index a74289b506a15734add5949da31f8e3b69dc2092..469fe9bff9ee2fe14e0ad1b63cf5f731355f2170 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_country.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_country.content @@ -65,6 +65,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_chamber.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_chamber.content index a58b62dd3fd48ad4f10d695abfa154231940834d..b613a7e50a60b999d40ae0969d788774a139f3c8 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_chamber.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_chamber.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_country.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_country.content index 3d1e2bf016fd8a829088c19f36256d95a767a74f..8d67670eca220fdef299983f945886eabbaed1b0 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_country.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_country.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_group.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_group.content index 5588b1eaaf092b6b704211e6d2965513f717e1c3..fbcc928040dfc818111f3a04f22753ddcb091347 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_group.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_group.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_multiple.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_multiple.content index 48f7ef6337150e2203b98cc762995cd7561692e6..5ccb5f7d9e4ced831f6e5d32fdad5e302c586ae4 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_multiple.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_multiple.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_notfound.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_notfound.content index 0af709b5a41d4b1b63ab082e9d54f08d07bf23c5..f8c0051e086e2815fa17dd72212c42c92e79bdb2 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_notfound.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_notfound.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_search.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_search.content index 935136ed8ebe84de1048613aea34d892e013e55f..b45e4166ddb7ddb0464e5a520c44cab3f1aed8f4 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_search.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_filter_search.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers 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 926fd08965d4338d55998180451a95c9c78080ca..e79225039c4c19fa9e24fa4535eb5dd1bac24ec2 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 @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers 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 d6f0a2faa608814a7f6561f780b11b93de3ac204..597f034d570e1f0fbdec2c239be087aad064d089 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 @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers 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 6b8cf4fc2cb70a3e2305bba5446e7b8e5137a333..0c72f895ecb0f6389405ceca779da1d172d57fbf 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 @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers 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 8d9c78164a000feb0adb12a7f362945cf11aaf0c..1360a23c9ff8c5bce588e1340b396d116c002c0a 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 @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers 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 84e9939b79c933de2d7fb2c93faaff53db6333ea..79aaab7d1087df061b0dcbe98e710b3c51606f2c 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 @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers 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 20ec8be59ffcb089ec2b200b4c4e5296a4d61483..5e55b82109b293177f48825c826f603ac084721f 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby12_displaylist.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby12_displaylist.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers 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 bfa6bad8b431391bb3d261082a3ac0b13bc13f78..f1f63eafc02d8cd499f24e45e0c391fc9e33e1e4 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby24_displaylist.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_page2_paginateby24_displaylist.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/RepresentativeListTest.test_sorting.content b/memopol/tests/response_fixtures/RepresentativeListTest.test_sorting.content index 96a275bb758eb4ca2e8f817be0a0517dd3dfd958..6ec2b23950cbf2b8dbc84d6ad1ebb034de1d814e 100644 --- a/memopol/tests/response_fixtures/RepresentativeListTest.test_sorting.content +++ b/memopol/tests/response_fixtures/RepresentativeListTest.test_sorting.content @@ -74,6 +74,11 @@ Committees
  • +
  • + + Themes + +
  • Dossiers diff --git a/memopol/tests/response_fixtures/ThemesTest.test_theme_detail.content b/memopol/tests/response_fixtures/ThemesTest.test_theme_detail.content new file mode 100644 index 0000000000000000000000000000000000000000..acab50477cc3688856e490180609e00ff1a14acf --- /dev/null +++ b/memopol/tests/response_fixtures/ThemesTest.test_theme_detail.content @@ -0,0 +1,356 @@ + + + + + + + + Home - Political Memory + + + + + + + + + + + + + + + + +
    + + +

    acta

    + +

    + Description + +

    +

    + The Anti-Counterfeiting Trade agreement is a really bad thing, we would like to kill it with fire. + +

    +

    + Links + +

    + + + + + + + + +
    + + Press release on ACTA from La Quadrature du Net + + + Jan. 1, 2008 + +
    +

    + Dossiers + +

    + + + + + + + + + + + + + + +
    + Chambers + + Dossier + + Reference + +
    + + + + + + Resolution on the Anti-Counterfeiting Trade Agreement (ACTA) + + + 2010/2935(RSP)
    +

    + Proposals + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + Chambers + + Dossier + + Reference + + Proposal + + Title + + Recommendation + + Status +
    + + + + + + Resolution on the Anti-Counterfeiting Trade Agreement (ACTA) + + + 2010/2935(RSP) + RC-B7-0617/2010 - Accord commercial anti-contrefaçon (ACAC) - Considérant X +
    + + B7-0617/2010 + + +
    Stop acta !adopted32924975
    + + + + + + Resolution on the Anti-Counterfeiting Trade Agreement (ACTA) + + + 2010/2935(RSP) + RC-B7-0617/2010 - Accord commercial anti-contrefaçon (ACAC) - Considérant CC +
    + + B7-0617/2010 + + +
    Stop acta !adopted31531214
    + + + + + + Resolution on the Anti-Counterfeiting Trade Agreement (ACTA) + + + 2010/2935(RSP) + RC-B7-0617/2010 - Accord commercial anti-contrefaçon (ACAC) - Résolution +
    + + B7-0617/2010 + + +
    Stop acta !rejected30632226
    +

    + Positions + +

    + + + + + + + + + +
    + Representative + + Date + + Position + + Link + +
    + +
    + + + + + + diff --git a/memopol/tests/response_fixtures/ThemesTest.test_theme_detail.metadata b/memopol/tests/response_fixtures/ThemesTest.test_theme_detail.metadata new file mode 100644 index 0000000000000000000000000000000000000000..a2e0a6921bc4a7d94e1887a6eab7a49889fc3ace --- /dev/null +++ b/memopol/tests/response_fixtures/ThemesTest.test_theme_detail.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/response_fixtures/ThemesTest.test_theme_list.content b/memopol/tests/response_fixtures/ThemesTest.test_theme_list.content new file mode 100644 index 0000000000000000000000000000000000000000..624b22f0ca116dbdac15b379309ca3f1e88758eb --- /dev/null +++ b/memopol/tests/response_fixtures/ThemesTest.test_theme_list.content @@ -0,0 +1,264 @@ + + + + + + + + Home - Political Memory + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + +
    + +
    Filter +
    + +
    + +
    + + + +
    + + + + + + +
    + + +
    +
    + Number of results : 1 + +
    + + +
    + Number of displayed results : + 12 + ( + + 12 + + / + + + 24 + + / + + + 48 + + / + + + 96 + + + ) + +
    +
    +
    + + +

    + Themes + +

    + + + + + + + + + +
    + Name + +
    + + acta + + +
    +
    + + +
    +
    + Number of results : 1 + +
    + + +
    + Number of displayed results : + 12 + ( + + 12 + + / + + + 24 + + / + + + 48 + + / + + + 96 + + + ) + +
    +
    +
    + + + + + +
    + + + + + + diff --git a/memopol/tests/response_fixtures/ThemesTest.test_theme_list.metadata b/memopol/tests/response_fixtures/ThemesTest.test_theme_list.metadata new file mode 100644 index 0000000000000000000000000000000000000000..a2e0a6921bc4a7d94e1887a6eab7a49889fc3ace --- /dev/null +++ b/memopol/tests/response_fixtures/ThemesTest.test_theme_list.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/response_fixtures/ThemesTest.test_theme_search.content b/memopol/tests/response_fixtures/ThemesTest.test_theme_search.content new file mode 100644 index 0000000000000000000000000000000000000000..3108048143e11c8f43bc0c076a287d73c92317bc --- /dev/null +++ b/memopol/tests/response_fixtures/ThemesTest.test_theme_search.content @@ -0,0 +1,264 @@ + + + + + + + + Home - Political Memory + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + +
    + +
    Filter +
    + +
    + +
    + + + +
    + + + + + + +
    + + +
    +
    + Number of results : 1 + +
    + + +
    + Number of displayed results : + 12 + ( + + 12 + + / + + + 24 + + / + + + 48 + + / + + + 96 + + + ) + +
    +
    +
    + + +

    + Themes + +

    + + + + + + + + + +
    + Name + +
    + + acta + + +
    +
    + + +
    +
    + Number of results : 1 + +
    + + +
    + Number of displayed results : + 12 + ( + + 12 + + / + + + 24 + + / + + + 48 + + / + + + 96 + + + ) + +
    +
    +
    + + + + + +
    + + + + + + diff --git a/memopol/tests/response_fixtures/ThemesTest.test_theme_search.metadata b/memopol/tests/response_fixtures/ThemesTest.test_theme_search.metadata new file mode 100644 index 0000000000000000000000000000000000000000..a2e0a6921bc4a7d94e1887a6eab7a49889fc3ace --- /dev/null +++ b/memopol/tests/response_fixtures/ThemesTest.test_theme_search.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/response_fixtures/ThemesTest.test_theme_search_noresults.content b/memopol/tests/response_fixtures/ThemesTest.test_theme_search_noresults.content new file mode 100644 index 0000000000000000000000000000000000000000..d44a2acd8ee084e1adee2a5f78af2ff6b62ee959 --- /dev/null +++ b/memopol/tests/response_fixtures/ThemesTest.test_theme_search_noresults.content @@ -0,0 +1,152 @@ + + + + + + + + Home - Political Memory + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + +
    + +
    Filter +
    + +
    + +
    + + + +
    + + + + + + +
    No matching themes found :(
    + + + + +
    + + + + + + diff --git a/memopol/tests/response_fixtures/ThemesTest.test_theme_search_noresults.metadata b/memopol/tests/response_fixtures/ThemesTest.test_theme_search_noresults.metadata new file mode 100644 index 0000000000000000000000000000000000000000..a2e0a6921bc4a7d94e1887a6eab7a49889fc3ace --- /dev/null +++ b/memopol/tests/response_fixtures/ThemesTest.test_theme_search_noresults.metadata @@ -0,0 +1,3 @@ +{ + "status_code": 200 +} \ No newline at end of file diff --git a/memopol/tests/test_themes.py b/memopol/tests/test_themes.py new file mode 100644 index 0000000000000000000000000000000000000000..49fb078bf0e760942240b6c5b90cf24a7bfe9d39 --- /dev/null +++ b/memopol/tests/test_themes.py @@ -0,0 +1,57 @@ +# -*- coding: utf8 -*- + +from django.test import TestCase + +from memopol_themes.models import Theme + +from .base import ResponseDiffMixin + + +class ThemesTest(ResponseDiffMixin, TestCase): + fixtures = ['smaller_sample.json'] + + def test_theme_list(self): + # session setup + self.client.get('/theme/') + + # 1 query for theme count + # 1 query for themes + self.responsediff_test('/theme/', 2) + + def test_theme_search(self): + # session setup + self.client.get('/theme/') + + # 1 query for theme count + # 1 query for themes + q = 'acta' + self.responsediff_test('/theme/?search=%s' % q, 2) + + def test_theme_search_noresults(self): + # session setup + self.client.get('/theme/') + + # 1 query for theme count + # nothing else since count = 0 + q = 'no-theme-will-have-that-title-ever' + self.responsediff_test('/theme/?search=%s' % q, 1) + + def test_theme_detail(self): + # Get 1st theme in dataset + theme = Theme.objects.order_by('pk')[0] + + # session setup + self.client.get('/theme/%s/' % theme.pk) + + # 1 query for the theme + # 1 query for links + # 1 query for dossiers + # 1 query for dossier documents + # 1 query for dossier document chambers + # 1 query for proposals + # 1 query for proposals dossiers + # 1 query for proposals dossier documents + # 1 query for proposals dossier document chambers + # 1 query for positions + # 1 query for position representativs + self.responsediff_test('/theme/%s/' % theme.slug, 11) diff --git a/memopol/urls.py b/memopol/urls.py index 848cb768ba9f5f24caf1faa7eba52e6571a14767..57d4c113783948e6362e00e0551c8c828b9e255d 100644 --- a/memopol/urls.py +++ b/memopol/urls.py @@ -11,6 +11,8 @@ from views.group_list import GroupList from views.representative_detail import RepresentativeDetail from views.representative_list import RepresentativeList from views.redirects import RedirectGroupList, RedirectGroupRepresentativeList +from views.theme_detail import ThemeDetail +from views.theme_list import ThemeList import api @@ -84,6 +86,16 @@ urlpatterns = [ ProposalAutocomplete.as_view(), name='proposal-autocomplete', ), + url( + r'^theme/$', + ThemeList.as_view(), + name='theme-list' + ), + url( + r'^theme/(?P[-\w]+)/$', + ThemeDetail.as_view(), + name='theme-detail' + ), url(r'^admin/', include(admin.site.urls)), url(r'^positions/', include('representatives_positions.urls', diff --git a/memopol/views/theme_detail.py b/memopol/views/theme_detail.py new file mode 100644 index 0000000000000000000000000000000000000000..bcd074d8e37ca57cc95b6afeb4d0af474b929a9c --- /dev/null +++ b/memopol/views/theme_detail.py @@ -0,0 +1,15 @@ +# coding: utf-8 + +from django.views import generic + +from memopol_themes.models import Theme + + +class ThemeDetail(generic.DetailView): + queryset = Theme.objects.prefetch_related( + 'links', + 'dossiers__documents__chamber', + 'proposals__recommendation', + 'proposals__dossier__documents__chamber', + 'positions__representative', + ) diff --git a/memopol/views/theme_list.py b/memopol/views/theme_list.py new file mode 100644 index 0000000000000000000000000000000000000000..12b56fcabec8cf40b909ff8ac29c890add34c22b --- /dev/null +++ b/memopol/views/theme_list.py @@ -0,0 +1,30 @@ +# coding: utf-8 + +from core.views import PaginationMixin + +from django.views import generic + +from memopol_themes.models import Theme + +from ..filters import ThemeFilter + + +class ThemeList(PaginationMixin, generic.ListView): + + current_filter = None + queryset = Theme.objects.all() + + def theme_filter(self, qs): + f = ThemeFilter(self.request.GET, queryset=qs) + self.current_filter = f + return f.qs + + def get_queryset(self): + qs = super(ThemeList, self).get_queryset() + qs = self.theme_filter(qs) + return qs + + def get_context_data(self, **kwargs): + c = super(ThemeList, self).get_context_data(**kwargs) + c['filter'] = self.current_filter + return c diff --git a/memopol_themes/migrations/0001_initial.py b/memopol_themes/migrations/0001_initial.py index 6c7d37c7c60194c9d0af1d5fbc1b953182d69d8c..410bab864b8eae4bb909cc2839f1421382eaa6b5 100644 --- a/memopol_themes/migrations/0001_initial.py +++ b/memopol_themes/migrations/0001_initial.py @@ -2,13 +2,14 @@ from __future__ import unicode_literals from django.db import migrations, models +import autoslug.fields class Migration(migrations.Migration): dependencies = [ ('representatives_votes', '0012_document'), - ('representatives_positions', '0002_increase_link_length'), + ('representatives_positions', '0003_remove_position_tags'), ] operations = [ @@ -17,6 +18,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('name', models.CharField(unique=True, max_length=255)), + ('slug', autoslug.fields.AutoSlugField(populate_from=b'name', editable=False)), ('description', models.TextField()), ('dossiers', models.ManyToManyField(related_name='themes', to='representatives_votes.Dossier')), ('positions', models.ManyToManyField(related_name='themes', to='representatives_positions.Position')), diff --git a/memopol_themes/models.py b/memopol_themes/models.py index efc62c325b48482afad021c1a759c0955cf0b926..93760fcff48d20f30e917e427dc9437886341913 100644 --- a/memopol_themes/models.py +++ b/memopol_themes/models.py @@ -1,12 +1,15 @@ from django.db import models from django.utils.encoding import smart_unicode +from autoslug import AutoSlugField + from representatives_votes.models import Dossier, Proposal from representatives_positions.models import Position class Theme(models.Model): name = models.CharField(max_length=255, unique=True) + slug = AutoSlugField(populate_from='name') description = models.TextField() dossiers = models.ManyToManyField(Dossier, related_name='themes') diff --git a/setup.py b/setup.py index a61880c9f9ddc54aa12524a5383da68dcdd4f516..e75551ae47b40be8f235ca295fc80d61aea6aed6 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ setup(name='political-memory', url='http://github.com/political-memory/political_memory/', install_requires=[ 'django-autocomplete-light>=3.0,<4.0', + 'django-autoslug>=1.9,<1.10', 'django-bootstrap3>=6,<7', 'django-coffeescript>=0.7,<0.8', 'django-compressor>=1,<2', diff --git a/templates/_header.haml b/templates/_header.haml index ae7cb83a63def82d26603a96e598aadd632d597b..949e93140af946b7e51e5aab0b22d3a99d03177a 100644 --- a/templates/_header.haml +++ b/templates/_header.haml @@ -32,6 +32,9 @@ %li %a{href: "{% url 'group-list' kind='committee' %}"} - trans 'Committees' + %li + %a{href: "{% url 'theme-list' %}"} + - trans 'Themes' %li %a{href: "{% url 'dossier-list' %}"} - trans 'Dossiers' diff --git a/templates/memopol_themes/theme_detail.haml b/templates/memopol_themes/theme_detail.haml new file mode 100644 index 0000000000000000000000000000000000000000..25f2bafcafc936f49943ef91b2fbac640194bb37 --- /dev/null +++ b/templates/memopol_themes/theme_detail.haml @@ -0,0 +1,132 @@ +- extends "base.html" + +- load i18n +- load memopol_tags + +- block content + + %h1 {{ theme.name }} + + %h2 + - trans "Description" + + %p.description + {{ theme.description }} + + %h2 + - trans "Links" + + %table.table + + - for link in theme.links.all + %tr + %td + %a.external{'href': '{{ link.link }}', target:'_blank'} + = link.title + %td + = link.datetime + + %h2 + - trans "Dossiers" + + %table.table + %tr + %th + - trans "Chambers" + %th + - trans "Dossier" + %th + - trans "Reference" + + - for dossier in theme.dossiers.all + %tr + %td + - for chamber in dossier.chambers + = chamber | chamber_small_icon + %td + %a{'href': "{% url 'dossier-detail' dossier.pk %}"} + {{ dossier.title }} + + %td= dossier.reference + + %h2 + - trans "Proposals" + + %table.table + %tr + %th + - trans "Chambers" + %th + - trans "Dossier" + %th + - trans "Reference" + %th + - trans "Proposal" + %th + - trans "Title" + %th + - trans "Recommendation" + %th + - trans "Status" + %th= "for" | position_icon + %th= "against" | position_icon + %th= "abstain" | position_icon + + - for proposal in theme.proposals.all + + %tr + %td + - for chamber in proposal.dossier.chambers + = chamber | chamber_small_icon + %td + %a{'href': "{% url 'dossier-detail' proposal.dossier.pk %}"} + {{ proposal.dossier.title }} + + %td= proposal.dossier.reference + + %td + = proposal.title + %br + %small + {{ proposal.reference }} + + - if proposal.recommendation + + %td= proposal.recommendation.title + %td= proposal.recommendation.recommendation | position_icon + + - else + %td.no-recommendation{colspan:2}= "No recommendation" + + %td= proposal.status + %td= proposal.total_for + %td= proposal.total_against + %td= proposal.total_abstain + + + %h2 + - trans "Positions" + + %table.table + %tr + %th + - trans "Representative" + %th + - trans "Date" + %th + - trans "Position" + %th + - trans "Link" + + - for position in theme.positions.all + + %tr.position + %td + = position.representative + %td= position.datetime + %td + %a{:href => '{{ position.get_absolute_url }}'} + =position.text|truncatewords:8 + %td + %a{:href => '{{ position.link }}'} + = position.link diff --git a/templates/memopol_themes/theme_list.haml b/templates/memopol_themes/theme_list.haml new file mode 100644 index 0000000000000000000000000000000000000000..c91e6c843dec16d7358bb8a0238dbee14f5c4430 --- /dev/null +++ b/templates/memopol_themes/theme_list.haml @@ -0,0 +1,38 @@ +- extends "base.html" +- load i18n +- load memopol_tags + +- block head + + {{ filter.form.media }} + +- block content + + - block search + + {% url 'theme-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 themes found :(" + + - else + + - include 'core/blocks/pagination.html' + + %h1 + - trans "Themes" + + %table.table + %tr + %th + - trans "Name" + + - for theme in object_list + %tr + %td= + %a{'href': "{% url 'theme-detail' theme.slug %}"} + {{ theme.name }} + + - include "core/blocks/pagination.html"