Skip to content

Commit

Permalink
Remove old CSV links, link to CSV builder
Browse files Browse the repository at this point in the history
  • Loading branch information
symroe committed May 24, 2024
1 parent abf735e commit cf14599
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 182 deletions.
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
1 change: 0 additions & 1 deletion ynr/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
{% block menu_bar_links %}
<li class="nav-links__item"><a href="{% url 'help-about' %}">About</a></li>
<li class="nav-links__item"><a href="{% url 'election_list_view' %}">Elections</a></li>
<li class="nav-links__item"><a href="{% url 'results-home' %}">Results</a></li>
<li class="nav-links__item"><a href="{% url 'reports_home' %}">Numbers</a></li>
<li class="nav-links__item"><a href="{% url 'volunteer-view' %}">Volunteer</a></li>
<li class="nav-links__item"><a href="{% url 'api-home' %}">Data</a></li>
Expand Down

0 comments on commit cf14599

Please sign in to comment.