Skip to content

Commit

Permalink
App Datenmanagement: Adressreferenzen bei invalidem Formular beibehal…
Browse files Browse the repository at this point in the history
…ten (bis dato wurden diese immer entfernt); Bereinigungsarbeiten im Code
  • Loading branch information
gdmhrogut committed Sep 21, 2023
1 parent 8b286e6 commit 523331e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 23 deletions.
65 changes: 59 additions & 6 deletions datenmanagement/models/models_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5821,8 +5821,7 @@ class Bemas_Altdaten_Verursacher(Basemodel):
default=0
)
bearbeitet = BooleanField(
' bearbeitet?',
default=True
' bearbeitet?'
)
reason_sector = BooleanField(
'Mangel in altem BEMAS: Branche fehlte'
Expand Down Expand Up @@ -5956,8 +5955,7 @@ class Bemas_Altdaten_Beschwerden(Basemodel):
default=0
)
bearbeitet = BooleanField(
' bearbeitet?',
default=True
' bearbeitet?'
)
reason_date_of_receipt = BooleanField(
'Mangel in altem BEMAS: Eingangsdatum fehlte'
Expand Down Expand Up @@ -6020,8 +6018,8 @@ class BasemodelMeta(SimpleModel.BasemodelMeta):
description = 'BEMAS-Altdaten: Beschwerden'
readonly_fields = [
'id', 'reason_date_of_receipt', 'reason_type_of_immission', 'reason_originator_id',
'reason_immission_point', 'source_beschwerdefuehrer_strasse', 'source_beschwerdefuehrer_plz',
'source_beschwerdefuehrer_ort', 'source_immissionsart'
'reason_immission_point', 'target_originator_id', 'source_beschwerdefuehrer_strasse',
'source_beschwerdefuehrer_plz', 'source_beschwerdefuehrer_ort', 'source_immissionsart'
]
address_type = 'Adresse'
address_mandatory = False
Expand Down Expand Up @@ -6049,3 +6047,58 @@ class BasemodelMeta(SimpleModel.BasemodelMeta):

def __str__(self):
return str(self.id)


BEMAS_ALTDATEN_JOURNALEREIGNISSE_TARGET_TYPE_OF_EVENT = (
('Besprechung', 'Besprechung'),
('Ortsbegehung', 'Ortsbegehung'),
('Prognose/Messung', 'Prognose/Messung'),
('Schriftverkehr', 'Schriftverkehr'),
('Telefonat', 'Telefonat')
)


class Bemas_Altdaten_Journalereignisse(Basemodel):
id = PositiveIntegerField(
' aus altem BEMAS: ID',
default=0
)
bearbeitet = BooleanField(
' bearbeitet?'
)
target_created_at = DateTimeField(
' für neues BEMAS: Zeitstempel'
)
target_complaint_id = PositiveIntegerField(
' aus altem BEMAS/für neues BEMAS: Beschwerde'
)
target_type_of_event = CharField(
' für neues BEMAS: Ereignisart',
choices=BEMAS_ALTDATEN_JOURNALEREIGNISSE_TARGET_TYPE_OF_EVENT
)
target_description = TextField(
' für neues BEMAS: Beschreibung',
validators=standard_validators
)

class Meta(Basemodel.Meta):
db_table = 'fachdaten\".\"bemas_altdaten_journalereignisse'
verbose_name = 'BEMAS-Altdaten: Journalereignis'
verbose_name_plural = 'BEMAS-Altdaten: Journalereignisse'

class BasemodelMeta(SimpleModel.BasemodelMeta):
description = 'BEMAS-Altdaten: Journalereignisse'
readonly_fields = ['id']
list_fields = {
'id': 'ID',
'bearbeitet': 'bearbeitet?',
'target_created_at': 'Zeitstempel',
'target_complaint_id': 'Beschwerde',
'target_type_of_event': 'Ereignisart',
'target_description': 'Beschreibung'
}
list_fields_with_datetime = ['target_created_at']
list_fields_with_number = ['id', 'target_complaint_id']

def __str__(self):
return str(self.id)
4 changes: 2 additions & 2 deletions datenmanagement/templates/datenmanagement/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ <h5 class="alert-heading">assoziierte Datensätze</h5>
inputField.prop('disabled', true);
} else {
inputField.parent().append('<span id="' + inputField.attr('id') + '" title="nicht editierbar – automatisch vergeben"><em>' + wert + '</em></span>');
let label = inputField.parent().closest('tr').find('label');
label.wrapInner('<em></em>');
inputField.hide();
}
let label = inputField.parent().closest('tr').find('label');
label.wrapInner('<em></em>');
}
{% else %}
inputField.closest('tr').hide();
Expand Down
17 changes: 17 additions & 0 deletions datenmanagement/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ def get_current_year():
return int(date.today().year)


def get_field_name_for_address_type(model, l10n=True):
"""
returns name of address related field depending on address reference type of passed model
:param model: model
:param l10n: localized name version?
:return: name of address related field depending on address reference type of passed model
"""
if model.BasemodelMeta.address_type == 'Adresse':
return 'adresse' if l10n else 'address'
elif model.BasemodelMeta.address_type == 'Straße':
return 'strasse' if l10n else 'street'
elif model.BasemodelMeta.address_type == 'Gemeindeteil':
return 'gemeindeteil' if l10n else 'district'
return None


def get_path(url):
"""
returns path related to passed URL
Expand Down
33 changes: 20 additions & 13 deletions datenmanagement/views/views_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from re import sub
from time import time

from datenmanagement.utils import is_address_related_field, is_geometry_field
from datenmanagement.utils import get_field_name_for_address_type, is_address_related_field, \
is_geometry_field
from .fields import AddressUUIDField, QuarterUUIDField, StreetUUIDField
from .functions import assign_widgets, get_thumb_url, set_form_attributes, \
set_form_context_elements, set_model_related_context_elements
Expand Down Expand Up @@ -391,6 +392,8 @@ def form_invalid(self, form, **kwargs):
form.data[field.name] = None
# keep address reference (otherwise it would be lost on re-rendering)
elif is_address_related_field(field):
field_name_for_address_type = get_field_name_for_address_type(self.model, False)
context_data['current_' + field_name_for_address_type] = form.data.get(field.name, None)
address = form.data.get(field.name + '_temp', None)
form.data[field.name] = address
# keep geometry (otherwise it would be lost on re-rendering)
Expand Down Expand Up @@ -543,12 +546,13 @@ def get_context_data(self, **kwargs):
else:
context['geometry'] = None
if self.model.BasemodelMeta.address_type:
if self.model.BasemodelMeta.address_type == 'Adresse' and self.object.adresse:
context['current_address'] = self.object.adresse.pk
elif self.model.BasemodelMeta.address_type == 'Straße' and self.object.strasse:
context['current_street'] = self.object.strasse.pk
elif self.model.BasemodelMeta.address_type == 'Gemeindeteil' and self.object.gemeindeteil:
context['current_district'] = self.object.gemeindeteil.pk
field_name_for_address_type = get_field_name_for_address_type(self.model, False)
if field_name_for_address_type == 'adresse' and self.object.adresse:
context['current_' + field_name_for_address_type] = self.object.adresse.pk
elif field_name_for_address_type == 'strasse' and self.object.strasse:
context['current_' + field_name_for_address_type] = self.object.strasse.pk
elif field_name_for_address_type == 'gemeindeteil' and self.object.gemeindeteil:
context['current_' + field_name_for_address_type] = self.object.gemeindeteil.pk
# Dictionary für alle Array-Felder und deren Inhalte vorbereiten,
# die als Inhalt mehr als einen Wert umfassen
array_fields_values = {}
Expand Down Expand Up @@ -587,12 +591,13 @@ def get_initial(self):
if self.model.BasemodelMeta.address_type:
# Dictionary um entsprechenden initialen Feldwert
# für Adresse, Straße oder Gemeindeteil ergänzen
if self.model.BasemodelMeta.address_type == 'Adresse' and self.object.adresse:
curr_dict['adresse'] = self.object.adresse
elif self.model.BasemodelMeta.address_type == 'Straße' and self.object.strasse:
curr_dict['strasse'] = self.object.strasse
elif self.model.BasemodelMeta.address_type == 'Gemeindeteil' and self.object.gemeindeteil:
curr_dict['gemeindeteil'] = self.object.gemeindeteil
field_name_for_address_type = get_field_name_for_address_type(self.model)
if field_name_for_address_type == 'adresse' and self.object.adresse:
curr_dict[field_name_for_address_type] = self.object.adresse
elif field_name_for_address_type == 'strasse' and self.object.strasse:
curr_dict[field_name_for_address_type] = self.object.strasse
elif field_name_for_address_type == 'gemeindeteil' and self.object.gemeindeteil:
curr_dict[field_name_for_address_type] = self.object.gemeindeteil
for field in self.model._meta.get_fields():
# bei Array-Feld...
if field.__class__.__name__ == 'ArrayField':
Expand Down Expand Up @@ -640,6 +645,8 @@ def form_invalid(self, form, **kwargs):
form.data[field.name] = values
# keep address reference (otherwise it would be lost on re-rendering)
elif is_address_related_field(field):
field_name_for_address_type = get_field_name_for_address_type(self.model, False)
context_data['current_' + field_name_for_address_type] = form.data.get(field.name, None)
address = form.data.get(field.name + '_temp', None)
form.data[field.name] = address
# keep geometry (otherwise it would be lost on re-rendering)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"@eslint/create-config": "^0.4.6",
"@fortawesome/fontawesome-free": "^6.4.2",
"@geoman-io/leaflet-geoman-free": "^2.14.2",
"bootstrap": "^5.3.1",
"eslint": "^8.48.0",
"bootstrap": "^5.3.2",
"eslint": "^8.49.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-jinja2-processor": "^1.2.0",
"jquery": "^3.7.1",
Expand Down

0 comments on commit 523331e

Please sign in to comment.