diff --git a/compensation/models/compensation.py b/compensation/models/compensation.py index b68ad105..6ebed855 100644 --- a/compensation/models/compensation.py +++ b/compensation/models/compensation.py @@ -290,6 +290,16 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin): """ self.intervention.mark_as_edited(user, request, edit_comment) + def is_ready_for_publish(self) -> bool: + """ Not inherited by RecordableObjectMixin + + Simplifies same usage for compensations as for other datatypes + + Returns: + is_ready (bool): True|False + """ + return self.intervention.is_ready_for_publish() + class CompensationDocument(AbstractDocument): """ diff --git a/compensation/models/eco_account.py b/compensation/models/eco_account.py index 7d339b4d..84a61409 100644 --- a/compensation/models/eco_account.py +++ b/compensation/models/eco_account.py @@ -193,6 +193,16 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix ) return deduction + def is_ready_for_publish(self) -> bool: + """ Checks whether the data passes all constraints for being publishable + + Returns: + is_ready (bool) : True|False + """ + is_recorded = self.recorded is not None + is_ready = is_recorded + return is_ready + class EcoAccountDocument(AbstractDocument): """ diff --git a/compensation/views/compensation.py b/compensation/views/compensation.py index ab11a62a..323921e4 100644 --- a/compensation/views/compensation.py +++ b/compensation/views/compensation.py @@ -451,7 +451,7 @@ def report_view(request: HttpRequest, id: str): tab_title = _("Report {}").format(comp.identifier) # If intervention is not recorded (yet or currently) we need to render another template without any data - if not comp.intervention.recorded: + if not comp.is_ready_for_publish(): template = "report/unavailable.html" context = { TAB_TITLE_IDENTIFIER: tab_title, diff --git a/compensation/views/eco_account.py b/compensation/views/eco_account.py index 14caf9d3..5c061b96 100644 --- a/compensation/views/eco_account.py +++ b/compensation/views/eco_account.py @@ -553,7 +553,7 @@ def report_view(request:HttpRequest, id: str): tab_title = _("Report {}").format(acc.identifier) # If intervention is not recorded (yet or currently) we need to render another template without any data - if not acc.recorded: + if not acc.is_ready_for_publish(): template = "report/unavailable.html" context = { TAB_TITLE_IDENTIFIER: tab_title, diff --git a/ema/models/ema.py b/ema/models/ema.py index 2c61a241..f0c4d234 100644 --- a/ema/models/ema.py +++ b/ema/models/ema.py @@ -109,6 +109,16 @@ class Ema(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin): self.set_geometry_conflict_message(request) return request + def is_ready_for_publish(self) -> bool: + """ Checks whether the data passes all constraints for being publishable + + Returns: + is_ready (bool) : True|False + """ + is_recorded = self.recorded is not None + is_ready = is_recorded + return is_ready + class EmaDocument(AbstractDocument): """ diff --git a/ema/views.py b/ema/views.py index cc7bbc93..1e8b089c 100644 --- a/ema/views.py +++ b/ema/views.py @@ -464,7 +464,7 @@ def report_view(request:HttpRequest, id: str): tab_title = _("Report {}").format(ema.identifier) # If intervention is not recorded (yet or currently) we need to render another template without any data - if not ema.recorded: + if not ema.is_ready_for_publish(): template = "report/unavailable.html" context = { TAB_TITLE_IDENTIFIER: tab_title, diff --git a/intervention/models/intervention.py b/intervention/models/intervention.py index 6f721237..766346f5 100644 --- a/intervention/models/intervention.py +++ b/intervention/models/intervention.py @@ -8,6 +8,8 @@ Created on: 15.11.21 import shutil from django.contrib import messages +from django.utils import timezone + from user.models import User from django.db import models, transaction from django.db.models import QuerySet @@ -282,6 +284,22 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec request = self.set_geometry_conflict_message(request) return request + def is_ready_for_publish(self) -> bool: + """ Checks whether the data passes all constraints for being publishable + + Returns: + is_ready (bool) : True|False + """ + now_date = timezone.now().date() + binding_date = self.legal.binding_date + is_binding_date_ready = binding_date is not None and binding_date <= now_date + is_recorded = self.recorded is not None + is_free_of_revocations = not self.legal.revocations.exists() + is_ready = is_binding_date_ready \ + and is_recorded \ + and is_free_of_revocations + return is_ready + class InterventionDocument(AbstractDocument): """ diff --git a/intervention/views.py b/intervention/views.py index ad046155..50856dfb 100644 --- a/intervention/views.py +++ b/intervention/views.py @@ -545,7 +545,7 @@ def report_view(request:HttpRequest, id: str): tab_title = _("Report {}").format(intervention.identifier) # If intervention is not recorded (yet or currently) we need to render another template without any data - if not intervention.recorded: + if not intervention.is_ready_for_publish(): template = "report/unavailable.html" context = { TAB_TITLE_IDENTIFIER: tab_title, diff --git a/konova/models/object.py b/konova/models/object.py index 900542d8..0a83a487 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -283,6 +283,15 @@ class RecordableObjectMixin(models.Model): CHECKED_RECORDED_RESET ) + @abstractmethod + def is_ready_for_publish(self) -> bool: + """ Check for all needed publishing-constraints on the data + + Returns: + is_ready (bool): True|False + """ + raise NotImplementedError("Implement this in the subclass!") + class CheckableObjectMixin(models.Model): # Checks - Refers to "Genehmigen" but optional diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index 619b6ef4..a45c4548 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 46827b72..2d3d4093 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -2214,8 +2214,8 @@ msgid "" " " msgstr "" "\n" -" Die Daten, die Sie einsehen möchten, sind in Bearbeitung und " -"daher aktuell nicht öffentlich einsehbar. Schauen Sie zu einem späteren " +" Diese Daten sind noch nicht veröffentlicht und " +"können daher aktuell nicht eingesehen werden. Schauen Sie zu einem späteren " "Zeitpunkt wieder vorbei. \n" " "