Пример #1
0
 def response_change(self, request, obj):
     """
     Determines the HttpResponse for the change_view stage.
     """
     if '_approve' in request.POST:
         try:
             obj.staff_approve(request.user)
         except ValidationError as e:
             msg = _("Unable to approve service '{name}': {error}.")
             msg = msg.format(name=obj.name, error=validation_error_as_text(e))
             self.message_user(request, msg, messages.ERROR)
             redirect_url = add_preserved_filters(
                 {'preserved_filters': self.get_preserved_filters(request),
                  'opts': self.model._meta},
                 request.path)
             return HttpResponseRedirect(redirect_url)
         else:
             msg = _('The service was approved successfully.')
             self.message_user(request, msg, messages.SUCCESS)
     elif '_reject' in request.POST:
         try:
             obj.staff_reject(request.user)
         except ValidationError as e:
             msg = _("Unable to reject service '{name}': {error}.")
             msg = msg.format(name=obj.name, error=validation_error_as_text(e))
             self.message_user(request, msg, messages.ERROR)
             redirect_url = add_preserved_filters(
                 {'preserved_filters': self.get_preserved_filters(request),
                  'opts': self.model._meta},
                 request.path)
             return HttpResponseRedirect(redirect_url)
         else:
             msg = _('The service was rejected successfully.')
             self.message_user(request, msg, messages.INFO)
     return super().response_change(request, obj)
Пример #2
0
 def response_change(self, request, obj):
     """
     Determines the HttpResponse for the change_view stage.
     """
     if '_activate' in request.POST:
         try:
             obj.activate_provider()
         except ValidationError as e:
             msg = _("Unable to activate user '{email}': {error}.")
             msg = msg.format(name=obj.email,
                              error=validation_error_as_text(e))
             self.message_user(request, msg, messages.ERROR)
             redirect_url = add_preserved_filters(
                 {
                     'preserved_filters':
                     self.get_preserved_filters(request),
                     'opts': self.model._meta
                 }, request.path)
             return HttpResponseRedirect(redirect_url)
         else:
             msg = _(
                 'The account was activated successfully. Email has been sent to user.'
             )
             self.message_user(request, msg, messages.SUCCESS)
     return super().response_change(request, obj)
Пример #3
0
 def response_change(self, request, obj):
     """
     Determines the HttpResponse for the change_view stage.
     """
     if '_approve' in request.POST:
         try:
             obj.staff_approve(request.user)
         except ValidationError as e:
             msg = _("Unable to approve service '{name}': {error}.")
             msg = msg.format(name=obj.name,
                              error=validation_error_as_text(e))
             self.message_user(request, msg, messages.ERROR)
             redirect_url = add_preserved_filters(
                 {
                     'preserved_filters':
                     self.get_preserved_filters(request),
                     'opts': self.model._meta
                 }, request.path)
             return HttpResponseRedirect(redirect_url)
         else:
             msg = _('The service was approved successfully.')
             self.message_user(request, msg, messages.SUCCESS)
     elif '_reject' in request.POST:
         try:
             obj.staff_reject(request.user)
         except ValidationError as e:
             msg = _("Unable to reject service '{name}': {error}.")
             msg = msg.format(name=obj.name,
                              error=validation_error_as_text(e))
             self.message_user(request, msg, messages.ERROR)
             redirect_url = add_preserved_filters(
                 {
                     'preserved_filters':
                     self.get_preserved_filters(request),
                     'opts': self.model._meta
                 }, request.path)
             return HttpResponseRedirect(redirect_url)
         else:
             msg = _('The service was rejected successfully.')
             self.message_user(request, msg, messages.INFO)
     return super().response_change(request, obj)
Пример #4
0
 def reject(self, request, queryset):
     # All must be in DRAFT status
     if queryset.exclude(status=Service.STATUS_DRAFT).exists():
         self.message_user(request, _("Only services in draft status may be rejected"), messages.ERROR)
         return
     any_rejected = False
     for service in queryset:
         try:
             service.staff_reject(request.user)
         except ValidationError as e:
             msg = _("Unable to reject service '{name}': {error}.")
             msg = msg.format(name=service.name, error=validation_error_as_text(e))
             messages.error(request, msg)
         else:
             any_rejected = True
     if any_rejected:
         self.message_user(request, _("Services have been rejected"))
Пример #5
0
 def reject(self, request, queryset):
     # All must be in DRAFT status
     if queryset.exclude(status=Service.STATUS_DRAFT).exists():
         self.message_user(
             request, _("Only services in draft status may be rejected"),
             messages.ERROR)
         return
     any_rejected = False
     for service in queryset:
         try:
             service.staff_reject(request.user)
         except ValidationError as e:
             msg = _("Unable to reject service '{name}': {error}.")
             msg = msg.format(name=service.name,
                              error=validation_error_as_text(e))
             messages.error(request, msg)
         else:
             any_rejected = True
     if any_rejected:
         self.message_user(request, _("Services have been rejected"))