From 97bea50b033763fa9ffc4cb43c75e371c39232e2 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sun, 20 May 2012 20:02:36 +0200 Subject: [PATCH] Use single url for toggle publish/unpublish election ballots. --- .../static/javascript/assignment.js | 3 ++- .../assignment/templates/assignment/view.html | 2 +- openslides/assignment/urls.py | 11 ++------- openslides/assignment/views.py | 23 +++++++++---------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/openslides/assignment/static/javascript/assignment.js b/openslides/assignment/static/javascript/assignment.js index 761a46756..9198434a0 100644 --- a/openslides/assignment/static/javascript/assignment.js +++ b/openslides/assignment/static/javascript/assignment.js @@ -58,10 +58,11 @@ $(function() { success: function(data) { if (data.published) { link.addClass('published'); + //link.attr('title', gettext('Unpublish ballot')) } else { link.removeClass('published'); + //link.attr('title', 'Publish ballot') } - link.attr('href', data.link); } }); }); diff --git a/openslides/assignment/templates/assignment/view.html b/openslides/assignment/templates/assignment/view.html index 069b37dd5..9ac452b0e 100644 --- a/openslides/assignment/templates/assignment/view.html +++ b/openslides/assignment/templates/assignment/view.html @@ -115,7 +115,7 @@ {% if perms.assignment.can_manage_assignment %} diff --git a/openslides/assignment/urls.py b/openslides/assignment/urls.py index d472cd88c..6d6b70603 100644 --- a/openslides/assignment/urls.py +++ b/openslides/assignment/urls.py @@ -95,15 +95,8 @@ urlpatterns = patterns('assignment.views', ), url(r'^poll/(?P\d+)/pub/$', - 'set_published', - {'published': True}, - name='assignment_poll_publish', - ), - - url(r'^poll/(?P\d+)/notpub/$', - 'set_published', - {'published': False}, - name='assignment_poll_notpublish', + 'set_publish_status', + name='assignment_poll_publish_status', ), url(r'^(?P\d+)/elected/(?P\d+)$', diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index ede62a0f2..812b92ce4 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -236,26 +236,25 @@ class ViewPoll(PollFormView): @permission_required('assignment.can_manage_assignment') -def set_published(request, poll_id, published=True): +def set_publish_status(request, poll_id): try: poll = AssignmentPoll.objects.get(pk=poll_id) - poll.set_published(published) if poll.published: - messages.success(request, _("Poll successfully set to published.") ) + poll.set_published(False) else: - messages.success(request, _("Poll successfully set to unpublished.") ) + poll.set_published(True) except AssignmentPoll.DoesNotExist: - messages.error(request, _('Poll ID %d does not exist.') % int(poll_id)) + messages.error(request, _('Ballot ID %d does not exist.') % int(poll_id)) + return redirect(reverse('assignment_view', args=[poll.assignment.id])) if request.is_ajax(): - if published: - link = reverse('assignment_poll_notpublish', args=[poll_id]) - else: - link = reverse('assignment_poll_publish', args=[poll_id]) - return ajax_request({'published': published, - 'link': link}) - return redirect(reverse('assignment_view', args=[poll.assignment.id])) + return ajax_request({'published': poll.published}) + if poll.published: + messages.success(request, _("Ballot successfully published.") ) + else: + messages.success(request, _("Ballot successfully unpublished.") ) + return redirect(reverse('assignment_view', args=[poll.assignment.id])) @permission_required('assignment.can_manage_assignment')