Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate lobbyist download page #222

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions camp_fin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
TopEarnersWidgetView,
TopExpensesView,
TransactionViewSet,
downloads_redirect_view,
bulk_candidates,
bulk_committees,
bulk_employers,
Expand Down Expand Up @@ -104,6 +105,7 @@
name="expenditure-detail",
),
path("committees/", CommitteeList.as_view(), name="committee-list"),
path("downloads/", downloads_redirect_view, name="downloads"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can just do

path("downloads/",
     HttpResponsePermanentRedirect(reverse("camp-fin-downloads")),
     name="downloads"),

seems clearer than creating a custom view that's just wrapping that up.

path(
r"committees/<slug:slug>/",
CommitteeDetail.as_view(),
Expand Down
68 changes: 41 additions & 27 deletions camp_fin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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()

Expand Down
Loading