Fix new class based view for support/unsupport motions. Fix strange error in QuestionMixin.
This commit is contained in:
parent
3bde0a8af9
commit
c036be05bf
@ -364,13 +364,13 @@ def reset(request, application_id):
|
|||||||
return redirect(reverse('application_view', args=[application_id]))
|
return redirect(reverse('application_view', args=[application_id]))
|
||||||
|
|
||||||
|
|
||||||
class SupportView(RedirectView, SingleObjectMixin, QuestionMixin):
|
class SupportView(SingleObjectMixin, QuestionMixin, RedirectView):
|
||||||
"""
|
"""
|
||||||
Support or unsupport an application
|
Support or unsupport an application
|
||||||
"""
|
"""
|
||||||
permission_required = 'application.can_support_application'
|
permission_required = 'application.can_support_application'
|
||||||
model = Application
|
model = Application
|
||||||
pk_url_kwarg = 'application_id' # TODO: Is this line neccessary?
|
pk_url_kwarg = 'application_id'
|
||||||
unsupport = False # Must be given in SupportView.as_view()
|
unsupport = False # Must be given in SupportView.as_view()
|
||||||
answer_url = None # Must be given in SupportView.as_view()
|
answer_url = None # Must be given in SupportView.as_view()
|
||||||
|
|
||||||
@ -380,24 +380,18 @@ class SupportView(RedirectView, SingleObjectMixin, QuestionMixin):
|
|||||||
else:
|
else:
|
||||||
return _('Do you really want to unsupport this motion?')
|
return _('Do you really want to unsupport this motion?')
|
||||||
|
|
||||||
# TODO: Why do we have to overwrite this method?
|
|
||||||
def pre_redirect(self, request, *args, **kwargs):
|
|
||||||
self.confirm_form()
|
|
||||||
|
|
||||||
def pre_post_redirect(self, request, *args, **kwargs):
|
def pre_post_redirect(self, request, *args, **kwargs):
|
||||||
if self.get_answer().lower() == 'yes':
|
if self.get_answer().lower() == 'yes':
|
||||||
if not self.unsupport:
|
if not self.unsupport:
|
||||||
Application.objects.get(pk=kwargs['application_id']).support(person=request.user)
|
self.get_object().support(person=request.user)
|
||||||
# Should the Exception Application.DoesNotExist be kept or not?
|
|
||||||
self.success_message = _("You have supported this motion successfully.")
|
self.success_message = _("You have supported this motion successfully.")
|
||||||
else:
|
else:
|
||||||
Application.objects.get(pk=kwargs['application_id']).unsupport(person=request.user)
|
self.get_object().unsupport(person=request.user)
|
||||||
# Should the Exception Application.DoesNotExist be kept or not?
|
|
||||||
self.success_message = _("You have unsupported this motion successfully.")
|
self.success_message = _("You have unsupported this motion successfully.")
|
||||||
messages.success(request, self.success_message)
|
messages.success(request, self.success_message)
|
||||||
|
|
||||||
def get_redirect_url(self, **kwargs):
|
def get_redirect_url(self, **kwargs):
|
||||||
return reverse('application_view', args=[kwargs['application_id']])
|
return reverse('application_view', args=[kwargs[self.pk_url_kwarg]])
|
||||||
|
|
||||||
|
|
||||||
@permission_required('application.can_manage_application')
|
@permission_required('application.can_manage_application')
|
||||||
|
@ -143,7 +143,7 @@ class QuestionMixin(object):
|
|||||||
'option_fields': option_fields})
|
'option_fields': option_fields})
|
||||||
|
|
||||||
def pre_redirect(self, request, *args, **kwargs):
|
def pre_redirect(self, request, *args, **kwargs):
|
||||||
self.confirm_form(request, self.object)
|
self.confirm_form()
|
||||||
|
|
||||||
def pre_post_redirect(self, request, *args, **kwargs):
|
def pre_post_redirect(self, request, *args, **kwargs):
|
||||||
messages.success(request)
|
messages.success(request)
|
||||||
|
Loading…
Reference in New Issue
Block a user