Intervention model refactoring

* splits Intervention model into three main components
   * Intervention (main object)
   * LegalData (holds legal dates, laws, etc.)
   * ResponsibilityData (holds organizations and handler)
   * This way data can be extended more easily in the future
* refactors admin.py and usages in templates
* introduces UuidModel as a base class for BaseResource
pull/2/head
mipel 3 years ago
parent 5858a5fdf9
commit e327f03893

@ -1,17 +1,38 @@
from django.contrib import admin from django.contrib import admin
from intervention.models import Intervention from intervention.models import Intervention, ResponsibilityData, LegalData
class InterventionAdmin(admin.ModelAdmin): class InterventionAdmin(admin.ModelAdmin):
list_display = [ list_display = [
"id", "id",
"title", "title",
"process_type",
"handler",
"created_on", "created_on",
"deleted_on", "deleted_on",
] ]
class ResponsibilityAdmin(admin.ModelAdmin):
list_display = [
"id",
"registration_office",
"registration_file_number",
"conservation_office",
"conservation_file_number",
"handler",
]
class LegalAdmin(admin.ModelAdmin):
list_display = [
"id",
"process_type",
"law",
"registration_date",
"binding_date",
]
admin.site.register(Intervention, InterventionAdmin) admin.site.register(Intervention, InterventionAdmin)
admin.site.register(ResponsibilityData, ResponsibilityAdmin)
admin.site.register(LegalData, LegalAdmin)

@ -12,32 +12,60 @@ from django.utils import timezone
from django.utils.timezone import now from django.utils.timezone import now
from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE
from konova.models import BaseObject, Geometry from konova.models import BaseObject, Geometry, UuidModel
from konova.utils.generators import generate_random_string from konova.utils.generators import generate_random_string
from organisation.models import Organisation from organisation.models import Organisation
from user.models import UserActionLogEntry from user.models import UserActionLogEntry
class Intervention(BaseObject): class ResponsibilityData(UuidModel):
""" """
Interventions are e.g. construction sites where nature used to be. Holds intervention data about responsible organizations and their file numbers for this case
""" """
registration_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, related_name="+") registration_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, related_name="+")
registration_file_number = models.CharField(max_length=1000, blank=True, null=True) registration_file_number = models.CharField(max_length=1000, blank=True, null=True)
conservation_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, related_name="+") conservation_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, related_name="+")
conservation_file_number = models.CharField(max_length=1000, blank=True, null=True) conservation_file_number = models.CharField(max_length=1000, blank=True, null=True)
handler = models.CharField(max_length=500, null=True, blank=True, help_text="Refers to 'Eingriffsverursacher'")
process_type = models.CharField(max_length=500, null=True, blank=True)
law = models.CharField(max_length=500, null=True, blank=True)
handler = models.CharField(max_length=500, null=True, blank=True, help_text="Who is responsible for this intervention?")
geometry = models.ForeignKey(Geometry, null=True, blank=True, on_delete=models.SET_NULL)
documents = models.ManyToManyField("konova.Document", blank=True)
class LegalData(UuidModel):
"""
Holds intervention legal data such as important dates, laws or responsible handler
"""
# Refers to "zugelassen am" # Refers to "zugelassen am"
registration_date = models.DateField(null=True, blank=True) registration_date = models.DateField(null=True, blank=True, help_text="Refers to 'Zugelassen am'")
# Refers to "Bestandskraft am" # Refers to "Bestandskraft am"
binding_on = models.DateField(null=True, blank=True) binding_date = models.DateField(null=True, blank=True, help_text="Refers to 'Bestandskraft am'")
process_type = models.CharField(max_length=500, null=True, blank=True)
law = models.CharField(max_length=500, null=True, blank=True)
class Intervention(BaseObject):
"""
Interventions are e.g. construction sites where nature used to be.
"""
responsible = models.OneToOneField(
ResponsibilityData,
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name='+',
help_text="Holds data on responsible organizations ('Zulassungsbehörde', 'Eintragungsstelle')"
)
legal = models.OneToOneField(
LegalData,
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name='+',
help_text="Holds data on legal dates or law"
)
geometry = models.ForeignKey(Geometry, null=True, blank=True, on_delete=models.SET_NULL)
documents = models.ManyToManyField("konova.Document", blank=True)
# Checks - Refers to "Genehmigen" but optional # Checks - Refers to "Genehmigen" but optional
checked = models.OneToOneField( checked = models.OneToOneField(

@ -64,31 +64,31 @@
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Process type' %}</th> <th scope="row">{% trans 'Process type' %}</th>
<td class="align-middle">{{intervention.process_type|default_if_none:""}}</td> <td class="align-middle">{{intervention.legal.process_type|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Law' %}</th> <th scope="row">{% trans 'Law' %}</th>
<td class="align-middle">{{intervention.law|default_if_none:""}}</td> <td class="align-middle">{{intervention.legal.law|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Registration office' %}</th> <th scope="row">{% trans 'Registration office' %}</th>
<td class="align-middle">{{intervention.registration_office|default_if_none:""}}</td> <td class="align-middle">{{intervention.responsible.registration_office|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Registration office file number' %}</th> <th scope="row">{% trans 'Registration office file number' %}</th>
<td class="align-middle">{{intervention.registration_file_number|default_if_none:""}}</td> <td class="align-middle">{{intervention.responsible.registration_file_number|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Conservation office' %}</th> <th scope="row">{% trans 'Conservation office' %}</th>
<td class="align-middle">{{intervention.conservation_office|default_if_none:""}}</td> <td class="align-middle">{{intervention.responsible.conservation_office|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Conversation office file number' %}</th> <th scope="row">{% trans 'Conversation office file number' %}</th>
<td class="align-middle">{{intervention.conservation_file_number|default_if_none:""}}</td> <td class="align-middle">{{intervention.responsible.conservation_file_number|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Intervention handler' %}</th> <th scope="row">{% trans 'Intervention handler' %}</th>
<td class="align-middle">{{intervention.handler|default_if_none:""}}</td> <td class="align-middle">{{intervention.responsible.handler|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Checked' %}</th> <th scope="row">{% trans 'Checked' %}</th>
@ -98,7 +98,7 @@
{% fa5_icon 'star' 'far' %} {% fa5_icon 'star' 'far' %}
</span> </span>
{% else %} {% else %}
<span class="check-star"> <span class="check-star" title="{% trans 'Checked on '%} {{intervention.checked.timestamp}} {% trans 'by' %} {{intervention.checked.user}}">
{% fa5_icon 'star' %} {% fa5_icon 'star' %}
</span> </span>
{% endif %} {% endif %}
@ -112,7 +112,7 @@
{% fa5_icon 'bookmark' 'far' %} {% fa5_icon 'bookmark' 'far' %}
</span> </span>
{% else %} {% else %}
<span class="registered-bookmark"> <span class="registered-bookmark" title="{% trans 'Recorded on '%} {{intervention.recorded.timestamp}} {% trans 'by' %} {{intervention.recorded.user}}">
{% fa5_icon 'bookmark' %} {% fa5_icon 'bookmark' %}
</span> </span>
{% endif %} {% endif %}
@ -120,11 +120,11 @@
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Registration date' %}</th> <th scope="row">{% trans 'Registration date' %}</th>
<td class="align-middle">{{intervention.registration_date|default_if_none:""}}</td> <td class="align-middle">{{intervention.legal.registration_date|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Binding on' %}</th> <th scope="row">{% trans 'Binding on' %}</th>
<td class="align-middle">{{intervention.binding_on|default_if_none:""}}</td> <td class="align-middle">{{intervention.legal.binding_on|default_if_none:""}}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans 'Last modified' %}</th> <th scope="row">{% trans 'Last modified' %}</th>

@ -15,14 +15,23 @@ from django.db import models
from konova.settings import DEFAULT_SRID from konova.settings import DEFAULT_SRID
class BaseResource(models.Model): class UuidModel(models.Model):
""" """
A basic resource model, which defines attributes for every derived model Encapsules identifying via uuid
""" """
id = models.UUIDField( id = models.UUIDField(
primary_key=True, primary_key=True,
default=uuid.uuid4, default=uuid.uuid4,
) )
class Meta:
abstract = True
class BaseResource(UuidModel):
"""
A basic resource model, which defines attributes for every derived model
"""
created_on = models.DateTimeField(auto_now_add=True, null=True) created_on = models.DateTimeField(auto_now_add=True, null=True)
created_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL, related_name="+") created_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL, related_name="+")

@ -78,7 +78,7 @@ def home_view(request: HttpRequest):
next_version=None, next_version=None,
) )
user_comps = comps.filter( user_comps = comps.filter(
users__in=[user] intervention__users__in=[user]
) )
eco_accs = EcoAccount.objects.filter( eco_accs = EcoAccount.objects.filter(
deleted_on=None, deleted_on=None,

Loading…
Cancel
Save