Skip to content

Commit

Permalink
Merge pull request #2322 from DemocracyClub/link-to-data-exporter
Browse files Browse the repository at this point in the history
Link to data exporter
  • Loading branch information
symroe authored May 25, 2024
2 parents 8be343b + cf14599 commit 3d799db
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 191 deletions.
12 changes: 6 additions & 6 deletions deploy/webapp_settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
}
]


# **** Other settings that might be useful to change locally

INTERNAL_IPS = [
Expand All @@ -55,19 +54,18 @@
},
}


# **** Settings that might be useful in production
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
RAVEN_CONFIG = {"dsn": os.environ.get("RAVEN_DSN")}

RUNNING_TESTS = False


# This should be one of:
# ELECTION_STATS
# SOPN_TRACKER
# RESULTS_PROGRESS
# DATA_DOWNLOAD
# BY_ELECTIONS
FRONT_PAGE_CTA = "None"
SOPN_TRACKER_INFO = {
Expand All @@ -81,10 +79,14 @@
# ("Northern Ireland", date(year=2023, month=4, day=24)),
]

DATA_DOWNLOAD_INFO = {
"election_date": "2024-07-04",
"election_name": "2024 general election",
"election_regex": "parl.2024-07-04",
}

SCHEDULED_ELECTION_DATES = ["2024-05-02", "2024-05-18"]


STATICFILES_STORAGE = "ynr.storages.StaticStorage"
DEFAULT_FILE_STORAGE = "ynr.storages.MediaStorage"
AWS_STORAGE_BUCKET_NAME = "static-candidates.democracyclub.org.uk"
Expand All @@ -95,7 +97,6 @@
AWS_BUCKET_ACL = AWS_DEFAULT_ACL
AWS_QUERYSTRING_AUTH = False


CSRF_TRUSTED_ORIGINS = [
f"https://{os.environ.get('FQDN')}",
]
Expand All @@ -109,7 +110,6 @@
EMAIL_HOST_USER = os.environ.get("SMTP_USERNAME")
EMAIL_HOST_PASSWORD = os.environ.get("SMTP_PASSWORD")


SLACK_TOKEN = os.environ.get("SLACK_TOKEN")

CELERY_IMPORTS = [
Expand Down
7 changes: 3 additions & 4 deletions ynr/apps/api/templates/api/api-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ <h1>Candidates and results data</h1>
<li><a href="{% url "api-home" %}">Data Overview</a></li>
<li><a href="{% url "api-terms" %}">Terms</a></li>
<li class="divider"></li>
<li class="heading"><a href="{% url "api_docs_csv" %}">CSV / Excel downloads</a></li>
<li class="heading"><a href="{% url "api_docs_results" %}">Results</a></li>
<li><a href="{% url "api_docs_results" %}#elected_csv">Elected CSV</a></li>
<li><a href="{% url "api_docs_results" %}#atom">ATOM feed</a></li>
<li class="heading"><a href="{% url "data_home" %}">CSV / Excel downloads</a></li>

<li class="divider"></li>
<li class="heading">
<a href="{% url "api_docs_next_home" %}">
Expand All @@ -26,6 +24,7 @@ <h1>Candidates and results data</h1>
<li><a href="{% url "api_docs_next_definitions" %}">Definitions</a></li>
<li class="divider"></li>
<li class="heading"><a href="{% url "api-root" version="v0.9" %}">v0.9 API</a></li>
<li><a href="{% url "api_docs_atom" %}">Results ATOM feed</a></li>
</ul>
</div>
<div class="columns large-10">
Expand Down
2 changes: 1 addition & 1 deletion ynr/apps/api/templates/api/api-home.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

### Formats

We have data in [CSV format]({% url "api_docs_csv" %}) or a REST API.
We have data in [CSV format]({% url "data_home" %}) or a REST API.

There are currently two API versions, [v0.9]({% url "api-root" version="v0.9" %})
and [next]({% url "api_docs_next_home" %}).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,104 +1,9 @@
{% extends "api/api-base.html" %}
{% block api_page_title %}
<h1>Results data</h1>
<h1>Results Atom feed</h1>
{% endblock %}
{% block api_content %}
<h2>Types of results</h2>
<p><strong>At the moment, we only support results for elections that use First Past The Post.</strong></p>

<p>We store two different types of results: <strong>elected</strong> and <strong>votes cast</strong>.</p>

<p><strong>Elected</strong> results involve just setting a flag on the <em>candidacy</em>
that the person was elected. This is the simplest form of result, and is often the quickest and easiest
information to collect.</p>

<p><strong>Votes cast</strong> results are the numbers of votes cast per person. For first past the post
elections, the winners are set based on the number of winners for that ballot.</p>

<h2 id="winners_csv">2019 General election 'elected' CSV</h2>
<p>For the 2019 General election we are publishing a CSV of winners, overnight.</p>
<p>The CSV will contain a header row, and then one row per ballot containing information
about the winner. No <em>votes cast</em> data will be in the CSV</p>

<a href="{% url "parl-2019-csv-results" %}" class="button">Download the CSV</a>

<p>The headings of th CSV are:</p>
<table class="table api_defs">
<thead>
<tr>
<th>Column Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>

<tr>
<td><code>election_slug</code></td>
<td><code>parl.2019-12-12</code>. Here for future proofing the format.</td>
</tr>
<tr>
<td><code>ballot_paper_id</code></td>
<td>The Democracy Club ballot paper ID. See the
<a href="https://elections.democracyclub.org.uk/reference_definition/">reference definition</a>
for detailed information. Used to format URLs on most of our sites, and in the REST API</td>
</tr>
<tr>
<td><code>gss</code></td>
<td>The GSS code for the ballot</td>
</tr>
<tr>
<td><code>person_id</code></td>
<td>The numerical ID assigned to a person by this site.</td>
</tr>
<tr>
<td><code>person_name</code></td>
<td>The person's name</td>
</tr>
<tr>
<td><code>party_id</code></td>
<td>The Party ID of the elected person.
See the <a href="/api/docs/next/definitions/#Party"><code>Party</code></a>
documentation for more.
Look out for edge cases here, for example <code>joint-party:53-119</code>
is the ID for 'Labour and Co-operative Party', <code>ynmp-party:2</code> 'Independent' and
<code>joint-party:53-119</code> 'Speaker seeking re-election'. All other values should match
The Electoral Commission IDs</td>
</tr>
<tr>
<td><code>party_name</code></td>
<td>The party name</td>
</tr>
<tr>
<td><code>theyworkforyou_url</code></td>
<td>If the person has ever been elected as an MP, they will have a TheyWorkForYou
URL here. Note that this doesn't mean they are an "incumbent", as they might not have
been in MP in the last parliament.</td>
</tr>
<tr>
<td><code>wikidata_id</code></td>
<td>The person's Wikidata ID</td>
</tr>
<tr>
<td><code>updated</code></td>
<td>The time the winner was recorded</td>
</tr>
<tr>
<td><code>previous_winner</code></td>
<td>The person ID of the person who was elected in the previous ballot for this area</td>
</tr>
<tr>
<td><code>previous_winner_party</code></td>
<td>The party ID of the person who was elected in the previous ballot for this area</td>
</tr>
</tbody>
</table>

<h2>Votes Cast</h2>
<p>Votes cast will be <a href="/api/docs/next/endpoints/#results_list">
published in our 'next' API</a>.</p>
<p>Use the <code>last_updated</code> param to poll for updates.</p>

<h2 id="atom">ATOM feeds</h2>
<h2 id="atom">Results ATOM feeds</h2>
<p>There is an atom feed of recent election results available in two versions:</p>

<ul>
Expand Down
49 changes: 0 additions & 49 deletions ynr/apps/api/templates/api/csv_list.html

This file was deleted.

32 changes: 32 additions & 0 deletions ynr/apps/api/templates/api/data-and-reports-base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends "base.html" %}

{% block hero %}
{{ block.super }}
<h1>Data and reports</h1>
<nav class="ds-subnav" aria-label="About">
<ul>
<li><a href="{% url "api-home" %}">API</a></li>
<li><a href="{% url "data_home" %}">CSVs</a></li>
{# <li><a href="{% source_url "api_docs_results" %}">Results</a></li>#}
<li><a href="{% url "api-terms" %}">Usage Terms</a></li>
<li><a href="{% url "reports_home" %}">Reports</a></li>
</ul>
</nav>
{% endblock %}

{% block content %}

<style>

</style>
<div class="data-and-reports">
{% block in_page_menu %}

{% endblock %}
<div class="page_content">
{% block api_content %}

{% endblock %}
</div>
</div>
{% endblock %}
7 changes: 1 addition & 6 deletions ynr/apps/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from api.views import (
APIDocsDefinitionsView,
APIDocsEndpointsView,
CSVListView,
NextAPIDocsView,
ResultsDocs,
)
Expand Down Expand Up @@ -84,7 +83,6 @@
next_api_router.register(r"candidates_elected", ElectedViewSet)
next_api_router.register(r"facebook_adverts", FacebookAdvertViewSet)


urlpatterns = [
# Router views
re_path(r"^api/(?P<version>v0.9)/", include(v09_api_router.urls)),
Expand All @@ -104,10 +102,7 @@
TemplateView.as_view(template_name="api/terms.html"),
name="api-terms",
),
re_path(r"^api/docs/csv/$", CSVListView.as_view(), name="api_docs_csv"),
re_path(
r"^api/docs/results/$", ResultsDocs.as_view(), name="api_docs_results"
),
re_path(r"^api/docs/atom/$", ResultsDocs.as_view(), name="api_docs_atom"),
re_path(
r"^api/docs/next/$",
NextAPIDocsView.as_view(patterns=next_api_router.urls, version="next"),
Expand Down
19 changes: 1 addition & 18 deletions ynr/apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.views.generic import TemplateView
from drf_yasg import openapi
from drf_yasg.generators import OpenAPISchemaGenerator
from elections.models import Election
from rest_framework.request import Request


Expand Down Expand Up @@ -64,21 +63,5 @@ def get_context_data(self, **kwargs):
return context


class CSVListView(TemplateView):
template_name = "api/csv_list.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

base_qs = Election.objects.all().order_by(
"current", "-election_date", "slug"
)
context["current_elections"] = base_qs.current()
context["future_elections"] = base_qs.future().exclude(current=True)
context["past_elections"] = base_qs.past().exclude(current=True)

return context


class ResultsDocs(TemplateView):
template_name = "api/results.html"
template_name = "api/atom.html"
19 changes: 13 additions & 6 deletions ynr/apps/data_exports/templates/data_exports/data_home.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{% extends "base.html" %}
{% extends "api/api-base.html" %}
{% load get_query %}
{% load data_field_value %}
{% block content %}

{% block api_content %}
<p>
This page allows downloading CSV exports of our data.
Please see the <a href="{% url "api-terms" %}">terms page</a> for usage terms.
</p>
<p>Although the data is free to use under the terms, we would love to know what your planning to use the data
and are happy to answer any questions you might have. <a href="https://democracyclub.org.uk/contact/">
Please get in touch</a>!</p>
<form action="" method="get">



<aside class="ds-filter">
<details {% if filter_set.data %}open=""{% endif %}>
<summary>Filters</summary>
Expand Down Expand Up @@ -79,9 +83,12 @@ <h3>{{ group_name|title }}</h3>
</details>
</aside>

<p style="margin-top:1em">
<button type="submit" class="button">Filter</button>
<a class="button" href="{% url "data_export" %}{% query_string request.GET format='csv' %}">Download CSV</a>
</p>


<input type="submit" class="button">
</form>
<div style="overflow-x: scroll; max-width: 100%">

Expand Down
4 changes: 1 addition & 3 deletions ynr/apps/elections/uk/templates/candidates/finder.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h1>Open candidate information for UK elections</h1>
{% sopn_import_progress %}
{% current_election_stats %}
{% results_progress %}
{% data_download %}
</div>
</div>
{% endif %}
Expand Down Expand Up @@ -97,9 +98,6 @@ <h1>Open candidate information for UK elections</h1>
{{ postcode_form.as_p }}
<input type="submit" class="button" value="Help add information!"/>
</form>
<h4>or</h4>
<h3>Get the data</h3>
<p><a href="/help/api" class="button secondary">Via our API or CSV download</a></p>
</div>
{% if front_page_cta == "BY_ELECTIONS" %}
<div class="finder__forms__container" style="margin-top:3em">
Expand Down
Loading

0 comments on commit 3d799db

Please sign in to comment.