Intervention revocation
* adds Revocation model to interventions/models.py * adds revocations to interventions detail view * fixes duplicated ids in html includes * refactors controls for detail view into included template files (controls.html) * reduces max length for payment transfer notes from 1000 to 200 * adds RevocationAdmin to intervention/admin.py * adds new form for adding a Revocation to an intervention's legal_data * only one revocation per intervention possible * removes add button in case of an existing revocation * adds revocation routes to intervention app * renames document field in Document model into file for more clarity * adds/updates translations
This commit is contained in:
+69
-1
@@ -14,7 +14,7 @@ from django.db import transaction
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from intervention.models import Intervention
|
||||
from intervention.models import Intervention, Revocation
|
||||
from konova.forms import BaseForm, BaseModalForm
|
||||
from konova.models import Document
|
||||
from konova.settings import DEFAULT_LAT, DEFAULT_LON, DEFAULT_ZOOM, ZB_GROUP, ETS_GROUP
|
||||
@@ -315,3 +315,71 @@ class ShareInterventionForm(BaseModalForm):
|
||||
id__in=self.cleaned_data["users"]
|
||||
)
|
||||
self.instance.users.set(accessing_users)
|
||||
|
||||
|
||||
class NewRevocationForm(BaseModalForm):
|
||||
date = forms.DateField(
|
||||
label=_("Date"),
|
||||
label_suffix=_(""),
|
||||
help_text=_("Date of revocation"),
|
||||
widget=forms.DateInput(
|
||||
attrs={
|
||||
"type": "date",
|
||||
"data-provide": "datepicker",
|
||||
},
|
||||
format="%d.%m.%Y"
|
||||
)
|
||||
)
|
||||
file = forms.FileField(
|
||||
label=_("Document"),
|
||||
label_suffix=_(""),
|
||||
help_text=_("Must be smaller than 15 Mb"),
|
||||
widget=forms.FileInput(
|
||||
attrs={
|
||||
"class": "w-75"
|
||||
}
|
||||
)
|
||||
)
|
||||
comment = forms.CharField(
|
||||
required=False,
|
||||
max_length=200,
|
||||
label=_("Comment"),
|
||||
label_suffix=_(""),
|
||||
help_text=_("Additional comment, maximum {} letters").format(200),
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
"cols": 30,
|
||||
"rows": 5,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("Add revocation")
|
||||
self.form_caption = ""
|
||||
self.form_attrs = {
|
||||
"enctype": "multipart/form-data", # important for file upload
|
||||
}
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
document = Document.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"],
|
||||
)
|
||||
revocation = Revocation.objects.create(
|
||||
date=self.cleaned_data["date"],
|
||||
comment=self.cleaned_data["comment"],
|
||||
document=document,
|
||||
created=user_action,
|
||||
)
|
||||
self.instance.legal.revocation = revocation
|
||||
self.instance.legal.save()
|
||||
return revocation
|
||||
|
||||
Reference in New Issue
Block a user