Skip to content
This repository has been archived by the owner on May 13, 2019. It is now read-only.

Commit

Permalink
Huge refactor of entity views to make section loading cleaner.
Browse files Browse the repository at this point in the history
  • Loading branch information
apendleton committed Sep 1, 2011
1 parent e3df0a1 commit 3d548fe
Show file tree
Hide file tree
Showing 20 changed files with 329 additions and 373 deletions.
4 changes: 3 additions & 1 deletion influence/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import datetime
import googleanalytics
import re
from django.utils.datastructures import SortedDict

def bar_validate(data):
''' take a dict formatted for submission to the barchart
Expand Down Expand Up @@ -136,7 +137,8 @@ def prepare_entity_view(request, entity_id, type):
context['cycle'] = cycle
context['entity_info'] = metadata['entity_info']
context['entity_info']['metadata']['source_display_name'] = get_source_display_name(metadata['entity_info']['metadata'])
context['external_links'] = external_sites.get_contribution_links(type, standardized_name, metadata['entity_info']['external_ids'], cycle)

context['sections'] = SortedDict()

if cycle != DEFAULT_CYCLE and unicode(str(cycle)) in metadata['entity_info']['metadata']:
# copy the current cycle's metadata into the generic metadata spot
Expand Down
308 changes: 196 additions & 112 deletions influence/views.py

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions templates/contributions.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
{% load humanize %}

<div class="overviewBar">
{% if not suppress_contrib_graphs %}
{% if not section.suppress_contrib_graphs %}
<a class="toggle">Toggle</a>
{% endif %}
<h3 class="insideBar">Contributions,
<h3 class="insideBar">Campaign Finance,
{% ifequal cycle "-1" %}
{{entity_info.camp_fin_years.start|add:-1}} &#150; {{entity_info.camp_fin_years.end}}
{% else %}
Expand Down Expand Up @@ -51,18 +51,18 @@ <h3 class="insideBar">Contributions,

{% block charts %}

{% if not suppress_contrib_graphs %}
{% if not section.suppress_contrib_graphs %}
{% if entity_info.type == "individual" %}
{% include "indiv_charts.html" %}
{% include "indiv_contributions.html" %}
{% else %}{% if entity_info.type == "politician" %}
{% include "pol_charts.html" %}
{% include "pol_contributions.html" %}
{% else %}{% if entity_info.type == "organization" %}
{% include "org_charts.html" %}
{% include "org_contributions.html" %}
{% else %}{% if entity_info.type == "industry" %}
{% include "industry_charts.html" %}
{% include "industry_contributions.html" %}
{% endif %}{% endif %}{% endif %}{% endif %}
{% else %}
{% if reason == "negative" %}
{% if section.reason == "negative" %}
<p>Due to refunds and other accounting issues, aggregate totals
for this time frame were negative.</p>
{% endif %}
Expand All @@ -73,12 +73,12 @@ <h3 class="insideBar">Contributions,
<div class="clear"></div>

<div class="external">
{% if external_links or partytime_link %}
{% if section.external_links or section.partytime_link %}
For more information on contributions:
{% for link in external_links %}
{% for link in section.external_links %}
<a href="{{ link.url }}" class="external" target="_blank">{{ link.text }}</a>
{% endfor %}
{% if partytime_link %}<a href="{{ partytime_link }}" class="external" target="_blank">Party Time</a>{% endif %}
{% if section.partytime_link %}<a href="{{ section.partytime_link }}" class="external" target="_blank">Party Time</a>{% endif %}
{% endif %}
</div>

Expand Down
48 changes: 20 additions & 28 deletions templates/entity_base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{% extends "search_base.html" %}

{% load influence_extras %}

{% block pagetopics %}: {% spaceless %}
{% filter nonempty_lines|pretty_list %}
{% for section in sections.values %}
{{ section.name }}
{% endfor %}
{% endfilter %}
{% endspaceless %}{% endblock %}

{% block js %}
{% block extrajs %}
<!-- extrajs is where the charts are loaded and must go *before* the --
Expand All @@ -22,16 +32,15 @@
{% block description %}
{% endblock %}
</div>
{% if sections.keys|length > 1 %}
<div id="miniNav" class="withBg">
<ul>
{% if contributions_data %}<li><a href="#contributions">Contributions</a></li>{% endif %}
{% if lobbying_data %}<li><a href="#lobbying">Lobbying</a></li>{% endif %}
{% if earmarks %}<li><a href="#earmarks">Earmarks</a></li>{% endif %}
{% if grants_and_contracts %}<li><a href="#federal_spending">Federal Spending</a></li>{% endif %}
{% if contractor_misconduct %}<li><a href="#contractor_misconduct">Contractor Misconduct</a></li>{% endif %}
{% if epa_echo %}<li><a href="#epa_echo">EPA Violations</a></li>{% endif %}
{% for section_id, section in sections.items %}
<li><a href="#{{ section_id }}">{{ section.name }}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="clear"></div>

<div class="module" id="timeSpan">
Expand All @@ -57,28 +66,11 @@
{% endblock %}
</div>

{% block contributions %}
<a name="contributions"></a>
{% endblock %}

{% block lobbying %}
<a name="lobbying"></a>
{% endblock %}

{% block earmarks %}
<a name="earmarks"></a>
{% endblock %}

{% block grants_and_contracts %}
<a name="federal_spending"></a>
{% endblock %}

{% block contractor_misconduct %}
<a name="contractor_misconduct"></a>
{% endblock %}

{% block epa_echo %}
<a name="epa_echo"></a>
{% block sections %}
{% for section_id, section in sections.items %}
<a name={{ section_id }}></a>
{% include section.template with section=section section_id=section_id %}
{% endfor %}
{% endblock %}

{% endblock %}<!-- end main -->
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<div class="twoColumn chartWrapper">
<div class="chart">
{% if candidates_barchart_data %}
{% if section.candidates_barchart_data %}
<h4 class="withTip">Top Politicians</h4>
<div class="graph" id="recipients_barchart">
<!-- raphael charts here -->
Expand All @@ -22,10 +22,10 @@ <h4 class="withTip">Republicans vs. Democrats</h4>

<div class="clear"></div> <!-- start a new row -->

{% if orgs_barchart_data and orgs_barchart_data != "[]" %}
{% if section.orgs_barchart_data and section.orgs_barchart_data != "[]" %}
<div class="twoColumn chartWrapper">
<div class="chart">
{% if orgs_barchart_data %}
{% if section.orgs_barchart_data %}
<h4 class="withTip">Top Organizations</h4>
<div class="graph" id="orgs_barchart">
<!-- raphael charts here -->
Expand Down
16 changes: 8 additions & 8 deletions templates/indiv_lobbying.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ <h3 class="insideBar">
</div>

<div class="chartModule">
{% if lobbying_with_firm %}
{% if section.lobbying_with_firm %}
<h4>Lobbying by {{ entity_info.name|standardize_individual_name }}</h4>

<div class="twoColumn chartWrapper">
<h5>Lobbied with the Following Firms</h5>
{% for row in lobbying_with_firm %}
{% for row in section.lobbying_with_firm %}
{% if row.registrant_entity %}
<a href="/organization/{{ row.registrant_name|slugify }}/{{ row.registrant_entity }}{{cycle|pretty_cycle}}">{{ row.registrant_name }}</a>{% if forloop.last %}{% else %},{% endif %}
{% else %}
Expand All @@ -30,11 +30,11 @@ <h5>Lobbied with the Following Firms</h5>
{% endfor %}
</div>

{% if issues_lobbied_for %}
{% if section.issues_lobbied_for %}
<div class="issuesLobbied oneColumn chartWrapper">
<h5>Most Frequently Disclosed Lobbying Issues</h5>
<ul>
{% for issue in issues_lobbied_for %}
{% for issue in section.issues_lobbied_for %}
<li>{{issue}}{% if forloop.last %}{% else %},{% endif %}</li>
{% endfor %}
</ul>
Expand All @@ -44,10 +44,10 @@ <h5>Most Frequently Disclosed Lobbying Issues</h5>

{% endif %} <!-- end if lobbying with firm -->

{% if lobbying_for_clients %}
{% if section.lobbying_for_clients %}
<div class="twoColumn chartWrapper">
<h5>Clients of Firms {{ entity_info.name|standardize_individual_name }} Worked For</h5>
{% for row in lobbying_for_clients %}
{% for row in section.lobbying_for_clients %}
{% if row.client_entity %}
<a href="/organization/{{ row.client_name|slugify }}/{{ row.client_entity }}{{cycle|pretty_cycle}}">{{ row.client_name }}</a>{% if forloop.last %}{% else %},{% endif %}
{% else %}
Expand All @@ -59,9 +59,9 @@ <h5>Clients of Firms {{ entity_info.name|standardize_individual_name }} Worked F
<div class="clear"></div>

<div class="external">
{% if lobbying_links %}
{% if section.lobbying_links %}
For more information on lobbying:
{% for link in lobbying_links %}
{% for link in section.lobbying_links %}
<a href="{{ link.url }}" class="external" target="_blank">{{ link.text }}</a>
{% endfor %}
{% endif %}
Expand Down
33 changes: 6 additions & 27 deletions templates/individual.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
{{ entity_info.name|standardize_individual_name }} |
{% endblock %}

{% block pagetopics %}: {% spaceless %}
{% filter nonempty_lines|pretty_list %}
{% if contributions_data %}Campaign Contributions{% endif %}
{% if lobbying_data %}Lobbying{% endif %}
{% endfilter %}
{% endspaceless %}{% endblock %}

{% block canonicalurl %}/individual/{{ entity_info.name|standardize_individual_name|slugify }}/{{ entity_info.id }}{{cycle|pretty_cycle}}{% endblock %}

{% block metadesc %}{{ entity_info.name|standardize_individual_name }} has given ${{entity_info.totals.contributor_amount|floatformat:0|intcomma }} in campaign contributions from {% ifequal cycle "-1" %}{{entity_info.camp_fin_years.start|add:-1}} to {{entity_info.camp_fin_years.end}}{% else %}{{cycle|add:-1}} to {{cycle}}{% endifequal %}. See where the money went on Influence Explorer.{% endblock %}
Expand All @@ -32,11 +25,11 @@
{% block extrajs %}
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
sparkline("sparklines", {% if sparkline_data %}{{ sparkline_data|safe }}{% else %}[]{% endif %});
sparkline("sparklines", {% if sections.contributions.sparkline_data %}{{ sections.contributions.sparkline_data|safe }}{% else %}[]{% endif %});
{% if not suppress_contrib_graphs %}
piechart("piechart_party", {% if party_breakdown %}{{ party_breakdown|safe }}{% else %}{}{% endif %}, type="party");
barchart("recipients_barchart", {% if candidates_barchart_data %}{{ candidates_barchart_data|safe }}{% else %} [] {% endif %});
barchart("orgs_barchart", {% if orgs_barchart_data %}{{ orgs_barchart_data|safe }}{% else %} [] {% endif %});
piechart("piechart_party", {% if sections.contributions.party_breakdown %}{{ sections.contributions.party_breakdown|safe }}{% else %}{}{% endif %}, type="party");
barchart("recipients_barchart", {% if sections.contributions.candidates_barchart_data %}{{ sections.contributions.candidates_barchart_data|safe }}{% else %} [] {% endif %});
barchart("orgs_barchart", {% if sections.contributions.orgs_barchart_data %}{{ sections.contributions.orgs_barchart_data|safe }}{% else %} [] {% endif %});
{% endif %}
});

Expand All @@ -55,8 +48,8 @@ <h2 class="individualName">{{ entity_info.name|standardize_individual_name }}</h
<div class="descriptorText" id="individualDescriptor">
<p>We rely on our partner organizations, the <a href="http://www.opensecrets.org/">Center for Responsive Politics</a> and the <a href="http://www.followthemoney.org/">National Institute on Money in State Politics</a>, to uniquely identify individuals' campaign finance and lobbying activity. If data appears to be missing, it may be that they have not identified all influence activity for this individual. If the data is completely different than you expected, it may be that you're looking at a different person with the same name.</p>
<p>In these cases, we suggest using our companion site, <a href="http://transparencydata.com">TransparencyData.com</a>, to search the underlying databases. TransparencyData provides extra information about each contribution, such as the donor's city, state and employer. This information should allow you to judge for yourself if the contribution came from the person for whom you searched.</p>
{% if external_links %}
{% for link in external_links %}
{% if sections.contributions.external_links %}
{% for link in sections.contributions.external_links %}
{% if link.text == "TransparencyData.com" %}
<p><a href="{{ link.url }}" class="external" target="_blank">Click here for campaign contributions with the name "{{ entity_info.name|standardize_individual_name }}".</a></p>
{% endif %}
Expand Down Expand Up @@ -88,17 +81,3 @@ <h2 class="individualName">{{ entity_info.name|standardize_individual_name }}</h
{% endif %}

{% endblock %}

{% block contributions %}
{% if contributions_data %}
{{ block.super }}
{% include "contributions.html" %}
{% endif %}
{% endblock %}

{% block lobbying %}
{% if lobbying_data %}
{{ block.super }}
{% include "indiv_lobbying.html" %}
{% endif %}
{% endblock %}
34 changes: 6 additions & 28 deletions templates/industry.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
{{ entity_info.name|standardize_industry_name}} |
{% endblock %}

{% block pagetopics %}: {% spaceless %}
{% filter nonempty_lines|pretty_list %}
{% if contributions_data %}Campaign Contributions{% endif %}
{% if lobbying_data %}Lobbying{% endif %}
{% endfilter %}
{% endspaceless %}{% endblock %}

{% block canonicalurl %}/industry/{{ entity_info.name|standardize_industry_name|slugify }}/{{ entity_info.id }}{{cycle|pretty_cycle}}{% endblock %}

{% block metadesc %}{{ entity_info.name|standardize_industry_name }} has given ${{entity_info.totals.contributor_amount|floatformat:0|intcomma }} in campaign contributions from {% ifequal cycle "-1" %}{{entity_info.camp_fin_years.start|add:-1}} to {{entity_info.camp_fin_years.end}}{% else %}{{cycle|add:-1}} to {{cycle}}{% endifequal %}. See where the money went on Influence Explorer.{% endblock %}
Expand All @@ -31,12 +24,12 @@
{% block extrajs %}
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
sparkline_by_party("sparklines", {% if sparkline_data %}{{ sparkline_data|safe }}, {{ cut_off_sparkline_at_step }} {% else %}[], 0{% endif %});
{% if not suppress_contrib_graphs %}
piechart("piechart_level", {% if level_breakdown %}{{ level_breakdown|safe }}{% else %}{}{% endif %});
piechart("piechart_party", {% if party_breakdown %}{{ party_breakdown|safe }}{% else %}{}{% endif %}, type="party" );
barchart("recipients_barchart", {% if recipients_barchart_data %}{{ recipients_barchart_data|safe }} {% else %} [] {% endif %});
barchart("organizations_barchart", {% if top_orgs %}{{ top_orgs|safe }} {% else %} [] {% endif %});
sparkline_by_party("sparklines", {% if sections.contributions.sparkline_data %}{{ sections.contributions.sparkline_data|safe }}, {{ sections.contributions.cut_off_sparkline_at_step }} {% else %}[], 0{% endif %});
{% if not sections.contributions.suppress_contrib_graphs %}
piechart("piechart_level", {% if sections.contributions.level_breakdown %}{{ sections.contributions.level_breakdown|safe }}{% else %}{}{% endif %});
piechart("piechart_party", {% if sections.contributions.party_breakdown %}{{ sections.contributions.party_breakdown|safe }}{% else %}{}{% endif %}, type="party" );
barchart("recipients_barchart", {% if sections.contributions.recipients_barchart_data %}{{ sections.contributions.recipients_barchart_data|safe }} {% else %} [] {% endif %});
barchart("organizations_barchart", {% if sections.contributions.top_orgs %}{{ sections.contributions.top_orgs|safe }} {% else %} [] {% endif %});
{% endif %}
});
</script>
Expand Down Expand Up @@ -72,18 +65,3 @@ <h2>{{ entity_info.name|standardize_industry_name }}</h2>
{% endif %}
{% endblock %}
{% endif %}


{% block contributions %}
{% if contributions_data %}
{{ block.super }}
{% include "contributions.html" %}
{% endif %}
{% endblock %}

{% block lobbying %}
{% if lobbying_data %}
{{ block.super }}
{% include "industry_lobbying.html" %}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="twoColumn chartWrapper">
<div class="chart">
{% if recipients_barchart_data %}
{% if section.recipients_barchart_data %}
<h4 class="key withTip">Top Organizations</h4>
<dl class="key">
<dt class="employees">Employee Color Block</dt>
Expand Down Expand Up @@ -30,7 +30,7 @@ <h4 class="withTip">Republicans vs. Democrats</h4>

<div class="twoColumn chartWrapper">
<div class="chart">
{% if recipients_barchart_data %}
{% if section.recipients_barchart_data %}
<h4 class="key withTip">Top Recipients</h4>
<dl class="key">
<dt class="employees">Employee Color Block</dt>
Expand Down
Loading

0 comments on commit 3d548fe

Please sign in to comment.