Skip to content

Commit

Permalink
Merge pull request #167 from datamade/jfc/spring-2020-update
Browse files Browse the repository at this point in the history
Update data for spring 2020 and disable races views
  • Loading branch information
jeancochrane authored May 8, 2020
2 parents 465bcfc + 9b6e30f commit 3f85ea1
Show file tree
Hide file tree
Showing 27 changed files with 148 additions and 393 deletions.
32 changes: 16 additions & 16 deletions camp_fin/management/commands/import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@
}

FILE_LOOKUP = {
'campaign': 'Cam_Campaign.xlsx',
'campaign': 'Cam_Campaign.csv',
'transaction': 'Cam_ContribExpenditure.zip',
'transactiontype': 'Cam_ContribExpenditureType.xlsx',
'office': 'Cam_ElectionOffice.xlsx',
'filingperiod': 'Cam_FilingPeriod.xlsx',
'filingperiod': 'Cam_FilingPeriod.csv',
'officetype': 'Cam_OfficeType.xlsx',
'filing': 'Cam_Report.xlsx',
'candidate': 'Cam_Candidate.xlsx',
'pac': 'Cam_PoliticalActionCommittee.xlsx',
'filing': 'Cam_Report.csv',
'candidate': 'Cam_Candidate.csv',
'pac': 'Cam_PoliticalActionCommittee.csv',
'campaignstatus': 'Cam_CampaignStatus.xlsx',
'county': 'Cam_County.xlsx',
'district': 'Cam_District.xlsx',
Expand All @@ -83,8 +83,8 @@
'entity': 'Cam_Entity.xlsx',
'entitytype': 'Cam_EntityType.xlsx',
'filingtype': 'Cam_FilingPeriodType.xlsx',
'loan': 'Cam_Loan.xlsx',
'loantransaction': 'Cam_LoanTransaction.xlsx',
'loan': 'Cam_Loan.csv',
'loantransaction': 'Cam_LoanTransaction.csv',
'loantransactiontype': 'Cam_LoanTransactionType.xlsx',
'politicalparty': 'Cam_PoliticalParty.xlsx',
'specialevent': 'Cam_SpecialEvent.xlsx',
Expand All @@ -93,17 +93,17 @@
'contacttype': 'Cam_ContactType.xlsx',
'contact': 'Cam_Contact.csv',
'state': 'States.csv',
'lobbyist': 'Cam_Lobbyist.xlsx',
'lobbyist': 'Cam_Lobbyist.csv',
'lobbyistregistration': 'Cam_LobbystRegistration.xlsx',
'lobbyistemployer': 'Cam_LobbyistEmployer.xlsx',
'lobbyistemployer': 'Cam_LobbyistEmployer.csv',
'organization': 'Cam_Organization.xlsx',
'lobbyistfilingperiod': 'Cam_FilingPeriodLobbyist.xlsx',
'lobbyisttransaction': 'Cam_ContribExpenditureLobbyist.xlsx',
'lobbyisttransactiontype': 'Cam_ContribExpenditureLobbyistType.xlsx',
'lobbyistbundlingdisclosure': 'Cam_BundlingDisclosureLobbyist.xlsx',
'lobbyistbundlingdisclosurecontributor': 'Cam_BundlingDisclosureLobbyistContributor.xlsx',
'lobbyistreport': 'Cam_ReportLobbyist.xlsx',
'lobbyistspecialevent': 'Cam_SpecialEventLobbyist.xlsx',
'lobbyistfilingperiod': 'Cam_FilingPeriodLobbyist.csv',
'lobbyisttransaction': 'Cam_ContribExpenditureLobbyist.csv',
'lobbyisttransactiontype': 'Cam_ContribExpenditureLobbyistType.csv',
'lobbyistbundlingdisclosure': 'Cam_BundlingDisclosureLobbyist.csv',
'lobbyistbundlingdisclosurecontributor': 'Cam_BundlingDisclosureLobbyistContributor.csv',
'lobbyistreport': 'Cam_ReportLobbyist.csv',
'lobbyistspecialevent': 'Cam_SpecialEventLobbyist.csv',
}

class Command(BaseCommand):
Expand Down
4 changes: 2 additions & 2 deletions camp_fin/management/commands/table_mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
LOAN = OrderedDict([
("loanid",{'field': 'id', 'data_type': 'bigint'}),
("contactid",{'field': 'contact_id', 'data_type': 'bigint'}),
("amount",{'field': 'amount', 'data_type': 'double precision'}),
("amount",{'field': 'amount', 'data_type': 'money::numeric::double precision'}),
("datereceived",{'field': 'received_date', 'data_type': 'timestamp with time zone'}),
("dateadded",{'field': 'date_added', 'data_type': 'timestamp with time zone'}),
("checknumber",{'field': 'check_number', 'data_type': 'varchar'}),
Expand Down Expand Up @@ -266,7 +266,7 @@
LOAN_TRANSACTION = OrderedDict([
("loantransactionid", {'field': 'id', 'data_type': 'bigint'}),
("loanid", {'field': 'loan_id', 'data_type': 'bigint'}),
("amount", {'field': 'amount', 'data_type': 'double precision'}),
("amount", {'field': 'amount', 'data_type': 'money::numeric::double precision'}),
("interestpaid", {'field': 'interest_paid', 'data_type': 'double precision'}),
("date", {'field': 'transaction_date', 'data_type': 'timestamp with time zone'}),
("dateadded", {'field': 'date_added', 'data_type': 'timestamp with time zone'}),
Expand Down
3 changes: 0 additions & 3 deletions camp_fin/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
<li>
<a href="{% url 'search' %}"><i class='fa fa-search'></i> Search</a>
</li>
<li>
<a href="{% url 'races' %}"><i class='fa fa-check-square-o'></i> Races</a>
</li>
<li>
<a href="{% url 'donations' %}"><i class='fa fa-dollar'></i> Donations</a>
</li>
Expand Down
107 changes: 0 additions & 107 deletions camp_fin/templates/camp_fin/candidate-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,113 +55,6 @@ <h3><i class="fa fa-fw fa-bar-chart"></i> Donations and expenditures over time</
{% endblock %}

{% block campaigns %}
{% if latest_race %}
<h3><i class="fa fa-fw fa-check-square-o"></i>Latest race</h3>
<p style="font-family:'Helvetica Neue',Helvetica,Arial,sans-serif">
{% if latest_race.funding_period == '2017' %}
<a href="{% url 'race-detail' latest_race.id %}">
{{ latest_race }} &raquo;
</a>
{% else %}
{{ latest_race }}
{% endif %}
</p>
<div class="row">
<div class="col-xs-12">
<table class="table">
<thead>
<th>Candidate</th>
<th class="visible-xs">Cash on hand</th>
<th>Funds raised</th>
<tbody>
<td class="no-wrap col-sm-4">
<!-- Start with this candidate -->
<p>
<strong>{{ candidate.full_name }}</strong>
</a>
{% if latest_campaign.party_identifier %}
<small>
<span class="party-identifier {{ latest_campaign.party_identifier }}">
({{ latest_campaign.party_identifier }})
</span>
</small>
{% endif %}
{% if campaign.is_winner %}
<i class="fa fa-fw fa-check-circle green"></i>
{% endif %}
</p>
<!-- Display the rest of the candidates -->
{% for campaign in latest_race.sorted_campaigns %}
{% if campaign.candidate != candidate %}
<p>
<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 %}
</p>
{% endif %}
{% endfor %}
</td>
<td class="visible-xs">
<!-- Start with this candidate -->
<p>
{{ latest_campaign.cash_on_hand | format_money_short }}
</p>
<!-- Other candidates -->
{% for campaign in latest_race.sorted_campaigns %}
{% if campaign.candidate != candidate %}
<p>
{{ campaign.cash_on_hand | format_money_short }}
</p>
{% endif %}
{% endfor %}
</td>
<td class="no-wrap col-sm-8">
<!-- Large sizes: show bar charts -->
<div class="hidden-xs">
<!-- Start with this candidate -->
{% with campaign=latest_campaign last_year=latest_race.funding_period total=latest_race.largest_contribution %}
{% include 'camp_fin/widgets/funding-distribution.html' %}
{% endwith %}
<!-- Display the rest of the candidates -->
{% for campaign in latest_race.sorted_campaigns %}
{% if campaign.candidate != candidate %}
{% with total=latest_race.largest_contribution last_year=latest_race.funding_period %}
{% include 'camp_fin/widgets/funding-distribution.html' %}
{% endwith %}
{% endif %}
{% endfor %}
</div>
<!-- Small sizes: show text cash amounts -->
<div class="visible-xs">
<!--This candidate -->
<p>
{% funds_raised latest_campaign latest_race.funding_period short=True %}
</p>
<!-- The rest of the candidates -->
{% for campaign in latest_race.sorted_campaigns %}
<p>
{% if campaign.candidate != candidate %}
{% funds_raised campaign latest_race.funding_period short=True %}
{% endif %}
</p>
{% endfor %}
</div>
</td>
</tbody>
</table>
</div>
</div>
{% endif %}
{% if campaigns %}
<h3><i class="fa fa-fw fa-history"></i> Past campaigns</h3>
<table class="table table-striped">
Expand Down
82 changes: 4 additions & 78 deletions camp_fin/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,82 +59,6 @@ <h1>Keep an eye on money in New Mexico politics</h1>
{{ page.text|safe }}
</div>
</div>
<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>
</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>
</p>
<br /><br />
</div>
</div>

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

Expand Down Expand Up @@ -198,8 +122,10 @@ <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='/about/'><i class='fa fa-fw fa-info-circle'></i> About</a></h2>
{{ home_page_about|safe }}
{% if home_page_about %}
<h2><a href='/about/'><i class='fa fa-fw fa-info-circle'></i> About</a></h2>
{{ home_page_about|safe }}
{% endif %}
</div>
</div>
{% endblock %}
29 changes: 0 additions & 29 deletions camp_fin/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,3 @@ def test_campaign_share_of_funds(self):
self.assertEqual(self.first_campaign.share_of_funds(total=total), 70)
self.assertEqual(self.second_campaign.share_of_funds(total=total), 30)
self.assertEqual(self.third_campaign.share_of_funds(total=total), 0)


class TestRaceView(DatabaseTestCase):
'''
Test views of the Race class that require database access.
'''
def test_race_view_html(self):
year = str(self.filing_period.due_date.year)
response = self.client.get(reverse('races') + '?year=%s' % year
+ '&type=%d' % self.office_type.id)

html = response.content.decode('utf-8')

self.assertIn('<title>Contested %s races in New Mexico' % year, html)
self.assertTemplateUsed(response, 'camp_fin/races.html')

# Check that a table is loaded
table_list = html.split('<tr')
self.assertTrue(len(table_list) > 2)

def test_race_detail_view_html(self):
detail_url = reverse('race-detail', args=[self.race.id])
response = self.client.get(detail_url)
self.assertEqual(response.status_code, 200)

html = response.content.decode('utf-8')

self.assertIn('<title>{year} Race for test office'.format(year=self.year), html)
self.assertTemplateUsed(response, 'camp_fin/race-detail.html')
32 changes: 0 additions & 32 deletions camp_fin/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,38 +112,6 @@ def test_campaign_party_identifier(self):
self.assertEqual(self.non_race_campaign.party_identifier, 'I')


class TestRaceView(StatelessTestCase):
'''
Test view to display contested races.
'''
@classmethod
def setUpTestData(cls):
super().setUpTestData()

# We don't actually need data here; we just need the table
call_command('import_data', '--add-aggregates', '--verbosity=0')

def test_race_view_resolves(self):
found = resolve(reverse('races'))
self.assertEqual(found.func.view_class, RacesView)

def test_race_detail_view_resolves(self):
found = resolve(reverse('race-detail', args=[self.race.id]))
self.assertEqual(found.func.view_class, RaceDetail)

def test_race_detail_view_404(self):
pk = 0
while pk == self.race.id:
pk += 1
if pk == 100:
self.fail() # Something's gone very wrong

bogus_url = reverse('race-detail', args=[pk])
response = self.client.get(bogus_url)

self.assertEqual(response.status_code, 404)


class TestAdmin(StatelessTestCase):
'''
Test some functionality of the Admin console.
Expand Down
3 changes: 0 additions & 3 deletions camp_fin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,6 @@ def get_context_data(self, **kwargs):

context['latest_campaign'] = latest_campaign

if latest_campaign:
context['latest_race'] = latest_campaign.active_race

context['campaigns'] = context['object'].campaign_set.all()

context['stories'] = self.object.story_set.all()
Expand Down
Binary file removed data/Cam_BundlingDisclosureLobbyist.xlsx
Binary file not shown.
Binary file removed data/Cam_BundlingDisclosureLobbyistContributor.xlsx
Binary file not shown.
Binary file removed data/Cam_Campaign.xlsx
Binary file not shown.
Binary file removed data/Cam_Candidate.xlsx
Binary file not shown.
Binary file modified data/Cam_ContribExpenditure.zip
Binary file not shown.
Binary file removed data/Cam_ContribExpenditureLobbyist.xlsx
Binary file not shown.
Binary file removed data/Cam_ContribExpenditureLobbyistType.xlsx
Binary file not shown.
Loading

0 comments on commit 3f85ea1

Please sign in to comment.