From 8d7947bbda23a1c7f035bf81a05cc77b067f7dd9 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Mon, 15 Nov 2021 09:59:01 +0100 Subject: [PATCH 1/2] #39 Drop fundings * removes fundings from all models, except the EMA model for migration compatibility (some old data may have fundings data) --- compensation/forms/forms.py | 27 ------------------- compensation/models.py | 11 -------- .../detail/compensation/view.html | 13 --------- .../compensation/detail/eco_account/view.html | 13 --------- .../report/compensation/report.html | 13 --------- .../report/eco_account/report.html | 13 --------- ema/forms.py | 24 +++++++++++++++++ ema/models.py | 13 ++++++++- 8 files changed, 36 insertions(+), 91 deletions(-) diff --git a/compensation/forms/forms.py b/compensation/forms/forms.py index 1b9f050d..1903ed4a 100644 --- a/compensation/forms/forms.py +++ b/compensation/forms/forms.py @@ -51,23 +51,6 @@ class AbstractCompensationForm(BaseForm): } ) ) - fundings = forms.ModelMultipleChoiceField( - label=_("Fundings"), - label_suffix="", - required=False, - help_text=_("Select fundings for this compensation"), - queryset=KonovaCode.objects.filter( - is_archived=False, - is_leaf=True, - code_lists__in=[CODELIST_COMPENSATION_FUNDING_ID], - ), - widget=autocomplete.ModelSelect2Multiple( - url="codes-compensation-funding-autocomplete", - attrs={ - "data-placeholder": _("Click for selection"), - } - ), - ) comment = forms.CharField( label_suffix="", label=_("Comment"), @@ -194,7 +177,6 @@ class NewCompensationForm(AbstractCompensationForm): # Fetch data from cleaned POST values identifier = self.cleaned_data.get("identifier", None) title = self.cleaned_data.get("title", None) - fundings = self.cleaned_data.get("fundings", None) intervention = self.cleaned_data.get("intervention", None) comment = self.cleaned_data.get("comment", None) @@ -215,7 +197,6 @@ class NewCompensationForm(AbstractCompensationForm): geometry=geometry, comment=comment, ) - comp.fundings.set(fundings) # Add the log entry to the main objects log list comp.log.add(action) @@ -237,7 +218,6 @@ class EditCompensationForm(NewCompensationForm): "identifier": self.instance.identifier, "title": self.instance.title, "intervention": self.instance.intervention, - "fundings": self.instance.fundings.all(), "comment": self.instance.comment, } disabled_fields = [] @@ -251,7 +231,6 @@ class EditCompensationForm(NewCompensationForm): # Fetch data from cleaned POST values identifier = self.cleaned_data.get("identifier", None) title = self.cleaned_data.get("title", None) - fundings = self.cleaned_data.get("fundings", None) intervention = self.cleaned_data.get("intervention", None) comment = self.cleaned_data.get("comment", None) @@ -271,7 +250,6 @@ class EditCompensationForm(NewCompensationForm): self.instance.geometry = geometry self.instance.comment = comment self.instance.modified = action - self.instance.fundings.set(fundings) self.instance.save() self.instance.log.add(action) @@ -342,7 +320,6 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix # Fetch data from cleaned POST values identifier = self.cleaned_data.get("identifier", None) title = self.cleaned_data.get("title", None) - fundings = self.cleaned_data.get("fundings", None) registration_date = self.cleaned_data.get("registration_date", None) handler = self.cleaned_data.get("handler", None) surface = self.cleaned_data.get("surface", None) @@ -379,7 +356,6 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix comment=comment, legal=legal ) - acc.fundings.set(fundings) acc.share_with(user) # Add the log entry to the main objects log list @@ -411,7 +387,6 @@ class EditEcoAccountForm(NewEcoAccountForm): "registration_date": reg_date, "conservation_office": self.instance.responsible.conservation_office, "conservation_file_number": self.instance.responsible.conservation_file_number, - "fundings": self.instance.fundings.all(), "comment": self.instance.comment, } disabled_fields = [] @@ -425,7 +400,6 @@ class EditEcoAccountForm(NewEcoAccountForm): # Fetch data from cleaned POST values identifier = self.cleaned_data.get("identifier", None) title = self.cleaned_data.get("title", None) - fundings = self.cleaned_data.get("fundings", None) registration_date = self.cleaned_data.get("registration_date", None) handler = self.cleaned_data.get("handler", None) surface = self.cleaned_data.get("surface", None) @@ -459,7 +433,6 @@ class EditEcoAccountForm(NewEcoAccountForm): self.instance.comment = comment self.instance.modified = action self.instance.save() - self.instance.fundings.set(fundings) # Add the log entry to the main objects log list self.instance.log.add(action) diff --git a/compensation/models.py b/compensation/models.py index 672d4e02..0417cd20 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -146,17 +146,6 @@ class AbstractCompensation(BaseObject): after_states = models.ManyToManyField(CompensationState, blank=True, related_name='+', help_text="Refers to 'Zielzustand Biotop'") actions = models.ManyToManyField(CompensationAction, blank=True, help_text="Refers to 'Maßnahmen'") - fundings = models.ManyToManyField( - KonovaCode, - blank=True, - limit_choices_to={ - "code_lists__in": [CODELIST_COMPENSATION_FUNDING_ID], - "is_selectable": True, - "is_archived": False, - }, - help_text="List of funding project codes", - ) - deadlines = models.ManyToManyField("konova.Deadline", blank=True, related_name="+") geometry = models.ForeignKey(Geometry, null=True, blank=True, on_delete=models.SET_NULL) diff --git a/compensation/templates/compensation/detail/compensation/view.html b/compensation/templates/compensation/detail/compensation/view.html index 35d45046..2adcd02e 100644 --- a/compensation/templates/compensation/detail/compensation/view.html +++ b/compensation/templates/compensation/detail/compensation/view.html @@ -66,19 +66,6 @@ {% endif %} - - {% trans 'Funded by' %} - - {% for funding in obj.fundings.all %} -
- {{ funding.short_name}} -
-
- {% empty %} - {% trans 'None' %} - {% endfor %} - - {% trans 'Last modified' %} diff --git a/compensation/templates/compensation/detail/eco_account/view.html b/compensation/templates/compensation/detail/eco_account/view.html index 6f7eca99..717d6d53 100644 --- a/compensation/templates/compensation/detail/eco_account/view.html +++ b/compensation/templates/compensation/detail/eco_account/view.html @@ -69,19 +69,6 @@ {% trans 'Action handler' %} {{obj.responsible.handler|default_if_none:""}} - - {% trans 'Funded by' %} - - {% for funding in obj.fundings.all %} -
- {{ funding.short_name}} -
-
- {% empty %} - {% trans 'None' %} - {% endfor %} - - {% trans 'Last modified' %} diff --git a/compensation/templates/compensation/report/compensation/report.html b/compensation/templates/compensation/report/compensation/report.html index 956c0094..74d67a58 100644 --- a/compensation/templates/compensation/report/compensation/report.html +++ b/compensation/templates/compensation/report/compensation/report.html @@ -20,19 +20,6 @@ - - {% trans 'Funded by' %} - - {% with obj.fundings.all as fundings %} - {% for funding in fundings %} -
{{funding.short_name}}
-
- {% empty %} - {% trans 'None' %} - {% endfor %} - {% endwith %} - - {% trans 'Last modified' %} diff --git a/compensation/templates/compensation/report/eco_account/report.html b/compensation/templates/compensation/report/eco_account/report.html index bd633322..ff47772d 100644 --- a/compensation/templates/compensation/report/eco_account/report.html +++ b/compensation/templates/compensation/report/eco_account/report.html @@ -24,19 +24,6 @@ {% trans 'Action handler' %} {{obj.responsible.handler|default_if_none:""}} - - {% trans 'Funded by' %} - - {% with obj.fundings.all as fundings %} - {% for funding in fundings %} -
{{funding.short_name}}
-
- {% empty %} - {% trans 'None' %} - {% endfor %} - {% endwith %} - - {% trans 'Deductions for' %} diff --git a/ema/forms.py b/ema/forms.py index 44d186c6..27efafb2 100644 --- a/ema/forms.py +++ b/ema/forms.py @@ -5,10 +5,15 @@ Contact: michel.peltriaux@sgdnord.rlp.de Created on: 06.10.21 """ +from dal import autocomplete +from django import forms from django.contrib.auth.models import User from django.db import transaction from django.urls import reverse, reverse_lazy from django.utils.translation import gettext_lazy as _ + +from codelist.models import KonovaCode +from codelist.settings import CODELIST_COMPENSATION_FUNDING_ID from compensation.forms.forms import AbstractCompensationForm, CompensationResponsibleFormMixin from ema.models import Ema from intervention.models import ResponsibilityData @@ -23,6 +28,25 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin): Second holds self.instance.response related fields """ + + fundings = forms.ModelMultipleChoiceField( + label=_("Fundings"), + label_suffix="", + required=False, + help_text=_("Select fundings for this compensation"), + queryset=KonovaCode.objects.filter( + is_archived=False, + is_leaf=True, + code_lists__in=[CODELIST_COMPENSATION_FUNDING_ID], + ), + widget=autocomplete.ModelSelect2Multiple( + url="codes-compensation-funding-autocomplete", + attrs={ + "data-placeholder": _("Click for selection"), + } + ), + ) + field_order = [ "identifier", "title", diff --git a/ema/models.py b/ema/models.py index d37eca5d..7b19c6aa 100644 --- a/ema/models.py +++ b/ema/models.py @@ -1,9 +1,10 @@ import shutil -from django.contrib.auth.models import User from django.db import models from django.db.models import QuerySet +from codelist.models import KonovaCode +from codelist.settings import CODELIST_COMPENSATION_FUNDING_ID from compensation.models import AbstractCompensation from ema.managers import EmaManager from ema.utils.quality import EmaQualityChecker @@ -27,6 +28,16 @@ class Ema(AbstractCompensation, ShareableObject, RecordableObject): EMA therefore holds data like a compensation: actions, before-/after-states, deadlines, ... """ + fundings = models.ManyToManyField( + KonovaCode, + blank=True, + limit_choices_to={ + "code_lists__in": [CODELIST_COMPENSATION_FUNDING_ID], + "is_selectable": True, + "is_archived": False, + }, + help_text="List of funding project codes", + ) objects = EmaManager() def __str__(self): -- 2.45.2 From d72c29bd562b9c285e474dcf70d29091e91193b9 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Mon, 15 Nov 2021 10:55:15 +0100 Subject: [PATCH 2/2] #39 Drop fundings * removes fundings from all models --- .../management/commands/update_codelist.py | 3 +-- compensation/forms/forms.py | 4 +-- compensation/models.py | 3 +-- ema/forms.py | 27 ------------------- ema/models.py | 12 --------- ema/templates/ema/detail/view.html | 13 --------- ema/templates/ema/report/report.html | 13 --------- konova/autocompletes.py | 12 +-------- konova/tests/test_views.py | 3 --- konova/urls.py | 4 +-- 10 files changed, 5 insertions(+), 89 deletions(-) diff --git a/codelist/management/commands/update_codelist.py b/codelist/management/commands/update_codelist.py index 3807b29d..44b4b908 100644 --- a/codelist/management/commands/update_codelist.py +++ b/codelist/management/commands/update_codelist.py @@ -13,7 +13,7 @@ from codelist.models import KonovaCode, KonovaCodeList from codelist.settings import CODELIST_INTERVENTION_HANDLER_ID, CODELIST_CONSERVATION_OFFICE_ID, \ CODELIST_REGISTRATION_OFFICE_ID, CODELIST_BIOTOPES_ID, CODELIST_LAW_ID, CODELIST_COMPENSATION_HANDLER_ID, \ CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, \ - CODELIST_COMPENSATION_FUNDING_ID, CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID + CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID from konova.management.commands.setup import BaseKonovaCommand bool_map = { @@ -37,7 +37,6 @@ class Command(BaseKonovaCommand): CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, - CODELIST_COMPENSATION_FUNDING_ID, CODELIST_PROCESS_TYPE_ID, ] self._write_warning("Fetching codes...") diff --git a/compensation/forms/forms.py b/compensation/forms/forms.py index 1903ed4a..52575d32 100644 --- a/compensation/forms/forms.py +++ b/compensation/forms/forms.py @@ -13,7 +13,7 @@ from django.utils.translation import gettext_lazy as _ from django import forms from codelist.models import KonovaCode -from codelist.settings import CODELIST_COMPENSATION_FUNDING_ID, CODELIST_CONSERVATION_OFFICE_ID +from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID from compensation.models import Compensation, EcoAccount from intervention.inputs import GenerateInput from intervention.models import Intervention, ResponsibilityData, LegalData @@ -146,7 +146,6 @@ class NewCompensationForm(AbstractCompensationForm): "identifier", "title", "intervention", - "fundings", "comment", ] @@ -298,7 +297,6 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix "surface", "conservation_file_number", "handler", - "fundings", "comment", ] diff --git a/compensation/models.py b/compensation/models.py index 0417cd20..15aa30e6 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -15,8 +15,7 @@ from django.db.models import Sum, QuerySet from django.utils.translation import gettext_lazy as _ from codelist.models import KonovaCode -from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID, \ - CODELIST_COMPENSATION_FUNDING_ID +from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID from compensation.managers import CompensationStateManager, EcoAccountDeductionManager, CompensationActionManager, \ EcoAccountManager, CompensationManager from compensation.utils.quality import CompensationQualityChecker, EcoAccountQualityChecker diff --git a/ema/forms.py b/ema/forms.py index 27efafb2..85a9094b 100644 --- a/ema/forms.py +++ b/ema/forms.py @@ -12,8 +12,6 @@ from django.db import transaction from django.urls import reverse, reverse_lazy from django.utils.translation import gettext_lazy as _ -from codelist.models import KonovaCode -from codelist.settings import CODELIST_COMPENSATION_FUNDING_ID from compensation.forms.forms import AbstractCompensationForm, CompensationResponsibleFormMixin from ema.models import Ema from intervention.models import ResponsibilityData @@ -28,32 +26,12 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin): Second holds self.instance.response related fields """ - - fundings = forms.ModelMultipleChoiceField( - label=_("Fundings"), - label_suffix="", - required=False, - help_text=_("Select fundings for this compensation"), - queryset=KonovaCode.objects.filter( - is_archived=False, - is_leaf=True, - code_lists__in=[CODELIST_COMPENSATION_FUNDING_ID], - ), - widget=autocomplete.ModelSelect2Multiple( - url="codes-compensation-funding-autocomplete", - attrs={ - "data-placeholder": _("Click for selection"), - } - ), - ) - field_order = [ "identifier", "title", "conservation_office", "conservation_file_number", "handler", - "fundings", "comment", ] @@ -75,7 +53,6 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin): # Fetch data from cleaned POST values identifier = self.cleaned_data.get("identifier", None) title = self.cleaned_data.get("title", None) - fundings = self.cleaned_data.get("fundings", None) handler = self.cleaned_data.get("handler", None) conservation_office = self.cleaned_data.get("conservation_office", None) conservation_file_number = self.cleaned_data.get("conservation_file_number", None) @@ -104,7 +81,6 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin): geometry=geometry, comment=comment, ) - acc.fundings.set(fundings) # Add the creating user to the list of shared users acc.share_with(user) @@ -135,7 +111,6 @@ class EditEmaForm(NewEmaForm): "handler": self.instance.responsible.handler, "conservation_office": self.instance.responsible.conservation_office, "conservation_file_number": self.instance.responsible.conservation_file_number, - "fundings": self.instance.fundings.all(), "comment": self.instance.comment, } disabled_fields = [] @@ -149,7 +124,6 @@ class EditEmaForm(NewEmaForm): # Fetch data from cleaned POST values identifier = self.cleaned_data.get("identifier", None) title = self.cleaned_data.get("title", None) - fundings = self.cleaned_data.get("fundings", None) handler = self.cleaned_data.get("handler", None) conservation_office = self.cleaned_data.get("conservation_office", None) conservation_file_number = self.cleaned_data.get("conservation_file_number", None) @@ -176,7 +150,6 @@ class EditEmaForm(NewEmaForm): self.instance.comment = comment self.instance.modified = action self.instance.save() - self.instance.fundings.set(fundings) # Add the log entry to the main objects log list self.instance.log.add(action) diff --git a/ema/models.py b/ema/models.py index 7b19c6aa..b35cda32 100644 --- a/ema/models.py +++ b/ema/models.py @@ -3,8 +3,6 @@ import shutil from django.db import models from django.db.models import QuerySet -from codelist.models import KonovaCode -from codelist.settings import CODELIST_COMPENSATION_FUNDING_ID from compensation.models import AbstractCompensation from ema.managers import EmaManager from ema.utils.quality import EmaQualityChecker @@ -28,16 +26,6 @@ class Ema(AbstractCompensation, ShareableObject, RecordableObject): EMA therefore holds data like a compensation: actions, before-/after-states, deadlines, ... """ - fundings = models.ManyToManyField( - KonovaCode, - blank=True, - limit_choices_to={ - "code_lists__in": [CODELIST_COMPENSATION_FUNDING_ID], - "is_selectable": True, - "is_archived": False, - }, - help_text="List of funding project codes", - ) objects = EmaManager() def __str__(self): diff --git a/ema/templates/ema/detail/view.html b/ema/templates/ema/detail/view.html index 757ee64d..6635569a 100644 --- a/ema/templates/ema/detail/view.html +++ b/ema/templates/ema/detail/view.html @@ -50,19 +50,6 @@ {% trans 'Action handler' %} {{obj.responsible.handler|default_if_none:""}} - - {% trans 'Funded by' %} - - {% for funding in obj.fundings.all %} -
- {{ funding.short_name}} -
-
- {% empty %} - {% trans 'None' %} - {% endfor %} - - {% trans 'Last modified' %} diff --git a/ema/templates/ema/report/report.html b/ema/templates/ema/report/report.html index 2395e7ce..38dd7f23 100644 --- a/ema/templates/ema/report/report.html +++ b/ema/templates/ema/report/report.html @@ -24,19 +24,6 @@ {% trans 'Action handler' %} {{obj.responsible.handler|default_if_none:""}} - - {% trans 'Funded by' %} - - {% with obj.fundings.all as fundings %} - {% for funding in fundings %} -
{{funding.short_name}}
-
- {% empty %} - {% trans 'None' %} - {% endfor %} - {% endwith %} - - {% trans 'Last modified' %} diff --git a/konova/autocompletes.py b/konova/autocompletes.py index ca5ee2c6..36e585bd 100644 --- a/konova/autocompletes.py +++ b/konova/autocompletes.py @@ -10,8 +10,7 @@ from django.db.models import Q from codelist.models import KonovaCode from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID, CODELIST_LAW_ID, \ - CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, CODELIST_PROCESS_TYPE_ID, \ - CODELIST_COMPENSATION_FUNDING_ID + CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, CODELIST_PROCESS_TYPE_ID from compensation.models import EcoAccount from intervention.models import Intervention @@ -109,15 +108,6 @@ class CompensationActionCodeAutocomplete(KonovaCodeAutocomplete): super().__init__(*args, **kwargs) -class CompensationFundingCodeAutocomplete(KonovaCodeAutocomplete): - """ - Due to limitations of the django dal package, we need to subclass for each code list - """ - def __init__(self, *args, **kwargs): - self.c = CODELIST_COMPENSATION_FUNDING_ID - super().__init__(*args, **kwargs) - - class BiotopeCodeAutocomplete(KonovaCodeAutocomplete): """ Due to limitations of the django dal package, we need to subclass for each code list diff --git a/konova/tests/test_views.py b/konova/tests/test_views.py index b5712cd5..682a43f1 100644 --- a/konova/tests/test_views.py +++ b/konova/tests/test_views.py @@ -408,7 +408,6 @@ class AutocompleteTestCase(BaseViewTestCase): cls.atcmplt_accs = reverse("accounts-autocomplete") cls.atcmplt_interventions = reverse("interventions-autocomplete") cls.atcmplt_code_comp_action = reverse("codes-compensation-action-autocomplete") - cls.atcmplt_code_comp_funding = reverse("codes-compensation-funding-autocomplete") cls.atcmplt_code_comp_biotope = reverse("codes-biotope-autocomplete") cls.atcmplt_code_comp_law = reverse("codes-law-autocomplete") cls.atcmplt_code_comp_process = reverse("codes-process-type-autocomplete") @@ -426,7 +425,6 @@ class AutocompleteTestCase(BaseViewTestCase): self.atcmplt_accs, self.atcmplt_interventions, self.atcmplt_code_comp_action, - self.atcmplt_code_comp_funding, self.atcmplt_code_comp_biotope, self.atcmplt_code_comp_law, self.atcmplt_code_comp_process, @@ -444,7 +442,6 @@ class AutocompleteTestCase(BaseViewTestCase): self.atcmplt_accs, self.atcmplt_interventions, self.atcmplt_code_comp_action, - self.atcmplt_code_comp_funding, self.atcmplt_code_comp_biotope, self.atcmplt_code_comp_law, self.atcmplt_code_comp_process, diff --git a/konova/urls.py b/konova/urls.py index 1aebcbcc..820de41b 100644 --- a/konova/urls.py +++ b/konova/urls.py @@ -19,8 +19,7 @@ from django.urls import path, include from konova.autocompletes import EcoAccountAutocomplete, \ InterventionAutocomplete, CompensationActionCodeAutocomplete, BiotopeCodeAutocomplete, LawCodeAutocomplete, \ - RegistrationOfficeCodeAutocomplete, ConservationOfficeCodeAutocomplete, ProcessTypeCodeAutocomplete, \ - CompensationFundingCodeAutocomplete + RegistrationOfficeCodeAutocomplete, ConservationOfficeCodeAutocomplete, ProcessTypeCodeAutocomplete from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG from konova.sso.sso import KonovaSSOClient from konova.views import logout_view, home_view, remove_deadline_view @@ -46,7 +45,6 @@ urlpatterns = [ path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"), path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="interventions-autocomplete"), path("atcmplt/codes/comp/action", CompensationActionCodeAutocomplete.as_view(), name="codes-compensation-action-autocomplete"), - path("atcmplt/codes/comp/funding", CompensationFundingCodeAutocomplete.as_view(), name="codes-compensation-funding-autocomplete"), path("atcmplt/codes/biotope", BiotopeCodeAutocomplete.as_view(), name="codes-biotope-autocomplete"), path("atcmplt/codes/law", LawCodeAutocomplete.as_view(), name="codes-law-autocomplete"), path("atcmplt/codes/prc-type", ProcessTypeCodeAutocomplete.as_view(), name="codes-process-type-autocomplete"), -- 2.45.2