def _handle_set_is_active(self): old_state = self.object.is_active state = bool(int(self.request.POST["set_is_active"])) if not state and hasattr(self.object, "user"): if (getattr(self.object.user, 'is_superuser', False) and not getattr( self.request.user, 'is_superuser', False )): raise Problem(_("You can not deactivate a superuser. Remove superuser permission first.")) if self.object.user == self.request.user: raise Problem(_("You can not deactivate yourself. Use another account to deactivate the current one.")) self.object.is_active = state self.object.save(update_fields=("is_active",)) messages.success(self.request, _("%(contact)s is now %(state)s.") % { "contact": self.object, "state": _("active") if state else _("inactive") }) if (self.object.is_active and self.object.is_active != old_state and isinstance(self.object, CompanyContact)): company_contact_activated.send(sender=type(self.object), instance=self.object, request=self.request) return HttpResponseRedirect(self.request.path)
def _handle_set_is_active(self): old_state = self.object.is_active state = bool(int(self.request.POST["set_is_active"])) if not state and hasattr(self.object, "user"): if (getattr(self.object.user, 'is_superuser', False) and not getattr(self.request.user, 'is_superuser', False)): raise Problem(_("You can not deactivate a superuser.")) if self.object.user == self.request.user: raise Problem(_("You can not deactivate yourself.")) self.object.is_active = state self.object.save(update_fields=("is_active",)) messages.success(self.request, _("%(contact)s is now %(state)s.") % { "contact": self.object, "state": _("active") if state else _("inactive") }) if (self.object.is_active and self.object.is_active != old_state and isinstance(self.object, CompanyContact)): company_contact_activated.send(sender=type(self.object), instance=self.object, request=self.request) return HttpResponseRedirect(self.request.path)