Refactoring
* moves adding of revocation into Intervention model
This commit is contained in:
@@ -176,33 +176,7 @@ class NewRevocationModalForm(BaseModalForm):
|
||||
}
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.EDITED
|
||||
)
|
||||
revocation = Revocation.objects.create(
|
||||
date=self.cleaned_data["date"],
|
||||
legal=self.instance.legal,
|
||||
comment=self.cleaned_data["comment"],
|
||||
created=created_action,
|
||||
)
|
||||
self.instance.modified = edited_action
|
||||
self.instance.save()
|
||||
self.instance.log.add(edited_action)
|
||||
|
||||
if self.cleaned_data["file"]:
|
||||
RevocationDocument.objects.create(
|
||||
title="revocation_of_{}".format(self.instance.identifier),
|
||||
date_of_creation=self.cleaned_data["date"],
|
||||
comment=self.cleaned_data["comment"],
|
||||
file=self.cleaned_data["file"],
|
||||
instance=revocation
|
||||
)
|
||||
revocation = self.instance.add_revocation(self)
|
||||
return revocation
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user