19
23
return direct_to_template(request, 'election/election_new.html', {})
21
25
def election_queue(request):
22
elections = Election.objects.filter(candidacy_start__gt=datetime.datetime.now())
26
elections = Election.objects.filter(candidature_start__gt=datetime.datetime.now())
23
27
return direct_to_template(request, 'election/election_list.html', {'elections': elections})
25
29
def election_active(request):
26
elections = Election.objects.filter(candidacy_start__lt=datetime.datetime.now(), election_end__gt=datetime.datetime.now())
30
elections = Election.objects.filter(candidature_start__lt=datetime.datetime.now(), election_end__gt=datetime.datetime.now())
27
31
return direct_to_template(request, 'election/election_list.html', {'elections': elections})
29
33
def election_past(request):
54
58
if request.POST and form.is_valid():
55
59
election = form.save()
56
messages.success(request, 'De verkiezing is gewijzigd.')
60
messages.success(request, _('The election has been edited'))
57
61
return redirect(election_detail, electionId=election.pk, electionName=election.name)
59
63
return direct_to_template(request, 'election/election_edit.html', {'form': form, 'election': election})
61
65
@custom_permission_required('elections.can_becandidate')
62
def election_apply(request, electionId, electionName):
66
def election_run(request, electionId, electionName):
63
67
election = Election.objects.get(pk=electionId)
64
if datetime.datetime.now() < election.candidacy_start:
65
messages.error(request, 'De kandidaatstelling is nog niet begonnen')
68
if datetime.datetime.now() < election.candidature_start:
69
messages.error(request, _('The candidature period hasn\'t started yet'))
66
70
return redirect(election_detail, electionId=election.pk, electionName=election.name)
67
if datetime.datetime.now() > election.candidacy_end:
68
messages.error(request, 'De kandidaatstelling is al afgelopen')
71
if datetime.datetime.now() > election.candidature_end:
72
messages.error(request, _('The candidature period has ended already'))
69
73
return redirect(election_detail, electionId=election.pk, electionName=election.name)
71
75
candidate, created = Candidate.objects.get_or_create(election=election, user=request.user)
76
80
candidate.display_name = lp.people[candidate.user.username].display_name
77
81
candidate.lp_profile = u"https://launchpad.net/~" + lp.people[candidate.user.username].name
79
messages.success(request, 'Je kandidaatstelling is succesvol aangepast.')
83
messages.success(request, _('Your candidature has been edited successfully'))
80
84
return redirect(election_detail, electionId=election.pk, electionName=election.name)
82
return direct_to_template(request, 'election/election_candidacy.html', {'form': form, 'election': election})
86
return direct_to_template(request, 'election/election_candidature.html', {'form': form, 'election': election})
84
88
@custom_permission_required('elections.can_vote')
85
89
def election_vote(request, electionId, electionName):
86
90
election = Election.objects.get(pk=electionId)
87
91
if datetime.datetime.now() < election.election_start:
88
messages.error(request, 'De verkiezing is nog niet begonnen')
92
messages.error(request, _('The election hasn\'t started yet'))
89
93
return redirect(election_detail, electionId=election.pk, electionName=election.name)
90
94
if datetime.datetime.now() > election.election_end:
91
messages.error(request, 'De verkiezing is al afgelopen')
95
messages.error(request, _('The election has ended already'))
92
96
return redirect(election_detail, electionId=election.pk, electionName=election.name)
93
97
if len(Candidate.objects.filter(election=election, chair_desired=True)) < 1:
94
messages.error(request, 'Er zijn niet genoeg kandidaten voor het voorzitterschap om de verkiezing te laten beginnen')
98
messages.error(request, _('There aren\'t enough candidates running for Chair to let the elections begin'))
95
99
return redirect(election_detail, electionId=election.pk, electionName=election.name)
96
100
if len(Candidate.objects.filter(election=election, council_desired=True)) < 6:
97
messages.error(request, 'Er zijn niet genoeg kandidaten voor de gemeenschapsraad om de verkiezing te laten beginnen')
101
messages.error(request, _('There aren\'t enough candidates running for the Community Council to let the elections begin'))
98
102
return redirect(election_detail, electionId=election.pk, electionName=election.name)
104
# Do some extensive hashing of the voter's OpenID to prevent easy decryption
100
105
openid = UserOpenID.objects.get(user=request.user)
101
user_hash = hash(openid.claimed_id) # TODO: Do a better hash
106
user_hash = hashlib.sha256(openid.claimed_id)
107
user_hash.update(SECRET_KEY)
108
user_hash = hashlib.sha256(user_hash.hexdigest())
109
user_hash.update(SECRET_KEY2)
110
for i in range(0,10):
111
user_hash = hashlib.sha256(user_hash.hexdigest())
102
113
try: # If the voter already exists, it has already voted, raise an exception!
103
Voter.objects.get(election=election, voter=user_hash)
114
Voter.objects.get(election=election, voter=user_hash.hexdigest())
104
115
except Voter.DoesNotExist:
107
messages.error(request, 'Je hebt al gestemd voor deze verkiezing')
118
messages.error(request, _('You\'ve already voted'))
108
119
return redirect(election_detail, electionId=election.pk, electionName=election.name)
110
121
form = VoteForm(data=request.POST or None, election=election)
112
123
if request.POST and form.is_valid():
114
125
Voter.objects.create(election=election, voter=user_hash)
115
messages.success(request, 'Je hebt gestemd.')
126
messages.success(request, _('You\'ve voted successfully'))
116
127
return redirect(election_detail, electionId=election.pk, electionName=election.name)
118
129
return direct_to_template(request, 'election/election_vote.html', {'form': form,
123
134
election = Election.objects.get(pk=electionId)
124
135
if datetime.datetime.now() < election.election_start:
125
136
if election.live_results:
126
messages.error(request, 'Het stemmen is nog niet begonnen, de eerste resultaten zijn pas zichtbaar op: %s' % election.election_start)
137
messages.error(request, _('The voting hasn\'t begun yet, the first results will be visible on %(date)s.') % election.election_start)
127
138
return redirect(election_detail, electionId=election.pk, electionName=election.name)
129
messages.error(request, 'Het stemmen is nog niet begonnen, de eerste resultaten zijn pas zichtbaar op: %s' % election.election_end)
140
messages.error(request, _('The voting hasn\'t begun yet, the first results will be visible on %(date)s.') % election.election_end)
130
141
return redirect(election_detail, electionId=election.pk, electionName=election.name)
131
142
if datetime.datetime.now() < election.election_end and not election.live_results:
132
messages.error(request, 'De resultaten zijn pas zichtbaar na de stemming (%s)' % election.election_end)
143
messages.error(request, _('The results will be visible after the vote has finished, on %(date)s.') % election.election_end)
133
144
return redirect(election_detail, electionId=election.pk, electionName=election.name)
135
146
top_chairs = Candidate.objects.filter(election=election, chair_desired=True).order_by('-chair_votes')[:5]