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 all commits
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
5 changes: 4 additions & 1 deletion camp_fin/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@
</a>
<ul class="dropdown-menu">
<li>
<a href="{% url 'downloads' %}">Campaign finance</a>
<a href="{% url 'camp-fin-downloads' %}">Campaign finance</a>
</li>
<li>
<a href="{% url 'lobbyist-downloads' %}">Lobbyists</a>
</li>
</ul>
</li>
Expand Down
15 changes: 13 additions & 2 deletions camp_fin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +28,8 @@
ContributionDownloadViewSet,
ContributionViewSet,
DonationsView,
DownloadView,
CampaignFinanceDownloadView,
LobbyistDownloadView,
ExpenditureDetail,
ExpenditureDownloadViewSet,
ExpenditureViewSet,
Expand All @@ -44,6 +46,7 @@
TopEarnersWidgetView,
TopExpensesView,
TransactionViewSet,
downloads_redirect_view,
bulk_candidates,
bulk_committees,
bulk_employers,
Expand Down Expand Up @@ -102,12 +105,20 @@
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(),
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"
),
Copy link
Member

Choose a reason for hiding this comment

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

let's add a 301 redirect from downlods to camp-find-downloads.

path("organizations/", OrganizationList.as_view(), name="organization-list"),
path(
r"organizations/<slug:slug>/",
Expand Down
88 changes: 61 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 @@ -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)
Expand All @@ -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

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,46 +67,6 @@ <h4 class="col-xs-12">
<br/><br />
</div>
</div>

<div class="row mb-3">
<h3>
<i class="fa fa-table"></i>
Independent Expenditures
</h3>
<a href="https://openness-project-nmid.s3.amazonaws.com/independent_expenditures.xlsx" target="_blank">
Download Independent Expenditures Spreadsheet
</a>
<div class="col-xs-12">
<br/><br />
</div>
</div>

<div class="row mb-3">
<h3>
<i class="fa fa-table"></i>
Lobbyist Employer
</h3>
<a href="https://openness-project-nmid.s3.amazonaws.com/lobbyist_employer.xlsx" target="_blank">
Download Lobbyist Employer Spreadsheet
</a>
<div class="col-xs-12">
<br/><br />
</div>
</div>

<div class="row mb-3">
<h3>
<i class="fa fa-table"></i>
Lobbyist
</h3>
<a href="https://openness-project-nmid.s3.amazonaws.com/lobbyist.xlsx" target="_blank">
Download Lobbyist Spreadsheet
</a>
<div class="col-xs-12">
<br/><br />
</div>
</div>

</div>
</div>

Expand Down
57 changes: 57 additions & 0 deletions pages/templates/lobbyist_downloads.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% extends 'base.html' %}
{% load static %}

{% block title %}Data downloads{% endblock %}

{% block full_content %}
<div class="container">
<div class='row'>
<div class='col-sm-8 col-sm-offset-2'>
<h1 id='download'><i class='fa fa-fw fa-download'></i> Lobbyist data downloads</h1>
<hr />
{{ page.text|safe }}

<div class="row mb-3">
<h3>
<i class="fa fa-table"></i>
Independent Expenditures
</h3>
<a href="https://openness-project-nmid.s3.amazonaws.com/independent_expenditures.xlsx" target="_blank">
Download Independent Expenditures Spreadsheet
</a>
<div class="col-xs-12">
<br/><br />
</div>
</div>

<div class="row mb-3">
<h3>
<i class="fa fa-table"></i>
Lobbyist Employer
</h3>
<a href="https://openness-project-nmid.s3.amazonaws.com/lobbyist_employer.xlsx" target="_blank">
Download Lobbyist Employer Spreadsheet
</a>
<div class="col-xs-12">
<br/><br />
</div>
</div>

<div class="row mb-3">
<h3>
<i class="fa fa-table"></i>
Lobbyist
</h3>
<a href="https://openness-project-nmid.s3.amazonaws.com/lobbyist.xlsx" target="_blank">
Download Lobbyist Spreadsheet
</a>
<div class="col-xs-12">
<br/><br />
</div>
</div>

</div>
</div>

</div>
{% endblock %}
Loading