From 0f7a6afcbeea35791d0c84f67e135395b6edb948 Mon Sep 17 00:00:00 2001 From: msj Date: Wed, 23 Oct 2024 10:15:08 -0400 Subject: [PATCH 1/5] Add separate lobbyist download page --- camp_fin/templates/base.html | 5 +- camp_fin/urls.py | 13 ++- camp_fin/views.py | 26 ++++- ...downloads.html => camp_fin_downloads.html} | 40 -------- pages/templates/lobbyist_downloads.html | 95 +++++++++++++++++++ 5 files changed, 133 insertions(+), 46 deletions(-) rename pages/templates/{downloads.html => camp_fin_downloads.html} (74%) create mode 100644 pages/templates/lobbyist_downloads.html diff --git a/camp_fin/templates/base.html b/camp_fin/templates/base.html index 940348c..1fc68da 100644 --- a/camp_fin/templates/base.html +++ b/camp_fin/templates/base.html @@ -106,7 +106,10 @@ diff --git a/camp_fin/urls.py b/camp_fin/urls.py index b9536f5..ca04db0 100644 --- a/camp_fin/urls.py +++ b/camp_fin/urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ + from django.contrib import admin from django.urls import include, path from rest_framework import routers @@ -27,7 +28,8 @@ ContributionDownloadViewSet, ContributionViewSet, DonationsView, - DownloadView, + CampaignFinanceDownloadView, + LobbyistDownloadView, ExpenditureDetail, ExpenditureDownloadViewSet, ExpenditureViewSet, @@ -107,7 +109,14 @@ CommitteeDetail.as_view(), name="committee-detail", ), - path("downloads/", DownloadView.as_view(), name="downloads"), + path( + "camp-fin-downloads/", + CampaignFinanceDownloadView.as_view(), + name="camp-fin-downloads", + ), + path( + "lobbyist-downloads/", LobbyistDownloadView.as_view(), name="lobbyist-downloads" + ), path("organizations/", OrganizationList.as_view(), name="organization-list"), path( r"organizations//", diff --git a/camp_fin/views.py b/camp_fin/views.py index b18ef03..3b61afa 100644 --- a/camp_fin/views.py +++ b/camp_fin/views.py @@ -129,9 +129,9 @@ def get_context_data(self, **kwargs): return context -class DownloadView(PagesMixin): - template_name = "downloads.html" - page_path = "/downloads/" +class CampaignFinanceDownloadView(PagesMixin): + template_name = "camp_fin_downloads.html" + page_path = "/camp-fin-downloads/" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -155,6 +155,26 @@ def get_context_data(self, **kwargs): return context +class LobbyistDownloadView(PagesMixin): + template_name = "lobbyist_downloads.html" + page_path = "/lobbyist-downloads/" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + seo = {} + seo.update(settings.SITE_META) + + seo["title"] = "Data downloads" + seo[ + "site_desc" + ] = "Download campaign finance data from New Mexico In Depth’s Money Trail NM" + + context["seo"] = seo + + return context + + class LobbyistContextMixin(object): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) diff --git a/pages/templates/downloads.html b/pages/templates/camp_fin_downloads.html similarity index 74% rename from pages/templates/downloads.html rename to pages/templates/camp_fin_downloads.html index cdee42e..0dc1f8c 100644 --- a/pages/templates/downloads.html +++ b/pages/templates/camp_fin_downloads.html @@ -67,46 +67,6 @@



- -
-

- - Independent Expenditures -

- - Download Independent Expenditures Spreadsheet - -
-

-
-
- -
-

- - Lobbyist Employer -

- - Download Lobbyist Employer Spreadsheet - -
-

-
-
- -
-

- - Lobbyist -

- - Download Lobbyist Spreadsheet - -
-

-
-
- diff --git a/pages/templates/lobbyist_downloads.html b/pages/templates/lobbyist_downloads.html new file mode 100644 index 0000000..bf74876 --- /dev/null +++ b/pages/templates/lobbyist_downloads.html @@ -0,0 +1,95 @@ +{% extends 'base.html' %} +{% load static %} + +{% block title %}Data downloads{% endblock %} + +{% block full_content %} +
+
+
+

Lobbyist Data downloads

+
+ {{ page.text|safe }} + +
+

+ + Independent Expenditures +

+ + Download Independent Expenditures Spreadsheet + +
+

+
+
+ +
+

+ + Lobbyist Employer +

+ + Download Lobbyist Employer Spreadsheet + +
+

+
+
+ +
+

+ + Lobbyist +

+ + Download Lobbyist Spreadsheet + +
+

+
+
+ +
+
+ +
+{% endblock %} + +{% block extra_js %} + + + +{% endblock %} + From b087e6d70bed9d544ffbd3b058481760e4a7d156 Mon Sep 17 00:00:00 2001 From: msj Date: Wed, 23 Oct 2024 10:24:35 -0400 Subject: [PATCH 2/5] Fix title --- pages/templates/lobbyist_downloads.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/templates/lobbyist_downloads.html b/pages/templates/lobbyist_downloads.html index bf74876..07b85ff 100644 --- a/pages/templates/lobbyist_downloads.html +++ b/pages/templates/lobbyist_downloads.html @@ -7,7 +7,7 @@
-

Lobbyist Data downloads

+

Lobbyist data downloads


{{ page.text|safe }} From 02bd9b8436b2cacb07b4f2f7d537cf29014cbf4a Mon Sep 17 00:00:00 2001 From: msj Date: Wed, 23 Oct 2024 11:38:56 -0400 Subject: [PATCH 3/5] Add 301 redirect for old downloads path --- camp_fin/urls.py | 2 ++ camp_fin/views.py | 68 ++++++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/camp_fin/urls.py b/camp_fin/urls.py index ca04db0..dc3fb74 100644 --- a/camp_fin/urls.py +++ b/camp_fin/urls.py @@ -46,6 +46,7 @@ TopEarnersWidgetView, TopExpensesView, TransactionViewSet, + downloads_redirect_view, bulk_candidates, bulk_committees, bulk_employers, @@ -104,6 +105,7 @@ name="expenditure-detail", ), path("committees/", CommitteeList.as_view(), name="committee-list"), + path("downloads/", downloads_redirect_view, name="downloads"), path( r"committees//", CommitteeDetail.as_view(), diff --git a/camp_fin/views.py b/camp_fin/views.py index 3b61afa..a8a2a9f 100644 --- a/camp_fin/views.py +++ b/camp_fin/views.py @@ -11,7 +11,12 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.db import connection from django.db.models import Max, Q -from django.http import HttpResponse, StreamingHttpResponse +from django.http import ( + HttpResponse, + StreamingHttpResponse, + HttpResponsePermanentRedirect, +) +from django.urls import reverse from django.shortcuts import render from django.utils import timezone from django.utils.decorators import method_decorator @@ -146,9 +151,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Data downloads" - seo[ - "site_desc" - ] = "Download campaign finance data from New Mexico In Depth’s Money Trail NM" + seo["site_desc"] = ( + "Download campaign finance data from New Mexico In Depth’s Money Trail NM" + ) context["seo"] = seo @@ -166,9 +171,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Data downloads" - seo[ - "site_desc" - ] = "Download campaign finance data from New Mexico In Depth’s Money Trail NM" + seo["site_desc"] = ( + "Download campaign finance data from New Mexico In Depth’s Money Trail NM" + ) context["seo"] = seo @@ -206,9 +211,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Lobbyist portal - Money Trail NM" - seo[ - "site_desc" - ] = "Browse lobbyists and their employers in New Mexico politics." + seo["site_desc"] = ( + "Browse lobbyists and their employers in New Mexico politics." + ) context["seo"] = seo @@ -442,10 +447,10 @@ def get_context_data(self, **kwargs): race_str = str(race) seo["title"] = race_str - seo[ - "site_desc" - ] = "View campaign finance contributions for the {race} in New Mexico".format( - race=race_str + seo["site_desc"] = ( + "View campaign finance contributions for the {race} in New Mexico".format( + race=race_str + ) ) context["seo"] = seo @@ -587,17 +592,17 @@ def get_context_data(self, **kwargs): seo["title"] = "Donations between {start_date} and {end_date}".format( **fmt_args ) - seo[ - "site_desc" - ] = "{count} donations between {start_date} and {end_date} totalling {total}".format( - **fmt_args + seo["site_desc"] = ( + "{count} donations between {start_date} and {end_date} totalling {total}".format( + **fmt_args + ) ) else: seo["title"] = "Donations on {start_date}".format(**fmt_args) - seo[ - "site_desc" - ] = "{count} donations on {start_date} totalling {total}".format(**fmt_args) + seo["site_desc"] = ( + "{count} donations on {start_date} totalling {total}".format(**fmt_args) + ) context["seo"] = seo @@ -1140,9 +1145,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Lobbyist transactions in New Mexico" - seo[ - "site_desc" - ] = "Browse contributions and expenditures of lobbyists in New Mexico" + seo["site_desc"] = ( + "Browse contributions and expenditures of lobbyists in New Mexico" + ) context["seo"] = seo @@ -1942,9 +1947,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Top earners" - seo[ - "site_desc" - ] = "Top earning political committees and candidates in New Mexico" + seo["site_desc"] = ( + "Top earning political committees and candidates in New Mexico" + ) context["seo"] = seo @@ -1956,6 +1961,15 @@ class TopEarnersWidgetView(TopEarnersBase): template_name = "camp_fin/widgets/top-earners.html" +def downloads_redirect_view(request): + """ + Sends a 301 redirect to campaign finance downloads for the previous + generic /downloads/ path. + """ + + return HttpResponsePermanentRedirect(reverse("camp-fin-downloads")) + + def make_response(query, filename, args=[]): cursor = connection.cursor() From 9e42171022dbad96209c0a6d7bc4283392f0fb0c Mon Sep 17 00:00:00 2001 From: msj Date: Wed, 23 Oct 2024 11:40:43 -0400 Subject: [PATCH 4/5] Remove unnecessary js --- pages/templates/lobbyist_downloads.html | 38 ------------------------- 1 file changed, 38 deletions(-) diff --git a/pages/templates/lobbyist_downloads.html b/pages/templates/lobbyist_downloads.html index 07b85ff..de73328 100644 --- a/pages/templates/lobbyist_downloads.html +++ b/pages/templates/lobbyist_downloads.html @@ -55,41 +55,3 @@

{% endblock %} - -{% block extra_js %} - - - -{% endblock %} - From 73e2d8ae235c61cac13955c21fb3959b676216af Mon Sep 17 00:00:00 2001 From: msj Date: Thu, 24 Oct 2024 10:28:55 -0400 Subject: [PATCH 5/5] Refactor downloads redirect --- camp_fin/urls.py | 13 ++++++--- camp_fin/views.py | 68 +++++++++++++++++++---------------------------- 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/camp_fin/urls.py b/camp_fin/urls.py index dc3fb74..a919758 100644 --- a/camp_fin/urls.py +++ b/camp_fin/urls.py @@ -16,10 +16,12 @@ from django.contrib import admin from django.urls import include, path +from django.views.generic import RedirectView from rest_framework import routers from camp_fin.views import ( AboutView, + CampaignFinanceDownloadView, CandidateDetail, CandidateList, CommitteeDetail, @@ -28,14 +30,13 @@ ContributionDownloadViewSet, ContributionViewSet, DonationsView, - CampaignFinanceDownloadView, - LobbyistDownloadView, ExpenditureDetail, ExpenditureDownloadViewSet, ExpenditureViewSet, FinancialDisclosuresView, IndexView, LoanViewSet, + LobbyistDownloadView, LobbyistsView, OrganizationDetail, OrganizationList, @@ -46,7 +47,6 @@ TopEarnersWidgetView, TopExpensesView, TransactionViewSet, - downloads_redirect_view, bulk_candidates, bulk_committees, bulk_employers, @@ -105,7 +105,6 @@ name="expenditure-detail", ), path("committees/", CommitteeList.as_view(), name="committee-list"), - path("downloads/", downloads_redirect_view, name="downloads"), path( r"committees//", CommitteeDetail.as_view(), @@ -119,6 +118,12 @@ path( "lobbyist-downloads/", LobbyistDownloadView.as_view(), name="lobbyist-downloads" ), + # Redirect requests to the old downloads page to campaign finance downloads + path( + "downloads/", + RedirectView.as_view(permanent=True, url="/camp-fin-downloads/"), + name="downloads", + ), path("organizations/", OrganizationList.as_view(), name="organization-list"), path( r"organizations//", diff --git a/camp_fin/views.py b/camp_fin/views.py index a8a2a9f..3b61afa 100644 --- a/camp_fin/views.py +++ b/camp_fin/views.py @@ -11,12 +11,7 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.db import connection from django.db.models import Max, Q -from django.http import ( - HttpResponse, - StreamingHttpResponse, - HttpResponsePermanentRedirect, -) -from django.urls import reverse +from django.http import HttpResponse, StreamingHttpResponse from django.shortcuts import render from django.utils import timezone from django.utils.decorators import method_decorator @@ -151,9 +146,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Data downloads" - seo["site_desc"] = ( - "Download campaign finance data from New Mexico In Depth’s Money Trail NM" - ) + seo[ + "site_desc" + ] = "Download campaign finance data from New Mexico In Depth’s Money Trail NM" context["seo"] = seo @@ -171,9 +166,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Data downloads" - seo["site_desc"] = ( - "Download campaign finance data from New Mexico In Depth’s Money Trail NM" - ) + seo[ + "site_desc" + ] = "Download campaign finance data from New Mexico In Depth’s Money Trail NM" context["seo"] = seo @@ -211,9 +206,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Lobbyist portal - Money Trail NM" - seo["site_desc"] = ( - "Browse lobbyists and their employers in New Mexico politics." - ) + seo[ + "site_desc" + ] = "Browse lobbyists and their employers in New Mexico politics." context["seo"] = seo @@ -447,10 +442,10 @@ def get_context_data(self, **kwargs): race_str = str(race) seo["title"] = race_str - seo["site_desc"] = ( - "View campaign finance contributions for the {race} in New Mexico".format( - race=race_str - ) + seo[ + "site_desc" + ] = "View campaign finance contributions for the {race} in New Mexico".format( + race=race_str ) context["seo"] = seo @@ -592,17 +587,17 @@ def get_context_data(self, **kwargs): seo["title"] = "Donations between {start_date} and {end_date}".format( **fmt_args ) - seo["site_desc"] = ( - "{count} donations between {start_date} and {end_date} totalling {total}".format( - **fmt_args - ) + seo[ + "site_desc" + ] = "{count} donations between {start_date} and {end_date} totalling {total}".format( + **fmt_args ) else: seo["title"] = "Donations on {start_date}".format(**fmt_args) - seo["site_desc"] = ( - "{count} donations on {start_date} totalling {total}".format(**fmt_args) - ) + seo[ + "site_desc" + ] = "{count} donations on {start_date} totalling {total}".format(**fmt_args) context["seo"] = seo @@ -1145,9 +1140,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Lobbyist transactions in New Mexico" - seo["site_desc"] = ( - "Browse contributions and expenditures of lobbyists in New Mexico" - ) + seo[ + "site_desc" + ] = "Browse contributions and expenditures of lobbyists in New Mexico" context["seo"] = seo @@ -1947,9 +1942,9 @@ def get_context_data(self, **kwargs): seo.update(settings.SITE_META) seo["title"] = "Top earners" - seo["site_desc"] = ( - "Top earning political committees and candidates in New Mexico" - ) + seo[ + "site_desc" + ] = "Top earning political committees and candidates in New Mexico" context["seo"] = seo @@ -1961,15 +1956,6 @@ class TopEarnersWidgetView(TopEarnersBase): template_name = "camp_fin/widgets/top-earners.html" -def downloads_redirect_view(request): - """ - Sends a 301 redirect to campaign finance downloads for the previous - generic /downloads/ path. - """ - - return HttpResponsePermanentRedirect(reverse("camp-fin-downloads")) - - def make_response(query, filename, args=[]): cursor = connection.cursor()