Use single url for toggle publish/unpublish election ballots.

This commit is contained in:
Emanuel Schuetze 2012-05-20 20:02:36 +02:00
parent 9b6640c2ae
commit 97bea50b03
4 changed files with 16 additions and 23 deletions

View File

@ -58,10 +58,11 @@ $(function() {
success: function(data) { success: function(data) {
if (data.published) { if (data.published) {
link.addClass('published'); link.addClass('published');
//link.attr('title', gettext('Unpublish ballot'))
} else { } else {
link.removeClass('published'); link.removeClass('published');
//link.attr('title', 'Publish ballot')
} }
link.attr('href', data.link);
} }
}); });
}); });

View File

@ -115,7 +115,7 @@
{% if perms.assignment.can_manage_assignment %} {% if perms.assignment.can_manage_assignment %}
</a> </a>
<a class="publish_link {% if poll.published %}published{% endif %}" <a class="publish_link {% if poll.published %}published{% endif %}"
href="{% if poll.published %}{% url assignment_poll_notpublish poll.id %}{% else %}{% url assignment_poll_publish poll.id %}{% endif %}" href="{% url assignment_poll_publish_status poll.id %}"
title="{%trans 'Publish/unpublish results' %}"> title="{%trans 'Publish/unpublish results' %}">
<span></span> <span></span>
</a> </a>

View File

@ -95,15 +95,8 @@ urlpatterns = patterns('assignment.views',
), ),
url(r'^poll/(?P<poll_id>\d+)/pub/$', url(r'^poll/(?P<poll_id>\d+)/pub/$',
'set_published', 'set_publish_status',
{'published': True}, name='assignment_poll_publish_status',
name='assignment_poll_publish',
),
url(r'^poll/(?P<poll_id>\d+)/notpub/$',
'set_published',
{'published': False},
name='assignment_poll_notpublish',
), ),
url(r'^(?P<assignment_id>\d+)/elected/(?P<profile_id>\d+)$', url(r'^(?P<assignment_id>\d+)/elected/(?P<profile_id>\d+)$',

View File

@ -236,26 +236,25 @@ class ViewPoll(PollFormView):
@permission_required('assignment.can_manage_assignment') @permission_required('assignment.can_manage_assignment')
def set_published(request, poll_id, published=True): def set_publish_status(request, poll_id):
try: try:
poll = AssignmentPoll.objects.get(pk=poll_id) poll = AssignmentPoll.objects.get(pk=poll_id)
poll.set_published(published)
if poll.published: if poll.published:
messages.success(request, _("Poll successfully set to published.") ) poll.set_published(False)
else: else:
messages.success(request, _("Poll successfully set to unpublished.") ) poll.set_published(True)
except AssignmentPoll.DoesNotExist: 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 request.is_ajax():
if published: return ajax_request({'published': poll.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]))
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') @permission_required('assignment.can_manage_assignment')