Templates + Routes
* adds control button for Intervention, Compensation, Ema and EcoAccount for setting a resubmission on an entry
This commit is contained in:
@@ -7,7 +7,7 @@ Created on: 22.07.21
|
||||
"""
|
||||
from django.contrib import admin
|
||||
|
||||
from konova.models import Geometry, Deadline, GeometryConflict, Parcel, District, Municipal, ParcelGroup
|
||||
from konova.models import Geometry, Deadline, GeometryConflict, Parcel, District, Municipal, ParcelGroup, Resubmission
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
|
||||
from user.models import UserAction
|
||||
@@ -139,6 +139,15 @@ class BaseObjectAdmin(BaseResourceAdmin, DeletableObjectMixinAdmin):
|
||||
]
|
||||
|
||||
|
||||
class ResubmissionAdmin(BaseResourceAdmin):
|
||||
list_display = [
|
||||
"resubmit_on"
|
||||
]
|
||||
fields = [
|
||||
"comment",
|
||||
"resubmit_on"
|
||||
]
|
||||
|
||||
|
||||
# Outcommented for a cleaner admin backend on production
|
||||
#admin.site.register(Geometry, GeometryAdmin)
|
||||
@@ -148,3 +157,4 @@ class BaseObjectAdmin(BaseResourceAdmin, DeletableObjectMixinAdmin):
|
||||
#admin.site.register(ParcelGroup, ParcelGroupAdmin)
|
||||
#admin.site.register(GeometryConflict, GeometryConflictAdmin)
|
||||
#admin.site.register(Deadline, DeadlineAdmin)
|
||||
#admin.site.register(Resubmission, ResubmissionAdmin)
|
||||
|
||||
@@ -13,7 +13,9 @@ from bootstrap_modal_forms.utils import is_ajax
|
||||
from django import forms
|
||||
from django.contrib import messages
|
||||
from django.contrib.gis import gdal
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models.fields.files import FieldFile
|
||||
from django.utils.timezone import now
|
||||
|
||||
from compensation.models import EcoAccount
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
@@ -26,7 +28,7 @@ from django.shortcuts import render
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.contexts import BaseContext
|
||||
from konova.models import BaseObject, Geometry, RecordableObjectMixin, AbstractDocument
|
||||
from konova.models import BaseObject, Geometry, RecordableObjectMixin, AbstractDocument, Resubmission
|
||||
from konova.settings import DEFAULT_SRID
|
||||
from konova.tasks import celery_update_parcels
|
||||
from konova.utils.message_templates import FORM_INVALID, FILE_TYPE_UNSUPPORTED, FILE_SIZE_TOO_LARGE, DOCUMENT_EDITED
|
||||
@@ -161,6 +163,7 @@ class BaseForm(forms.Form):
|
||||
self,
|
||||
(
|
||||
NewDeductionModalForm,
|
||||
ResubmissionModalForm,
|
||||
EditEcoAccountDeductionModalForm,
|
||||
RemoveEcoAccountDeductionModalForm,
|
||||
)
|
||||
@@ -686,3 +689,72 @@ class RecordModalForm(BaseModalForm):
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ResubmissionModalForm(BaseModalForm):
|
||||
date = forms.DateField(
|
||||
label_suffix=_(""),
|
||||
label=_("Date"),
|
||||
help_text=_("When do you want to be reminded?"),
|
||||
widget=forms.DateInput(
|
||||
attrs={
|
||||
"type": "date",
|
||||
"data-provide": "datepicker",
|
||||
"class": "form-control",
|
||||
},
|
||||
format="%d.%m.%Y"
|
||||
)
|
||||
)
|
||||
comment = forms.CharField(
|
||||
required=False,
|
||||
label=_("Comment"),
|
||||
label_suffix=_(""),
|
||||
help_text=_("Additional comment"),
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
"cols": 30,
|
||||
"rows": 5,
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("Resubmission")
|
||||
self.form_caption = _("Set your resubmission for this entry.")
|
||||
self.action_url = None
|
||||
|
||||
try:
|
||||
self.resubmission = self.instance.resubmissions.get(
|
||||
user=self.user
|
||||
)
|
||||
self.initialize_form_field("date", str(self.resubmission.resubmit_on))
|
||||
self.initialize_form_field("comment", self.resubmission.comment)
|
||||
except ObjectDoesNotExist:
|
||||
self.resubmission = Resubmission()
|
||||
|
||||
def is_valid(self):
|
||||
super_valid = super().is_valid()
|
||||
self_valid = True
|
||||
|
||||
date = self.cleaned_data.get("date")
|
||||
today = now().today().date()
|
||||
if date <= today:
|
||||
self.add_error(
|
||||
"date",
|
||||
_("The date should be in the future")
|
||||
)
|
||||
self_valid = False
|
||||
|
||||
return super_valid and self_valid
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
self.resubmission.user = self.user
|
||||
self.resubmission.resubmit_on = self.cleaned_data.get("date")
|
||||
self.resubmission.comment = self.cleaned_data.get("comment")
|
||||
self.resubmission.save()
|
||||
self.instance.resubmissions.add(self.resubmission)
|
||||
return self.resubmission
|
||||
|
||||
|
||||
Reference in New Issue
Block a user