Skip to content

Commit

Permalink
fix links
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Apr 24, 2024
1 parent 6c31508 commit 9c4771f
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 216 deletions.
12 changes: 11 additions & 1 deletion camp_fin/management/commands/import_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def handle(self, *args, **options):
else:
county = None

_, created = models.Campaign.objects.get_or_create(
campaign, created = models.Campaign.objects.get_or_create(
election_season=election_season,
candidate=candidate,
office=office,
Expand All @@ -101,6 +101,16 @@ def handle(self, *args, **options):
political_party=political_party,
)

campaign.sos_link = "https://login.cfis.sos.state.nm.us/#/exploreDetails/{id}/{office_id}/{district_id}/{election_id}/{election_year}".format( # noqa
id=record["IDNumber"],
office_id=record["OfficeId"] or "null",
district_id=record["DistrictId"] or "null",
election_id=int(float(record["ElectionId"])) or "null",
election_year=record["ElectionYear"] or "null",
)

campaign.save()

self.stderr.write(
f"Linked {candidates_linked} candidates with a campaign, "
f"created {candidates_created} candidates"
Expand Down
11 changes: 8 additions & 3 deletions camp_fin/management/commands/import_pac_committees.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def handle(self, *args, **options):
if state_id:

try:
models.PAC.objects.get(entity__user_id=record["StateID"])
pac = models.PAC.objects.get(entity__user_id=record["StateID"])
pacs_linked += 1

except models.PAC.DoesNotExist:
Expand All @@ -51,7 +51,7 @@ def handle(self, *args, **options):
user_id=record["StateID"],
)

models.PAC.objects.create(
pac = models.PAC.objects.create(
name=record["CommitteeName"],
slug=f'{slugify(record["CommitteeName"])}-{get_random_string(5)}',
entity=entity,
Expand All @@ -72,14 +72,19 @@ def handle(self, *args, **options):
entity_type=entity_type,
)

models.PAC.objects.create(
pac = models.PAC.objects.create(
name=record["CommitteeName"],
slug=f'{slugify(record["CommitteeName"])}-{get_random_string(5)}',
entity=entity,
)

pacs_created += 1

pac.sos_link = "https://login.cfis.sos.state.nm.us/#/exploreCommitteeDetail/{id}".format(
id=record["IdNumber"]
)
pac.save()

self.stderr.write(
f"found {pacs_linked} pacs, "
f"created {pacs_created} pacs, "
Expand Down
27 changes: 27 additions & 0 deletions camp_fin/migrations/0085_auto_20240424_1218.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2024-04-24 18:18
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("camp_fin", "0084_auto_20240418_1048"),
]

operations = [
migrations.AddField(
model_name="candidate",
name="sos_link",
field=models.URLField(default="https://google.com"),
preserve_default=False,
),
migrations.AddField(
model_name="pac",
name="sos_link",
field=models.URLField(default="https://google.com"),
preserve_default=False,
),
]
25 changes: 25 additions & 0 deletions camp_fin/migrations/0086_auto_20240424_1303.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2024-04-24 19:03
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("camp_fin", "0085_auto_20240424_1218"),
]

operations = [
migrations.RemoveField(
model_name="candidate",
name="sos_link",
),
migrations.AddField(
model_name="campaign",
name="sos_link",
field=models.URLField(default="https://google.com"),
preserve_default=False,
),
]
2 changes: 2 additions & 0 deletions camp_fin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __str__(self):

class PAC(models.Model):
entity = models.ForeignKey("Entity", db_constraint=False)
sos_link = models.URLField()
name = models.CharField(max_length=100)
acronym = models.CharField(max_length=15, null=True)
business_phone = models.CharField(max_length=20, null=True)
Expand Down Expand Up @@ -119,6 +120,7 @@ class Campaign(models.Model):
race_status = models.CharField(
max_length=25, default="active", choices=status_choices, blank=True, null=True
)
sos_link = models.URLField()

def __str__(self):
office = self.office.description
Expand Down
218 changes: 109 additions & 109 deletions camp_fin/templates/camp_fin/candidate-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,127 +4,127 @@
{% block title %}{{ candidate.full_name }}{% endblock %}

{% block header %}
<div class="row">
<div class="col-xs-12">
<p class="breadcrumbs"><a href='/candidates'>&laquo; Candidates</a></p>
</div>
<div class="row">
<div class="col-xs-12">
<p class="breadcrumbs"><a href='/candidates'>&laquo; Candidates</a></p>
</div>
<div class="row">
<div class="col-xs-12">
<h1>
<i class="fa fa-fw fa-user"></i>
{{ candidate }}
<small>Candidate</small>
</h1>
{% if sos_link %}
<p><a href="{{sos_link}}" target="_blank">View on the New Mexico Secretary of State's website &raquo;</a></p>
{% endif %}
{% if stories %}
<h3>Related stories</h3>
<ul>
{% for story in stories %}
<li><a href="{{ story.link }}">{{ story.title }}</a></li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h1>
<i class="fa fa-fw fa-user"></i>
{{ candidate }}
<small>Candidate</small>
</h1>
{% if latest_campaign.sos_link %}
<p><a href="{{latest_campaign.sos_link}}" target="_blank">View on the New Mexico Secretary of State's website &raquo;</a></p>
{% endif %}
{% if stories %}
<h3>Related stories</h3>
<ul>
{% for story in stories %}
<li><a href="{{ story.link }}">{{ story.title }}</a></li>
{% endfor %}
</ul>
{% endif %}
</div>
<div class="row">
<div class="col-xs-12">
<a href="{% url 'bulk-contributions-list' %}?candidate_id={{ candidate.id }}" class="btn btn-default"
id="contributions-download">
<i class="fa fa-fw fa-download"></i>
Download contributions
</a>
<a href="{% url 'bulk-expenditures-list' %}?candidate_id={{ candidate.id }}" class="btn btn-default"
id="expenditures-download">
<i class="fa fa-fw fa-download"></i>
Download expenditures
</a>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<a href="{% url 'bulk-contributions-list' %}?candidate_id={{ candidate.id }}" class="btn btn-default"
id="contributions-download">
<i class="fa fa-fw fa-download"></i>
Download contributions
</a>
<a href="{% url 'bulk-expenditures-list' %}?candidate_id={{ candidate.id }}" class="btn btn-default"
id="expenditures-download">
<i class="fa fa-fw fa-download"></i>
Download expenditures
</a>
</div>
</div>
{% endblock %}

{% block charts %}
<h3><i class="fa fa-fw fa-area-chart"></i> Net funds over time</h3>
<div id='net-funds-chart'></div>
<h3><i class="fa fa-fw fa-area-chart"></i> Net funds over time</h3>
<div id='net-funds-chart'></div>

<h3><i class="fa fa-fw fa-bar-chart"></i> Donations and expenditures over time</h3>
<div id='expend-chart'></div>
<h3><i class="fa fa-fw fa-bar-chart"></i> Donations and expenditures over time</h3>
<div id='expend-chart'></div>

{% endblock %}

{% block campaigns %}
{% if campaigns %}
<h3><i class="fa fa-fw fa-history"></i> Past campaigns</h3>
<table class="table table-striped">
<thead>
<tr>
<th>Office (Party)</th>
<th>Committee</th>
<th>Election year</th>
</tr>
</thead>
<tbody>
{% for campaign in campaigns %}
<tr>
<td>
{{ campaign.office.description }}
{% if campaign.party_identifier %}
<span class="party-identifier {{ campaign.party_identifier }}">
({{ campaign.party_identifier }})
</span>
{% endif %}
</td>
<td>
{% if campaign.committee_name %}
<a href="{% url 'search' %}?term={{ campaign.committee_name|urlencode }}">
{{ campaign.committee_name }}
</a>
{% endif %}
</td>
<td>{{ campaign.election_season.year }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if campaigns %}
<h3><i class="fa fa-fw fa-history"></i> Past campaigns</h3>
<table class="table table-striped">
<thead>
<tr>
<th>Office (Party)</th>
<th>Committee</th>
<th>Election year</th>
</tr>
</thead>
<tbody>
{% for campaign in campaigns %}
<tr>
<td>
{{ campaign.office.description }}
{% if campaign.party_identifier %}
<span class="party-identifier {{ campaign.party_identifier }}">
({{ campaign.party_identifier }})
</span>
{% endif %}
</td>
<td>
{% if campaign.committee_name %}
<a href="{% url 'search' %}?term={{ campaign.committee_name|urlencode }}">
{{ campaign.committee_name }}
</a>
{% endif %}
</td>
<td>{{ campaign.election_season.year }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock %}

{% block js_templates %}
<script type="text/EJS" id="top-money-table-guts">
<table class="table table-striped">
<thead>
<tr>
<% if(transaction_type == 'top-donors'){ %>
<th>Donor</th>
<th>Total donated</th>
<% } else { %>
<th>Recipient</th>
<th>Total received</th>
<% } %>
<th>Election year</th>
</tr>
</thead>
<tbody>
<% $.each(transactions, function(i, transaction){ %>
<tr>
<td>
<% if (transaction.redact) { %>
<%= transaction.display_name %>
<% } else { %>
<a href='/search/?term=<%= encodeURIComponent(transaction.display_name.replace("\'", "")) %>'>
<%= transaction.display_name %>
</a>
<% } %>
</td>
<td class='nowrap'>
<%= accounting.formatMoney(transaction.amount) %>
</td>
<td><%= transaction.year %></td>
</tr>
<% }) %>
</tbody>
</table>
</script>
<script type="text/EJS" id="top-money-table-guts">
<table class="table table-striped">
<thead>
<tr>
<% if(transaction_type == 'top-donors'){ %>
<th>Donor</th>
<th>Total donated</th>
<% } else { %>
<th>Recipient</th>
<th>Total received</th>
<% } %>
<th>Election year</th>
</tr>
</thead>
<tbody>
<% $.each(transactions, function(i, transaction){ %>
<tr>
<td>
<% if (transaction.redact) { %>
<%= transaction.display_name %>
<% } else { %>
<a href='/search/?term=<%= encodeURIComponent(transaction.display_name.replace("\'", "")) %>'>
<%= transaction.display_name %>
</a>
<% } %>
</td>
<td class='nowrap'>
<%= accounting.formatMoney(transaction.amount) %>
</td>
<td><%= transaction.year %></td>
</tr>
<% }) %>
</tbody>
</table>
</script>
{% endblock %}
Loading

0 comments on commit 9c4771f

Please sign in to comment.