Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin'
Browse files Browse the repository at this point in the history
  • Loading branch information
helgihg committed Jun 18, 2018
2 parents 1d8a307 + adaf722 commit 943b5d0
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 59 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.9
0.10.10
20 changes: 8 additions & 12 deletions core/static/js/wasa2il.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,18 @@ function election_render(election) {
$(".voting").show();
}

// FIXME: The second term here makes much of the code below obsolete.
// This is deliberate; we would like to allow users to withdraw
// their candidacy at any time, but we need a few more things before
// that is safe and reasonable:
// 1. E-mail notifications to people who have voted for the candidate
// 2. A grace period so people can update their votes
// 3. Double-checking the ballot counting logic to ensure this does
// not break anything at that end, as it will create a gap in
// the user's ballot sequence.
if (election_ui_update_is_safe()) {
if (election_state == 'concluded' || election_state == 'voting') {
if (election_state == 'concluded') {
$("#election_button_withdraw").hide();
$("#election_button_announce").hide();
}
else if (election_object.user_is_candidate) {
$("#election_button_withdraw").show();
else if (election_state == 'voting') {
if (election_object.user_is_candidate) {
$("#election_button_withdraw").show();
}
else {
$("#election_button_withdraw").hide();
}
$("#election_button_announce").hide();
}
else {
Expand Down
36 changes: 29 additions & 7 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@

from hashlib import sha1

# BEGIN - Included for Wasa2ilLoginView
from django.contrib.auth import login as auth_login
from django.contrib.auth.views import LoginView
# END

# BEGIN - Included for Wasa2ilRegistrationView
# BEGIN - Included for Wasa2ilRegistrationView and Wasa2ilActivationView
from django.contrib.auth import login
from django.contrib.sites.shortcuts import get_current_site
from registration.backends.default.views import ActivationView
from registration.backends.default.views import RegistrationView
from registration import signals as registration_signals
# END
Expand Down Expand Up @@ -547,6 +544,31 @@ def register(self, form):
return new_user


class Wasa2ilActivationView(ActivationView):

def activate(self, *args, **kwargs):
activation_key = kwargs.get('activation_key', '')
site = get_current_site(self.request)
user, activated = self.registration_profile.objects.activate_user(
activation_key,
site
)

if activated:
registration_signals.user_activated.send(
sender=self.__class__,
user=user,
request=self.request
)

login(self.request, user, 'django.contrib.auth.backends.ModelBackend')

return user

def get_success_url(self, user):
return '%s?returnTo=%s' % (reverse('tc_accept_page'), reverse('login_or_saml_redirect'))


@login_required
def verify(request):

Expand Down Expand Up @@ -613,7 +635,7 @@ def login_or_saml_redirect(request):
we want immediately following the login, before verification.
'''
if request.user.userprofile.verified:
return settings.LOGIN_REDIRECT_URL
return redirect(settings.LOGIN_REDIRECT_URL)
else:
return redirect(settings.SAML_1['URL'])

Expand Down
21 changes: 21 additions & 0 deletions election/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ def process(self):
if self.is_processed:
raise Election.AlreadyProcessedException('Election %s has already been processed!' % self)

# "Flatten" the values of votes in an election. A candidate may be
# removed from an election when voting has already started. When that
# happens, ballots with that candidate may have a gap in their values,
# for example [0, 1, 2, 4] , because the person with value 3 was
# removed from the election. Here the ballot is "flattened" so that
# gaps are eliminated and the values are made sequential, i.e.
# [0, 1, 2, 3] and not [0, 1, 2, 4].
votes = self.electionvote_set.order_by('user_id', 'value')
last_user_id = 0
for vote in votes:
# Reset correct value every time we start processing a new user.
if last_user_id != vote.user_id:
correct_value = 0

if vote.value != correct_value:
vote.value = correct_value
vote.save()

correct_value += 1
last_user_id = vote.user_id

if self.candidate_set.count() == 0:
# If there are no candidates, there's no need to calculate
# anything. We're pretty confident in these being the results.
Expand Down
7 changes: 6 additions & 1 deletion urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@

url(r'^accounts/sso/', core_views.sso),
url(r'^accounts/register/$', core_views.Wasa2ilRegistrationView.as_view(), name='registration_register'),
url(
r'^accounts/activate/(?P<activation_key>\w+)/$',
core_views.Wasa2ilActivationView.as_view(),
name='registration_activate'
),

# SAML-related URLs.
url(r'^accounts/verify/', core_views.verify),
url(r'^accounts/login-or-saml-redirect/', core_views.login_or_saml_redirect),
url(r'^accounts/login-or-saml-redirect/', core_views.login_or_saml_redirect, name='login_or_saml_redirect'),

url(r'^accounts/', include('registration.urls')),

Expand Down
5 changes: 4 additions & 1 deletion wasa2il/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import os
from utils import here

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

try:
from local_settings import *
except ImportError:
from default_settings import *
print('No local_settings.py found. Setting default values.')

# Get Wasa2il version.
with open('VERSION', 'r') as f:
with open(os.path.join(BASE_DIR, 'VERSION'), 'r') as f:
WASA2IL_VERSION = f.readlines().pop(0).strip()
f.close()

Expand Down
1 change: 1 addition & 0 deletions wasa2il/templates/_sidenav_polity.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
<span class="label label-warning">{% trans 'You are not a member of this polity.' %}</span>
{% endif %}
</li>
</ul>
1 change: 1 addition & 0 deletions wasa2il/templates/_sidenav_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
{% trans "User's tasks" %}
</a></li>
{% endif %}
</ul>
5 changes: 1 addition & 4 deletions wasa2il/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,11 @@
{% elif profile %}
{% include "_sidenav_profile.html" %}
{% endif %}


</ul>
</div>

{% block dialog %}{% endblock %}

{% include 'splash-message.html' %}
{% include 'splash_message.html' %}

<div id="content-wrapper">
{% comment %}
Expand Down
15 changes: 0 additions & 15 deletions wasa2il/templates/registration/data_disclaimer.html

This file was deleted.

5 changes: 1 addition & 4 deletions wasa2il/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ <h1>{% trans "Log in" %} <small>{% trans "and partake in democracy..." %}</small
</form>
</div>
</div>
<hr/>
<div>
{% include "registration/data_disclaimer.html" %}
</div>

</section>
{% endblock %}
19 changes: 5 additions & 14 deletions wasa2il/templates/registration/registration_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
<section class="content">
<h1>{% trans "Sign up" %} <small>{% trans 'and partake in democracy...' %}</small></h1>

{% if not request.GET.email %}
<div>
{% include "registration/data_disclaimer.html" %}
</div>
<hr>
{% endif %}

<div class="row">
<div class="col-md-6 col-xs-12">

<p class="alert alert-info">
{% trans "Please be advised that by registering and verifying your account, you become a member of the Pirate Party of Iceland." %}
</p>

{% if request.GET.email_sig and request.GET.email %}
<form action="/gateway/register/?{{ request.GET.urlencode }}" method="POST">
{% else %}
Expand Down Expand Up @@ -47,12 +45,5 @@ <h1>{% trans "Sign up" %} <small>{% trans 'and partake in democracy...' %}</smal

</div>

{% if request.GET.email %}
<hr>
<div>
{% include 'registration/data_disclaimer.html' %}
</div>
{% endif %}

</section>
{% endblock %}
File renamed without changes.

0 comments on commit 943b5d0

Please sign in to comment.