#39 Drop fundings

* removes fundings from all models, except the EMA model for migration compatibility (some old data may have fundings data)
This commit is contained in:
mpeltriaux 2021-11-15 09:59:01 +01:00
parent c1a251abc9
commit 8d7947bbda
8 changed files with 36 additions and 91 deletions

View File

@ -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)

View File

@ -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)

View File

@ -66,19 +66,6 @@
{% endif %}
</td>
</tr>
<tr>
<th scope="row">{% trans 'Funded by' %}</th>
<td class="align-middle">
{% for funding in obj.fundings.all %}
<div class="badge badge-pill rlp-r-outline">
{{ funding.short_name}}
</div>
<br>
{% empty %}
{% trans 'None' %}
{% endfor %}
</td>
</tr>
<tr>
<th scope="row">{% trans 'Last modified' %}</th>
<td class="align-middle">

View File

@ -69,19 +69,6 @@
<th scope="row">{% trans 'Action handler' %}</th>
<td class="align-middle">{{obj.responsible.handler|default_if_none:""}}</td>
</tr>
<tr>
<th scope="row">{% trans 'Funded by' %}</th>
<td class="align-middle">
{% for funding in obj.fundings.all %}
<div class="badge badge-pill rlp-r-outline">
{{ funding.short_name}}
</div>
<br>
{% empty %}
{% trans 'None' %}
{% endfor %}
</td>
</tr>
<tr>
<th scope="row">{% trans 'Last modified' %}</th>
<td class="align-middle">

View File

@ -20,19 +20,6 @@
</a>
</td>
</tr>
<tr>
<th scope="row">{% trans 'Funded by' %}</th>
<td class="align-middle">
{% with obj.fundings.all as fundings %}
{% for funding in fundings %}
<div class="badge pill-badge rlp-r-outline">{{funding.short_name}}</div>
<br>
{% empty %}
{% trans 'None' %}
{% endfor %}
{% endwith %}
</td>
</tr>
<tr>
<th scope="row">{% trans 'Last modified' %}</th>
<td class="align-middle">

View File

@ -24,19 +24,6 @@
<th scope="row">{% trans 'Action handler' %}</th>
<td class="align-middle">{{obj.responsible.handler|default_if_none:""}}</td>
</tr>
<tr>
<th scope="row">{% trans 'Funded by' %}</th>
<td class="align-middle">
{% with obj.fundings.all as fundings %}
{% for funding in fundings %}
<div class="badge pill-badge rlp-r-outline">{{funding.short_name}}</div>
<br>
{% empty %}
{% trans 'None' %}
{% endfor %}
{% endwith %}
</td>
</tr>
<tr>
<th scope="row">{% trans 'Deductions for' %}</th>
<td class="align-middle">

View File

@ -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",

View File

@ -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):