diff --git a/compensation/models/compensation.py b/compensation/models/compensation.py index ea69cef..3deff50 100644 --- a/compensation/models/compensation.py +++ b/compensation/models/compensation.py @@ -418,6 +418,18 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin): super().set_status_messages(request) return request + @property + def is_recorded(self): + """ Getter for record status as property + + Since compensations inherit their record status from their intervention, the intervention's status is being + returned + + Returns: + + """ + return self.intervention.is_recorded + class CompensationDocument(AbstractDocument): """ diff --git a/compensation/views/compensation.py b/compensation/views/compensation.py index 4068e6b..9c82c88 100644 --- a/compensation/views/compensation.py +++ b/compensation/views/compensation.py @@ -22,7 +22,7 @@ from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DA CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, \ COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, \ DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, \ - DEADLINE_EDITED + DEADLINE_EDITED, RECORDED_BLOCKS_EDIT from konova.utils.user_checks import in_group @@ -69,6 +69,14 @@ def new_view(request: HttpRequest, intervention_id: str = None): """ template = "compensation/form/view.html" + intervention = get_object_or_404(Intervention, id=intervention_id) + if intervention.is_recorded: + messages.info( + request, + RECORDED_BLOCKS_EDIT + ) + return redirect("intervention:detail", id=intervention_id) + data_form = NewCompensationForm(request.POST or None, intervention_id=intervention_id) geom_form = SimpleGeomForm(request.POST or None, read_only=False) if request.method == "POST": @@ -134,6 +142,13 @@ def edit_view(request: HttpRequest, id: str): template = "compensation/form/view.html" # Get object from db comp = get_object_or_404(Compensation, id=id) + if comp.is_recorded: + messages.info( + request, + RECORDED_BLOCKS_EDIT + ) + return redirect("compensation:detail", id=id) + # Create forms, initialize with values from db/from POST request data_form = EditCompensationForm(request.POST or None, instance=comp) geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=comp) diff --git a/compensation/views/eco_account.py b/compensation/views/eco_account.py index 68a5536..ecaccbe 100644 --- a/compensation/views/eco_account.py +++ b/compensation/views/eco_account.py @@ -35,7 +35,8 @@ from konova.utils.generators import generate_qr_code from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \ CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, \ COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, \ - DEDUCTION_EDITED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED + DEDUCTION_EDITED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED, \ + RECORDED_BLOCKS_EDIT from konova.utils.user_checks import in_group @@ -145,6 +146,13 @@ def edit_view(request: HttpRequest, id: str): template = "compensation/form/view.html" # Get object from db acc = get_object_or_404(EcoAccount, id=id) + if acc.is_recorded: + messages.info( + request, + RECORDED_BLOCKS_EDIT + ) + return redirect("compensation:acc:detail", id=id) + # Create forms, initialize with values from db/from POST request data_form = EditEcoAccountForm(request.POST or None, instance=acc) geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=acc) diff --git a/ema/views.py b/ema/views.py index debd31d..ce0d68f 100644 --- a/ema/views.py +++ b/ema/views.py @@ -26,7 +26,7 @@ from konova.utils.generators import generate_qr_code from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \ DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, \ COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, \ - COMPENSATION_ACTION_EDITED, DEADLINE_EDITED + COMPENSATION_ACTION_EDITED, DEADLINE_EDITED, RECORDED_BLOCKS_EDIT from konova.utils.user_checks import in_group @@ -213,6 +213,13 @@ def edit_view(request: HttpRequest, id: str): template = "compensation/form/view.html" # Get object from db ema = get_object_or_404(Ema, id=id) + if ema.is_recorded: + messages.info( + request, + RECORDED_BLOCKS_EDIT + ) + return redirect("ema:detail", id=id) + # Create forms, initialize with values from db/from POST request data_form = EditEmaForm(request.POST or None, instance=ema) geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=ema) diff --git a/intervention/views.py b/intervention/views.py index b2b78ee..f882f21 100644 --- a/intervention/views.py +++ b/intervention/views.py @@ -18,7 +18,8 @@ from konova.utils.documents import remove_document, get_document from konova.utils.generators import generate_qr_code from konova.utils.message_templates import INTERVENTION_INVALID, FORM_INVALID, IDENTIFIER_REPLACED, \ CHECKED_RECORDED_RESET, DEDUCTION_REMOVED, DEDUCTION_ADDED, REVOCATION_ADDED, REVOCATION_REMOVED, \ - COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, DEDUCTION_EDITED, REVOCATION_EDITED, DOCUMENT_EDITED + COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, DEDUCTION_EDITED, REVOCATION_EDITED, DOCUMENT_EDITED, \ + RECORDED_BLOCKS_EDIT from konova.utils.user_checks import in_group @@ -302,6 +303,13 @@ def edit_view(request: HttpRequest, id: str): template = "intervention/form/view.html" # Get object from db intervention = get_object_or_404(Intervention, id=id) + if intervention.is_recorded: + messages.info( + request, + RECORDED_BLOCKS_EDIT + ) + return redirect("intervention:detail", id=id) + # Create forms, initialize with values from db/from POST request data_form = EditInterventionForm(request.POST or None, instance=intervention) geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=intervention) diff --git a/konova/forms.py b/konova/forms.py index fd359cb..cde3129 100644 --- a/konova/forms.py +++ b/konova/forms.py @@ -57,6 +57,8 @@ class BaseForm(forms.Form): self.has_required_fields = True break + self.check_for_recorded_instance() + @abstractmethod def save(self): # To be implemented in subclasses! @@ -136,6 +138,22 @@ class BaseForm(forms.Form): set_class = set_class.replace(cls, "") self.fields[field].widget.attrs["class"] = set_class + def check_for_recorded_instance(self): + """ Checks if the instance is recorded and runs some special logic if yes + + If the instance is recorded, the form shall not display any possibility to + edit any data. Instead, the users should get some information about why they can not edit anything + + Returns: + + """ + if self.instance is None or not isinstance(self.instance, BaseObject): + # Do nothing + return + + if self.instance.is_recorded: + self.template = "form/recorded_no_edit.html" + class RemoveForm(BaseForm): check = forms.BooleanField( @@ -410,7 +428,6 @@ class NewDocumentModalForm(BaseModalForm): super().__init__(*args, **kwargs) self.form_title = _("Add new document") self.form_caption = _("") - self.template = "modal/modal_form.html" self.form_attrs = { "enctype": "multipart/form-data", # important for file upload } @@ -597,4 +614,12 @@ class RecordModalForm(BaseModalForm): self.instance.set_unrecorded(self.user) else: self.instance.set_recorded(self.user) - return self.instance \ No newline at end of file + return self.instance + + def check_for_recorded_instance(self): + """ Overwrite the check method for doing nothing on the RecordModalForm + + Returns: + + """ + pass diff --git a/konova/models/object.py b/konova/models/object.py index 59c6886..a1cff71 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -337,6 +337,15 @@ class RecordableObjectMixin(models.Model): """ raise NotImplementedError("Implement this in the subclass!") + @property + def is_recorded(self): + """ Getter for record status as property + + Returns: + + """ + return self.recorded is not None + class CheckableObjectMixin(models.Model): # Checks - Refers to "Genehmigen" but optional diff --git a/konova/utils/message_templates.py b/konova/utils/message_templates.py index 64b7eab..e062005 100644 --- a/konova/utils/message_templates.py +++ b/konova/utils/message_templates.py @@ -17,6 +17,7 @@ IDENTIFIER_REPLACED = _("The identifier '{}' had to be changed to '{}' since ano ENTRY_REMOVE_MISSING_PERMISSION = _("Only conservation or registration office users are allowed to remove entries.") MISSING_GROUP_PERMISSION = _("You need to be part of another user group.") CHECKED_RECORDED_RESET = _("Status of Checked and Recorded reseted") +RECORDED_BLOCKS_EDIT = _("Entry is recorded. To edit data, the entry first needs to be unrecorded.") # SHARE DATA_UNSHARED = _("This data is not shared with you") diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index 68305e7..b8d66ac 100644 Binary files a/locale/de/LC_MESSAGES/django.mo and b/locale/de/LC_MESSAGES/django.mo differ diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index 08aed93..0ec797a 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -18,15 +18,15 @@ #: konova/filters/mixins.py:277 konova/filters/mixins.py:323 #: konova/filters/mixins.py:361 konova/filters/mixins.py:362 #: konova/filters/mixins.py:393 konova/filters/mixins.py:394 -#: konova/forms.py:143 konova/forms.py:244 konova/forms.py:315 -#: konova/forms.py:359 konova/forms.py:369 konova/forms.py:382 -#: konova/forms.py:394 konova/forms.py:412 user/forms.py:42 +#: konova/forms.py:163 konova/forms.py:264 konova/forms.py:335 +#: konova/forms.py:379 konova/forms.py:389 konova/forms.py:402 +#: konova/forms.py:414 konova/forms.py:432 user/forms.py:42 #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-04-13 15:13+0200\n" +"POT-Creation-Date: 2022-04-19 09:31+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -77,7 +77,7 @@ msgstr "Bericht generieren" msgid "Select a timespan and the desired conservation office" msgstr "Wählen Sie die Zeitspanne und die gewünschte Eintragungsstelle" -#: analysis/forms.py:69 konova/forms.py:191 +#: analysis/forms.py:69 konova/forms.py:211 msgid "Continue" msgstr "Weiter" @@ -342,7 +342,7 @@ msgstr "Automatisch generiert" #: intervention/templates/intervention/detail/includes/documents.html:28 #: intervention/templates/intervention/detail/view.html:31 #: intervention/templates/intervention/report/report.html:12 -#: konova/forms.py:358 +#: konova/forms.py:378 msgid "Title" msgstr "Bezeichnung" @@ -369,7 +369,7 @@ msgstr "Kompensation XY; Flur ABC" #: intervention/templates/intervention/detail/includes/documents.html:34 #: intervention/templates/intervention/detail/includes/payments.html:34 #: intervention/templates/intervention/detail/includes/revocation.html:38 -#: konova/forms.py:393 konova/templates/konova/includes/comment_card.html:16 +#: konova/forms.py:413 konova/templates/konova/includes/comment_card.html:16 msgid "Comment" msgstr "Kommentar" @@ -493,7 +493,7 @@ msgid "Due on which date" msgstr "Zahlung wird an diesem Datum erwartet" #: compensation/forms/modalForms.py:64 compensation/forms/modalForms.py:359 -#: intervention/forms/modalForms.py:177 konova/forms.py:395 +#: intervention/forms/modalForms.py:177 konova/forms.py:415 msgid "Additional comment, maximum {} letters" msgstr "Zusätzlicher Kommentar, maximal {} Zeichen" @@ -538,7 +538,7 @@ msgstr "Neuer Zustand" msgid "Insert data for the new state" msgstr "Geben Sie die Daten des neuen Zustandes ein" -#: compensation/forms/modalForms.py:217 konova/forms.py:193 +#: compensation/forms/modalForms.py:217 konova/forms.py:213 msgid "Object removed" msgstr "Objekt entfernt" @@ -871,7 +871,7 @@ msgstr "Dokumente" #: compensation/templates/compensation/detail/eco_account/includes/documents.html:14 #: ema/templates/ema/detail/includes/documents.html:14 #: intervention/templates/intervention/detail/includes/documents.html:14 -#: konova/forms.py:411 +#: konova/forms.py:431 msgid "Add new document" msgstr "Neues Dokument hinzufügen" @@ -879,7 +879,7 @@ msgstr "Neues Dokument hinzufügen" #: compensation/templates/compensation/detail/eco_account/includes/documents.html:31 #: ema/templates/ema/detail/includes/documents.html:31 #: intervention/templates/intervention/detail/includes/documents.html:31 -#: konova/forms.py:368 +#: konova/forms.py:388 msgid "Created on" msgstr "Erstellt" @@ -887,7 +887,7 @@ msgstr "Erstellt" #: compensation/templates/compensation/detail/eco_account/includes/documents.html:61 #: ema/templates/ema/detail/includes/documents.html:61 #: intervention/templates/intervention/detail/includes/documents.html:65 -#: konova/forms.py:474 +#: konova/forms.py:493 msgid "Edit document" msgstr "Dokument bearbeiten" @@ -1149,17 +1149,17 @@ msgstr "Kompensationen - Übersicht" msgid "Compensation {} edited" msgstr "Kompensation {} bearbeitet" -#: compensation/views/compensation.py:161 compensation/views/eco_account.py:165 +#: compensation/views/compensation.py:161 compensation/views/eco_account.py:172 #: ema/views.py:233 intervention/views.py:327 msgid "Edit {}" msgstr "Bearbeite {}" -#: compensation/views/compensation.py:240 compensation/views/eco_account.py:351 +#: compensation/views/compensation.py:240 compensation/views/eco_account.py:358 #: ema/views.py:194 intervention/views.py:531 msgid "Log" msgstr "Log" -#: compensation/views/compensation.py:584 compensation/views/eco_account.py:719 +#: compensation/views/compensation.py:584 compensation/views/eco_account.py:726 #: ema/views.py:551 intervention/views.py:677 msgid "Report {}" msgstr "Bericht {}" @@ -1172,40 +1172,46 @@ msgstr "Ökokonten - Übersicht" msgid "Eco-Account {} added" msgstr "Ökokonto {} hinzugefügt" -#: compensation/views/eco_account.py:155 +#: compensation/views/eco_account.py:151 +msgid "" +"Entry is recorded. To edit data, the entry first needs to be unrecorded." +msgstr "" +"Eintrag ist verzeichnet. Um Daten zu bearbeiten, muss der Eintrag erst entzeichnet werden." + +#: compensation/views/eco_account.py:162 msgid "Eco-Account {} edited" msgstr "Ökokonto {} bearbeitet" -#: compensation/views/eco_account.py:268 +#: compensation/views/eco_account.py:275 msgid "Eco-account removed" msgstr "Ökokonto entfernt" -#: compensation/views/eco_account.py:372 ema/views.py:275 +#: compensation/views/eco_account.py:379 ema/views.py:275 #: intervention/views.py:630 msgid "{} unrecorded" msgstr "{} entzeichnet" -#: compensation/views/eco_account.py:372 ema/views.py:275 +#: compensation/views/eco_account.py:379 ema/views.py:275 #: intervention/views.py:630 msgid "{} recorded" msgstr "{} verzeichnet" -#: compensation/views/eco_account.py:796 ema/views.py:621 +#: compensation/views/eco_account.py:803 ema/views.py:621 #: intervention/views.py:428 msgid "{} has already been shared with you" msgstr "{} wurde bereits für Sie freigegeben" -#: compensation/views/eco_account.py:801 ema/views.py:626 +#: compensation/views/eco_account.py:808 ema/views.py:626 #: intervention/views.py:433 msgid "{} has been shared with you" msgstr "{} ist nun für Sie freigegeben" -#: compensation/views/eco_account.py:808 ema/views.py:633 +#: compensation/views/eco_account.py:815 ema/views.py:633 #: intervention/views.py:440 msgid "Share link invalid" msgstr "Freigabelink ungültig" -#: compensation/views/eco_account.py:831 ema/views.py:656 +#: compensation/views/eco_account.py:838 ema/views.py:656 #: intervention/views.py:463 msgid "Share settings updated" msgstr "Freigabe Einstellungen aktualisiert" @@ -1392,7 +1398,7 @@ msgstr "Kompensationen und Zahlungen geprüft" msgid "Run check" msgstr "Prüfung vornehmen" -#: intervention/forms/modalForms.py:264 konova/forms.py:515 +#: intervention/forms/modalForms.py:264 konova/forms.py:534 msgid "" "I, {} {}, confirm that all necessary control steps have been performed by " "myself." @@ -1633,65 +1639,65 @@ msgstr "Nch Eintragungsstelle suchen" msgid "Save" msgstr "Speichern" -#: konova/forms.py:71 +#: konova/forms.py:74 msgid "Not editable" msgstr "Nicht editierbar" -#: konova/forms.py:142 konova/forms.py:314 +#: konova/forms.py:162 konova/forms.py:334 msgid "Confirm" msgstr "Bestätige" -#: konova/forms.py:154 konova/forms.py:323 +#: konova/forms.py:174 konova/forms.py:343 msgid "Remove" msgstr "Löschen" -#: konova/forms.py:156 +#: konova/forms.py:176 msgid "You are about to remove {} {}" msgstr "Sie sind dabei {} {} zu löschen" -#: konova/forms.py:243 konova/utils/quality.py:44 konova/utils/quality.py:46 +#: konova/forms.py:263 konova/utils/quality.py:44 konova/utils/quality.py:46 #: templates/form/collapsable/form.html:45 msgid "Geometry" msgstr "Geometrie" -#: konova/forms.py:324 +#: konova/forms.py:344 msgid "Are you sure?" msgstr "Sind Sie sicher?" -#: konova/forms.py:370 +#: konova/forms.py:390 msgid "When has this file been created? Important for photos." msgstr "Wann wurde diese Datei erstellt oder das Foto aufgenommen?" -#: konova/forms.py:381 +#: konova/forms.py:401 #: venv/lib/python3.7/site-packages/django/db/models/fields/files.py:231 msgid "File" msgstr "Datei" -#: konova/forms.py:383 +#: konova/forms.py:403 msgid "Allowed formats: pdf, jpg, png. Max size 15 MB." msgstr "Formate: pdf, jpg, png. Maximal 15 MB." -#: konova/forms.py:449 +#: konova/forms.py:468 msgid "Added document" msgstr "Dokument hinzugefügt" -#: konova/forms.py:506 +#: konova/forms.py:525 msgid "Confirm record" msgstr "Verzeichnen bestätigen" -#: konova/forms.py:514 +#: konova/forms.py:533 msgid "Record data" msgstr "Daten verzeichnen" -#: konova/forms.py:521 +#: konova/forms.py:540 msgid "Confirm unrecord" msgstr "Entzeichnen bestätigen" -#: konova/forms.py:522 +#: konova/forms.py:541 msgid "Unrecord data" msgstr "Daten entzeichnen" -#: konova/forms.py:523 +#: konova/forms.py:542 msgid "I, {} {}, confirm that this data must be unrecorded." msgstr "" "Ich, {} {}, bestätige, dass diese Daten wieder entzeichnet werden müssen." @@ -2358,6 +2364,25 @@ msgstr "Allgemeine Daten" msgid "Cancel" msgstr "Abbrechen" +#: templates/form/recorded_no_edit.html:9 +msgid "This data is recorded" +msgstr "Daten sind verzeichnet" + +#: templates/form/recorded_no_edit.html:14 +msgid "" +"\n" +" Whilst recorded the data is published publicly. If you wish to edit " +"any information on this data, the data needs\n" +" to be unrecorded first. Do not forget to record it afterwards, " +"again.\n" +" " +msgstr "" +"\n" +"Verzeichnete Daten sind öffentlich einsehbar. Wenn Sie Informationen " +"überarbeiten möchten muss dieser Datensatz zunächst entzeichnet werden. " +"Vergessen Sie nicht ihn anschließend wieder zu verzeichnen.\n" +" " + #: templates/form/table/generic_table_form_body.html:24 msgid "Fields with * are required." msgstr "* sind Pflichtfelder." @@ -2546,11 +2571,11 @@ msgstr "Administratoren verwalten die Teamdaten und Mitglieder" msgid "Selected admin ({}) needs to be a member of this team." msgstr "Gewählter Administrator ({}) muss ein Mitglied des Teams sein." -#: user/forms.py:291 user/templates/user/team/index.html:51 +#: user/forms.py:291 user/templates/user/team/index.html:54 msgid "Edit team" msgstr "Team bearbeiten" -#: user/forms.py:323 user/templates/user/team/index.html:58 +#: user/forms.py:323 user/templates/user/team/index.html:50 msgid "Leave team" msgstr "Team verlassen" @@ -2640,7 +2665,7 @@ msgstr "Neues Team hinzufügen" msgid "Members" msgstr "Mitglieder" -#: user/templates/user/team/index.html:54 +#: user/templates/user/team/index.html:57 msgid "Remove team" msgstr "Team entfernen" diff --git a/templates/form/recorded_no_edit.html b/templates/form/recorded_no_edit.html new file mode 100644 index 0000000..45fd08d --- /dev/null +++ b/templates/form/recorded_no_edit.html @@ -0,0 +1,19 @@ +{% load i18n fontawesome_5 %} + +
+

+ + {% fa5_icon 'bookmark' %} + + + {% trans 'This data is recorded' %} + +

+
+
+ {% blocktrans %} + Whilst recorded the data is published publicly. If you wish to edit any information on this data, the data needs + to be unrecorded first. Do not forget to record it afterwards, again. + {% endblocktrans %} +
+
\ No newline at end of file