def apply_transition(self, *args, **kwargs): old_status = self.object.status result = super().apply_transition(*args, **kwargs) if self.object.status != old_status: Event.change_submission_status( author=self.request.user, submission=self.object, old_status=old_status ) return result
def apply_transition(self, request, *args, **kwargs): """ Applies a specific transition and redirects the user to the success URL. """ self.object = self.get_object() success_url = self.get_success_url() old_status = self.object.status # Applies the transition transition = getattr(self.object, self.transition_name) transition() self.object.save() # Records the event if self.object.status != old_status: Event.change_submission_status( author=self.request.user, submission=self.object, old_status=old_status ) return HttpResponseRedirect(success_url)
def form_valid(self, form): result = super().form_valid(form) Event.create_submission(author=self.request.user, submission=form.instance) return result