Use single url for toggle publish/unpublish election ballots.
This commit is contained in:
parent
9b6640c2ae
commit
97bea50b03
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -115,7 +115,7 @@
|
||||
{% if perms.assignment.can_manage_assignment %}
|
||||
</a>
|
||||
<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' %}">
|
||||
<span></span>
|
||||
</a>
|
||||
|
@ -95,15 +95,8 @@ urlpatterns = patterns('assignment.views',
|
||||
),
|
||||
|
||||
url(r'^poll/(?P<poll_id>\d+)/pub/$',
|
||||
'set_published',
|
||||
{'published': True},
|
||||
name='assignment_poll_publish',
|
||||
),
|
||||
|
||||
url(r'^poll/(?P<poll_id>\d+)/notpub/$',
|
||||
'set_published',
|
||||
{'published': False},
|
||||
name='assignment_poll_notpublish',
|
||||
'set_publish_status',
|
||||
name='assignment_poll_publish_status',
|
||||
),
|
||||
|
||||
url(r'^(?P<assignment_id>\d+)/elected/(?P<profile_id>\d+)$',
|
||||
|
@ -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))
|
||||
|
||||
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})
|
||||
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():
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user