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

Put lobbyist info on homepage #157

Merged
merged 3 commits into from
Jan 18, 2019
Merged
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
212 changes: 76 additions & 136 deletions camp_fin/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load helpers %}
{% load staticfiles %}
{% load explainer %}
{% load humanize %}

{% block title %}
Keep an eye on money in New Mexico politics
Expand Down Expand Up @@ -55,137 +56,84 @@ <h1>Keep an eye on money in New Mexico politics</h1>
{{ page.text|safe }}
</div>
</div>

<div class='row'>
<div class='col-sm-12'>

<h2>
<a href="{% url 'race-detail' governor_race.id %}">
<i class='fa fa-star'></i> {{ year }}
Race for Governor
<div class="row">
<div class='col-xs-12'>
<h1>
<i class="fa fa-fw fa-university"></i>
New Mexico Lobbyists
<br/>
<small>
Browse lobbyists and their employers in New Mexico
</small>
</h1>
</div>
</div>
<div class="row">
<div class="col-xs-12 lobbyist-stats">
<p>
<span class="green">
<i class="fa fa-fw fa-plus-circle"></i>
{{ total_lobbyist_contributions|format_money_short }}
</span>
raised for candidates and committees since 2013
</p>
<p>
<span class="red">
<i class="fa fa-fw fa-minus-circle"></i>
{{ total_lobbyist_expenditures|format_money_short }}
</span>
spent on lobbying since 2013
</p>
</div>
<hr/>
</div>
{% if page.text %}
<div class="row">
<div class="col-xs-12 col-md-10">
{{ page.text|safe }}
</div>
</div>
{% endif %}
<div class="row">
<div class="col-xs-12">
<h3>
<i class="fa fa-fw fa-user"></i>
Browse {{ num_lobbyists|intcomma }}
<a href="{% url 'lobbyist-list' %}">lobbyists</a>
</h3>
{% with sortable=False %}
{% include 'camp_fin/widgets/lobbyist-list.html' %}
{% endwith %}
<p>
<a href="{% url 'lobbyist-list' %}" class='btn btn-danger'>
<i class='fa fa-fw fa-user'></i>
See more top lobbyists >
</a>
</h2>
{{ home_page_governors_race|safe }}
<table class="table table-striped">
<thead>
<tr>
<th>Candidate</th>
<th class="text-right">
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." %}
</th>
<th class="text-right">
Total funds raised since {{ last_year }}
{% explainer "'Funds raised' includes both contributions and loans to the campaign." %}
</th>
</tr>
</thead>
<tbody>
{% for campaign in governor_race.active_campaigns %}
<tr>
<td class="col-sm-6">
<a href="{% url 'candidate-detail' campaign.candidate.slug %}">
{{ campaign.candidate.full_name }}
</a>
{% if campaign.party_identifier %}
<small>
<span class="party-identifier {{ campaign.party_identifier }}">
({{ campaign.party_identifier }})
</span>
</small>
{% endif %}
{% if campaign.is_winner %}
<i class="fa fa-fw fa-check-circle green"></i>
{% endif %}
</a>
</td>
<td class="text-right">
<span class="hidden-sm hidden-xs">
{{ campaign.cash_on_hand | format_money }}
</span>
<span class="visible-sm-block visible-xs-block">
{{ campaign.cash_on_hand | format_money_short }}
</span>
</td>
<td class="text-right">
<span class="hidden-sm hidden-xs">
{% funds_raised campaign last_year %}
</span>
<span class="visible-sm-block visible-xs-block">
{% funds_raised campaign last_year short=True %}
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>

<p><a href="{% url 'race-detail' governor_race.id %}" class='btn btn-danger'><i class='fa fa-star'></i> View details of the race for Governor ></a></p><br /><br />

<h2>
<a href="{% url 'races' %}">
<i class="fa fa-fw fa-check-square-o"></i>
Other top {{ year }} races
</p>
<br />
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h3>
<i class="fa fa-fw fa-users"></i>
Browse {{ num_employers|intcomma }}
<a href="{% url 'organization-list' %}">employers</a>
paying lobbyists
</h3>
{% include 'camp_fin/widgets/organization-list.html' %}
<p>
<a href="{% url 'organization-list' %}" class='btn btn-danger'>
<i class='fa fa-fw fa-user'></i>
See more top lobbyist employers >
</a>
</h2>
{{ home_page_contested_races|safe }}
{% with races=top_races %}
{% include 'camp_fin/widgets/races_list.html' %}
{% endwith %}

<p><a href="{% url 'races' %}" class='btn btn-danger'><i class='fa fa-plus-circle'></i> More top races ></a></p><br /><br />

<h2><a href='/donations/'><i class='fa fa-dollar'></i> Largest donations</a></h2>
{{ home_page_largest_donations|safe }}
<table class='table table-striped'>
<thead>
<tr>
<th>
Donor
</th>

<th>
Amount {{ sort_order|get_sort_icon|safe }}
</th>
<th>
Recipient
</th>
<th class='hidden-sm hidden-xs'>
Date
</th>
</tr>
</thead>
<tbody>
{% for transaction in transaction_objects %}
<tr>
<td>
{{ transaction.full_name }}
</td>
<td class='no-wrap'>
<a href="{% url 'contribution-detail' transaction.id %}">
<span class='hidden-sm hidden-xs'>{{transaction.transaction_type|get_transaction_verb }}</span>
<strong class='hidden-sm hidden-xs'>{{ transaction.amount|format_money }}</strong>
<strong class='visible-sm-block visible-xs-block'>{{ transaction.amount|format_money_short }}</strong>
<span class='hidden-sm hidden-xs'>to</span>
</a>
</td>
<td>
{% if transaction.pac_slug %}
<a href="{% url 'committee-detail' transaction.pac_slug %}">{{ transaction.transaction_subject }}</a>
{% endif %}
{% if transaction.candidate_slug %}
<a href="{% url 'candidate-detail' transaction.candidate_slug %}">{{ transaction.transaction_subject }}</a>
{% endif %}
</td>
<td class='no-wrap hidden-sm hidden-xs'>
{{ transaction.received_date|date:"M j, Y" }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</p>
<br /><br />
</div>
</div>

<p><a href='/donations/' class='btn btn-danger'><i class='fa fa-dollar'></i> Browse donations ></a></p><br /><br />
<div class='row'>
<div class='col-sm-12'>

<h2><a href='/candidates/'><i class='fa fa-user'></i> Top candidates</a></h2>
{{ home_page_top_candidates|safe }}
Expand Down Expand Up @@ -247,14 +195,6 @@ <h2><a href='/committees/'><i class='fa fa-group'></i> Top Committees</a></h2>

<p><a href='/committees/' class='btn btn-danger'><i class='fa fa-group'></i> Browse committees ></a></p><br /><br />

<h2><a href="{% url 'lobbyist-portal' %}"><i class='fa fa-university'></i> Top lobbyists</a></h2>
{{ home_page_top_lobbyists|safe }}
{% with sortable=False %}
{% include 'camp_fin/widgets/lobbyist-list.html' %}
{% endwith %}

<p><a href="{% url 'lobbyist-portal' %}" class='btn btn-danger'><i class='fa fa-university'></i> See more on the lobbyist portal ></a></p><br /><br />

<h2><a href='/about/'><i class='fa fa-fw fa-info-circle'></i> About</a></h2>
{{ home_page_about|safe }}
</div>
Expand Down
8 changes: 4 additions & 4 deletions camp_fin/templates/lobbyist-portal.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ <h1>
<p>
<span class="green">
<i class="fa fa-fw fa-plus-circle"></i>
{{ total_contributions|format_money_short }}
{{ total_lobbyist_contributions|format_money_short }}
</span>
raised for candidates and committees
raised for candidates and committees since 2013
</p>
<p>
<span class="red">
<i class="fa fa-fw fa-minus-circle"></i>
{{ total_expenditures|format_money_short }}
{{ total_lobbyist_expenditures|format_money_short }}
</span>
spent on lobbying
spent on lobbying since 2013
</p>
</div>
<hr/>
Expand Down
105 changes: 43 additions & 62 deletions camp_fin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,45 @@ def get_context_data(self, **kwargs):
return context


class IndexView(TopEarnersBase, PagesMixin):
class LobbyistContextMixin(object):
Copy link
Member

Choose a reason for hiding this comment

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

smart!

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 = '/'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -199,72 +239,13 @@ def get_context_data(self, **kwargs):
context['pac_objects'] = pac_objects
context['candidate_objects'] = candidate_objects

# Race for governor
hancush marked this conversation as resolved.
Show resolved Hide resolved
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'
Expand Down