diff --git a/VERSION b/VERSION index f314d020..ddf1d4ae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.10.9 +0.10.10 diff --git a/core/static/js/wasa2il.js b/core/static/js/wasa2il.js index 5246c4d6..25bf9a66 100755 --- a/core/static/js/wasa2il.js +++ b/core/static/js/wasa2il.js @@ -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 { diff --git a/core/views.py b/core/views.py index 5d9642d7..c278587b 100644 --- a/core/views.py +++ b/core/views.py @@ -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 @@ -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): @@ -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']) diff --git a/election/models.py b/election/models.py index a89fa01b..ff10ebaf 100644 --- a/election/models.py +++ b/election/models.py @@ -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. diff --git a/urls.py b/urls.py index 9b19ddb0..6f2d20e3 100644 --- a/urls.py +++ b/urls.py @@ -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\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')), diff --git a/wasa2il/settings.py b/wasa2il/settings.py index 5257ebcc..5aed337c 100644 --- a/wasa2il/settings.py +++ b/wasa2il/settings.py @@ -4,6 +4,9 @@ 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: @@ -11,7 +14,7 @@ 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() diff --git a/wasa2il/templates/_sidenav_polity.html b/wasa2il/templates/_sidenav_polity.html index 5771e7b4..fe967fbf 100644 --- a/wasa2il/templates/_sidenav_polity.html +++ b/wasa2il/templates/_sidenav_polity.html @@ -69,3 +69,4 @@ {% trans 'You are not a member of this polity.' %} {% endif %} + diff --git a/wasa2il/templates/_sidenav_profile.html b/wasa2il/templates/_sidenav_profile.html index 2c048ee5..3e35455e 100644 --- a/wasa2il/templates/_sidenav_profile.html +++ b/wasa2il/templates/_sidenav_profile.html @@ -14,3 +14,4 @@ {% trans "User's tasks" %} {% endif %} + diff --git a/wasa2il/templates/base.html b/wasa2il/templates/base.html index b67e553d..84feaa15 100644 --- a/wasa2il/templates/base.html +++ b/wasa2il/templates/base.html @@ -103,14 +103,11 @@ {% elif profile %} {% include "_sidenav_profile.html" %} {% endif %} - - - {% block dialog %}{% endblock %} - {% include 'splash-message.html' %} + {% include 'splash_message.html' %}
{% comment %} diff --git a/wasa2il/templates/registration/data_disclaimer.html b/wasa2il/templates/registration/data_disclaimer.html deleted file mode 100644 index dd45ec9d..00000000 --- a/wasa2il/templates/registration/data_disclaimer.html +++ /dev/null @@ -1,15 +0,0 @@ -{% load i18n %} - -

{% trans "As of February 12th 2014, we require the verification of all user accounts via the so-called Icekey." %}

-{% if not request.GET.email %} -

{% trans "Please be advised that by registering and verifying your account, you become a member of the Pirate Party of Iceland." %}

-{% endif %} -

{% trans "Membership of political organizations is considered sensitive information by law." %}

-

{% trans "Therefore, you should keep the following in mind when becoming a member and using our system:" %}

- diff --git a/wasa2il/templates/registration/login.html b/wasa2il/templates/registration/login.html index 91ac4c55..e0984352 100644 --- a/wasa2il/templates/registration/login.html +++ b/wasa2il/templates/registration/login.html @@ -44,9 +44,6 @@

{% trans "Log in" %} {% trans "and partake in democracy..." %}

-
-
-{% include "registration/data_disclaimer.html" %} -
+ {% endblock %} diff --git a/wasa2il/templates/registration/registration_form.html b/wasa2il/templates/registration/registration_form.html index c26415dc..4ff71b42 100644 --- a/wasa2il/templates/registration/registration_form.html +++ b/wasa2il/templates/registration/registration_form.html @@ -10,15 +10,13 @@

{% trans "Sign up" %} {% trans 'and partake in democracy...' %}

-{% if not request.GET.email %} -
-{% include "registration/data_disclaimer.html" %} -
-
-{% endif %} -
+ +

+ {% trans "Please be advised that by registering and verifying your account, you become a member of the Pirate Party of Iceland." %} +

+ {% if request.GET.email_sig and request.GET.email %}
{% else %} @@ -47,12 +45,5 @@

{% trans "Sign up" %} {% trans 'and partake in democracy...' %} -{% if request.GET.email %} -
-
- {% include 'registration/data_disclaimer.html' %} -
-{% endif %} -

{% endblock %} diff --git a/wasa2il/templates/splash-message.html b/wasa2il/templates/splash_message.html similarity index 100% rename from wasa2il/templates/splash-message.html rename to wasa2il/templates/splash_message.html