From 9055c81e9d708ca827eef22112c403d025fcab3a Mon Sep 17 00:00:00 2001 From: Eric van Zanten Date: Thu, 17 Jan 2019 09:51:00 -0600 Subject: [PATCH 1/3] Put lobbyist tables on homepage. Make candidate and committee tables on home page make sense --- camp_fin/templates/index.html | 212 +++++++++--------------- camp_fin/templates/lobbyist-portal.html | 4 +- camp_fin/views.py | 105 +++++------- 3 files changed, 121 insertions(+), 200 deletions(-) diff --git a/camp_fin/templates/index.html b/camp_fin/templates/index.html index 4caf660..b0965bb 100644 --- a/camp_fin/templates/index.html +++ b/camp_fin/templates/index.html @@ -2,6 +2,7 @@ {% load helpers %} {% load staticfiles %} {% load explainer %} +{% load humanize %} {% block title %} Keep an eye on money in New Mexico politics @@ -55,137 +56,84 @@

Keep an eye on money in New Mexico politics

{{ page.text|safe }} - -
-
- -

- - {{ year }} - Race for Governor +
+
+

+ + New Mexico Lobbyists +
+ + Browse lobbyists and their employers in New Mexico + +

+
+
+
+
+

+ + + {{ total_lobbyist_contributions|format_money_short }} + + raised for candidates and committees +

+

+ + + {{ total_lobbyist_expenditures|format_money_short }} + + spent on lobbying +

+
+
+
+{% if page.text %} +
+
+ {{ page.text|safe }} +
+
+{% endif %} +
+
+

+ + Browse {{ num_lobbyists|intcomma }} + lobbyists +

+ {% with sortable=False %} + {% include 'camp_fin/widgets/lobbyist-list.html' %} + {% endwith %} +

+ + + See more top lobbyists > -

- {{ home_page_governors_race|safe }} - - - - - - - - - - {% for campaign in governor_race.active_campaigns %} - - - - - - {% endfor %} - -
Candidate - Cash on hand - {% explainer "The amount of available funds that the campaign reported at the time of the last filing date. This number does not include outstanding debts." %} - - Total funds raised since {{ last_year }} - {% explainer "'Funds raised' includes both contributions and loans to the campaign." %} -
- - {{ campaign.candidate.full_name }} - - {% if campaign.party_identifier %} - - - ({{ campaign.party_identifier }}) - - - {% endif %} - {% if campaign.is_winner %} - - {% endif %} - - - - - {{ campaign.cash_on_hand | format_money_short }} - - - - - {% funds_raised campaign last_year short=True %} - -
- -

View details of the race for Governor >



- -

- - - Other top {{ year }} races +

+
+

+
+
+
+

+ + Browse {{ num_employers|intcomma }} + employers + paying lobbyists +

+ {% include 'camp_fin/widgets/organization-list.html' %} +

+ + + See more top lobbyist employers > - - {{ home_page_contested_races|safe }} - {% with races=top_races %} - {% include 'camp_fin/widgets/races_list.html' %} - {% endwith %} - -

More top races >



- -

Largest donations

- {{ home_page_largest_donations|safe }} - - - - - - - - - - - - {% for transaction in transaction_objects %} - - - - - - - {% endfor %} - -
- Donor - - Amount {{ sort_order|get_sort_icon|safe }} - - Recipient -
- {{ transaction.full_name }} - - - - - {{ transaction.amount|format_money_short }} - - - - {% if transaction.pac_slug %} - {{ transaction.transaction_subject }} - {% endif %} - {% if transaction.candidate_slug %} - {{ transaction.transaction_subject }} - {% endif %} -
+

+

+
+
-

Browse donations >



+
+

Top candidates

{{ home_page_top_candidates|safe }} @@ -247,14 +195,6 @@

Top Committees

Browse committees >



-

Top lobbyists

- {{ home_page_top_lobbyists|safe }} - {% with sortable=False %} - {% include 'camp_fin/widgets/lobbyist-list.html' %} - {% endwith %} - -

See more on the lobbyist portal >



-

About

{{ home_page_about|safe }}
diff --git a/camp_fin/templates/lobbyist-portal.html b/camp_fin/templates/lobbyist-portal.html index 771b22f..9269dbd 100644 --- a/camp_fin/templates/lobbyist-portal.html +++ b/camp_fin/templates/lobbyist-portal.html @@ -23,14 +23,14 @@

- {{ total_contributions|format_money_short }} + {{ total_lobbyist_contributions|format_money_short }} raised for candidates and committees

- {{ total_expenditures|format_money_short }} + {{ total_lobbyist_expenditures|format_money_short }} spent on lobbying

diff --git a/camp_fin/views.py b/camp_fin/views.py index d256677..948d948 100644 --- a/camp_fin/views.py +++ b/camp_fin/views.py @@ -84,7 +84,45 @@ def get_context_data(self, **kwargs): return context -class IndexView(TopEarnersBase, PagesMixin): +class LobbyistContextMixin(object): + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + context['lobbyists'] = Lobbyist.top(limit=5) + context['organizations'] = Organization.top(limit=5) + + context['num_lobbyists'] = Lobbyist.objects.count() + context['num_employers'] = Organization.objects.count() + + get_total_contributions = ''' + SELECT SUM(political_contributions) + FROM camp_fin_lobbyistreport + ''' + + get_total_expenditures = ''' + SELECT SUM(expenditures) + FROM camp_fin_lobbyistreport + ''' + + with connection.cursor() as cursor: + cursor.execute(get_total_contributions) + context['total_lobbyist_contributions'] = cursor.fetchone()[0] + + cursor.execute(get_total_expenditures) + context['total_lobbyist_expenditures'] = cursor.fetchone()[0] + + seo = {} + seo.update(settings.SITE_META) + + seo['title'] = "Lobbyist portal - The Openness Project" + seo['site_desc'] = 'Browse lobbyists and their employers in New Mexico politics.' + + context['seo'] = seo + + return context + + +class IndexView(TopEarnersBase, LobbyistContextMixin, PagesMixin): template_name = 'index.html' page_path = '/' @@ -150,6 +188,7 @@ def get_context_data(self, **kwargs): JOIN camp_fin_filing AS filing USING(entity_id) WHERE filing.date_added >= '{year}-01-01' + AND filing.closing_balance IS NOT NULL ORDER BY pac.id, filing.date_added desc ) AS pac ) AS s @@ -185,6 +224,7 @@ def get_context_data(self, **kwargs): JOIN camp_fin_office AS office ON campaign.office_id = office.id WHERE filing.date_added >= '{year}-01-01' + AND filing.closing_balance IS NOT NULL ORDER BY candidate.id, filing.date_added DESC ) AS candidates ) AS s @@ -199,72 +239,13 @@ def get_context_data(self, **kwargs): context['pac_objects'] = pac_objects context['candidate_objects'] = candidate_objects - # Race for governor - gov_race = Race.objects.filter(office__description='Governor')\ - .filter(election_season__year=year)\ - .first() - - context['governor_race'] = gov_race - - # Hottest races - top_races = Race.objects.filter(election_season__year=year)\ - .exclude(office__description='Governor')\ - .order_by('-total_contributions')\ - .prefetch_related('campaign_set')\ - .prefetch_related('campaign_set__race')\ - .prefetch_related('campaign_set__political_party')\ - .prefetch_related('campaign_set__candidate')\ - .prefetch_related('campaign_set__candidate__entity') - - # Only get the ten top races - context['top_races'] = top_races[:10] - context['verbose_type'] = 'all' - - # Lobbyists - context['lobbyists'] = Lobbyist.top(limit=5) - return context -class LobbyistPortal(PagesMixin): + +class LobbyistPortal(LobbyistContextMixin, PagesMixin): template_name = 'lobbyist-portal.html' page_path = '/lobbyist-portal/' - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - - context['lobbyists'] = Lobbyist.top(limit=5) - context['organizations'] = Organization.top(limit=5) - - context['num_lobbyists'] = Lobbyist.objects.count() - context['num_employers'] = Organization.objects.count() - - get_total_contributions = ''' - SELECT SUM(political_contributions) - FROM camp_fin_lobbyistreport - ''' - - get_total_expenditures = ''' - SELECT SUM(expenditures) - FROM camp_fin_lobbyistreport - ''' - - with connection.cursor() as cursor: - cursor.execute(get_total_contributions) - context['total_contributions'] = cursor.fetchone()[0] - - cursor.execute(get_total_expenditures) - context['total_expenditures'] = cursor.fetchone()[0] - - seo = {} - seo.update(settings.SITE_META) - - seo['title'] = "Lobbyist portal - The Openness Project" - seo['site_desc'] = 'Browse lobbyists and their employers in New Mexico politics.' - - context['seo'] = seo - - return context - class RacesView(PaginatedList): template_name = 'camp_fin/races.html' From 057aac230b7bc762dc8a13b4fa9f436233194c48 Mon Sep 17 00:00:00 2001 From: Eric van Zanten Date: Thu, 17 Jan 2019 09:56:20 -0600 Subject: [PATCH 2/3] Add a bit of clarifying text --- camp_fin/templates/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/camp_fin/templates/index.html b/camp_fin/templates/index.html index b0965bb..dd44950 100644 --- a/camp_fin/templates/index.html +++ b/camp_fin/templates/index.html @@ -75,14 +75,14 @@

{{ total_lobbyist_contributions|format_money_short }} - raised for candidates and committees + raised for candidates and committees since 2013

{{ total_lobbyist_expenditures|format_money_short }} - spent on lobbying + spent on lobbying since 2013


From c2a23cc0a184684fbf9f079c1506f79ea372311c Mon Sep 17 00:00:00 2001 From: Eric van Zanten Date: Thu, 17 Jan 2019 09:56:57 -0600 Subject: [PATCH 3/3] Add clarity to homepage as well --- camp_fin/templates/lobbyist-portal.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/camp_fin/templates/lobbyist-portal.html b/camp_fin/templates/lobbyist-portal.html index 9269dbd..f1cf111 100644 --- a/camp_fin/templates/lobbyist-portal.html +++ b/camp_fin/templates/lobbyist-portal.html @@ -25,14 +25,14 @@

{{ total_lobbyist_contributions|format_money_short }} - raised for candidates and committees + raised for candidates and committees since 2013

{{ total_lobbyist_expenditures|format_money_short }} - spent on lobbying + spent on lobbying since 2013