Skip to content
Snippets Groups Projects
Commit 12344a26 authored by Ben Adida's avatar Ben Adida
Browse files

added election metadata API endpoint and call from client to get things like help email address

parent c3838c46
Branches
Tags
No related merge requests found
......@@ -9,8 +9,12 @@ from django.conf.urls.defaults import *
from helios.views import *
urlpatterns = patterns('',
# election data that is cryptographically verified
(r'^$', one_election),
# metadata that need not be verified
(r'^/meta$', one_election_meta),
# edit election params
(r'^/edit$', one_election_edit),
(r'^/schedule$', one_election_schedule),
......
{"help_email": "help@heliosvoting.org", "use_advanced_audit_features": true}
\ No newline at end of file
......@@ -133,6 +133,14 @@ class Election(HeliosModel):
# help email
help_email = models.EmailField(null=True)
# metadata for the election
@property
def metadata(self):
return {
'help_email': self.help_email or 'help@heliosvoting.org',
'use_advanced_audit_features': self.use_advanced_audit_features
}
@property
def pretty_type(self):
return dict(self.ELECTION_TYPES)[self.election_type]
......
......@@ -312,6 +312,10 @@ class DataFormatBlackboxTests(object):
response = self.client.get("/helios/elections/%s" % self.election.uuid, follow=False)
self.assertEqualsToFile(response, self.EXPECTED_ELECTION_FILE)
def test_election_metadata(self):
response = self.client.get("/helios/elections/%s/meta" % self.election.uuid, follow=False)
self.assertEqualsToFile(response, self.EXPECTED_ELECTION_METADATA_FILE)
def test_voters_list(self):
response = self.client.get("/helios/elections/%s/voters/" % self.election.uuid, follow=False)
self.assertEqualsToFile(response, self.EXPECTED_VOTERS_FILE)
......@@ -331,6 +335,7 @@ class DataFormatBlackboxTests(object):
class LegacyElectionBlackboxTests(DataFormatBlackboxTests, TestCase):
fixtures = ['legacy-data.json']
EXPECTED_ELECTION_FILE = 'helios/fixtures/legacy-election-expected.json'
EXPECTED_ELECTION_METADATA_FILE = 'helios/fixtures/legacy-election-metadata-expected.json'
EXPECTED_VOTERS_FILE = 'helios/fixtures/legacy-election-voters-expected.json'
EXPECTED_TRUSTEES_FILE = 'helios/fixtures/legacy-trustees-expected.json'
EXPECTED_BALLOTS_FILE = 'helios/fixtures/legacy-ballots-expected.json'
......
......@@ -290,6 +290,13 @@ def one_election(request, election):
raise Http404
return election.toJSONDict(complete=True)
@election_view()
@json
def one_election_meta(request, election):
if not election:
raise Http404
return election.metadata
@election_view()
def election_badge(request, election):
election_url = get_election_url(election)
......
<span style="float:right; padding-right:20px;">
<a target="_new" href="mailto:help@heliosvoting.org?subject=help%20with%20election%20{$T.election.name}&body=I%20need%20help%20with%20election%20{$T.election.uuid}">help!</a>
<a target="_new" href="mailto:{$T.election_metadata.help_email}?subject=help%20with%20election%20{$T.election.name}&body=I%20need%20help%20with%20election%20{$T.election.uuid}">help!</a>
</span>
{#if $T.election.BOGUS_P}
The public key for this election is not yet ready. This election is in preview mode only.
......
......@@ -182,8 +182,8 @@ BOOTH.setup_election = function(raw_json) {
BOOTH.election[field] = escape_html(BOOTH.election[field]);
});
$('#header').processTemplate({'election' : BOOTH.election});
$('#footer').processTemplate({'election' : BOOTH.election});
$('#header').processTemplate({'election' : BOOTH.election, 'election_metadata': BOOTH.election_metadata});
$('#footer').processTemplate({'election' : BOOTH.election, 'election_metadata': BOOTH.election_metadata});
BOOTH.setup_ballot();
};
......@@ -326,10 +326,14 @@ BOOTH.show_encryption_message_before = function(func_to_execute) {
BOOTH.load_and_setup_election = function(election_url) {
// the hash will be computed within the setup function call now
$.get(election_url, function(raw_json) {
// let's also get the metadata
$.getJSON(election_url + "/meta", {}, function(election_metadata) {
BOOTH.election_metadata = election_metadata;
BOOTH.setup_election(raw_json);
BOOTH.show_election();
BOOTH.election_url = election_url;
});
});
if (USE_SJCL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment