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..dc3fb74 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, @@ -44,6 +46,7 @@ TopEarnersWidgetView, TopExpensesView, TransactionViewSet, + downloads_redirect_view, bulk_candidates, bulk_committees, bulk_employers, @@ -102,12 +105,20 @@ name="expenditure-detail", ), path("committees/", CommitteeList.as_view(), name="committee-list"), + path("downloads/", downloads_redirect_view, name="downloads"), path( r"committees//", 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..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 @@ -129,9 +134,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) @@ -146,9 +151,29 @@ 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 + + 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 @@ -186,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 @@ -422,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 @@ -567,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 @@ -1120,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 @@ -1922,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 @@ -1936,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() 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..de73328 --- /dev/null +++ b/pages/templates/lobbyist_downloads.html @@ -0,0 +1,57 @@ +{% 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 %}