From c13e23e1c69f17855c0a29db933dcb72176fd454 Mon Sep 17 00:00:00 2001 From: Sebastian Gutzeit Date: Mon, 6 Nov 2023 09:46:01 +0100 Subject: [PATCH] App Datenmanagement: Bugfixes --- datenmanagement/models/models_simple.py | 4 ++-- datenmanagement/sql/schema.sql | 12 ++++++++++-- datenmanagement/tests/test_models_codelist.py | 6 ------ datenmanagement/tests/test_models_simple.py | 15 ++++++++------- datenmanagement/views/views_list_map.py | 5 +++++ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/datenmanagement/models/models_simple.py b/datenmanagement/models/models_simple.py index 94c1de70..ceb8e5aa 100644 --- a/datenmanagement/models/models_simple.py +++ b/datenmanagement/models/models_simple.py @@ -4,7 +4,7 @@ from django.contrib.postgres.fields import ArrayField from django.core.validators import EmailValidator, MaxValueValidator, MinValueValidator, \ RegexValidator, URLValidator -from django.db.models import CASCADE, RESTRICT, SET_NULL, ForeignKey +from django.db.models import CASCADE, RESTRICT, SET_NULL, ForeignKey, OneToOneField from django.db.models.fields import BooleanField, CharField, DateField, DateTimeField, \ DecimalField, PositiveIntegerField, TextField from django.db.models.fields.files import FileField, ImageField @@ -2942,7 +2942,7 @@ class Kehrbezirke(SimpleModel): Kehrbezirke """ - adresse = ForeignKey( + adresse = OneToOneField( Adressen, verbose_name='Adresse', on_delete=CASCADE, diff --git a/datenmanagement/sql/schema.sql b/datenmanagement/sql/schema.sql index 82d6049a..b0a5281a 100644 --- a/datenmanagement/sql/schema.sql +++ b/datenmanagement/sql/schema.sql @@ -700,8 +700,8 @@ CREATE TABLE codelisten.bevollmaechtigte_bezirksschornsteinfeger ( erstellt date DEFAULT (now())::date NOT NULL, auswaertig boolean NOT NULL, bezirk character(6), - bestellungszeitraum_beginn date NOT NULL, - bestellungszeitraum_ende date NOT NULL, + bestellungszeitraum_beginn date, + bestellungszeitraum_ende date, vorname character varying(255) NOT NULL, nachname character varying(255) NOT NULL, anschrift_strasse character varying(255) NOT NULL, @@ -5625,6 +5625,14 @@ ALTER TABLE ONLY fachdaten_adressbezug.hospize_hro ADD CONSTRAINT hospize_hro_pk PRIMARY KEY (uuid); +-- +-- Name: kehrbezirke_hro kehrbezirke_hro_adresse_unique; Type: CONSTRAINT; Schema: fachdaten_adressbezug; Owner: - +-- + +ALTER TABLE ONLY fachdaten_adressbezug.kehrbezirke_hro + ADD CONSTRAINT kehrbezirke_hro_adresse_unique UNIQUE (adresse); + + -- -- Name: kehrbezirke_hro kehrbezirke_hro_pk; Type: CONSTRAINT; Schema: fachdaten_adressbezug; Owner: - -- diff --git a/datenmanagement/tests/test_models_codelist.py b/datenmanagement/tests/test_models_codelist.py index 7b9d7ef1..dff28f6c 100644 --- a/datenmanagement/tests/test_models_codelist.py +++ b/datenmanagement/tests/test_models_codelist.py @@ -3868,8 +3868,6 @@ class BevollmaechtigteBezirksschornsteinfegerTest(DefaultCodelistTestCase): create_test_subset_in_classmethod = False attributes_values_db_initial = { 'auswaertig': False, - 'bestellungszeitraum_beginn': VALID_DATE, - 'bestellungszeitraum_ende': VALID_DATE, 'vorname': 'Vorname1', 'nachname': 'Nachname1', 'anschrift_strasse': 'Straße1', @@ -3882,8 +3880,6 @@ class BevollmaechtigteBezirksschornsteinfegerTest(DefaultCodelistTestCase): } attributes_values_view_initial = { 'auswaertig': False, - 'bestellungszeitraum_beginn': VALID_DATE, - 'bestellungszeitraum_ende': VALID_DATE, 'vorname': 'Vorname3', 'nachname': 'Nachname3', 'anschrift_strasse': 'Straße3', @@ -3893,8 +3889,6 @@ class BevollmaechtigteBezirksschornsteinfegerTest(DefaultCodelistTestCase): } attributes_values_view_updated = { 'auswaertig': False, - 'bestellungszeitraum_beginn': VALID_DATE, - 'bestellungszeitraum_ende': VALID_DATE, 'vorname': 'Vorname4', 'nachname': 'Nachname4', 'anschrift_strasse': 'Straße4', diff --git a/datenmanagement/tests/test_models_simple.py b/datenmanagement/tests/test_models_simple.py index b37e28f0..8587ad20 100644 --- a/datenmanagement/tests/test_models_simple.py +++ b/datenmanagement/tests/test_models_simple.py @@ -5909,14 +5909,15 @@ class KehrbezirkeTest(DefaultSimpleModelTestCase): @classmethod def setUpTestData(cls): super().setUpTestData() - adresse = Adressen.objects.create( - adresse='Adresse' + adresse1 = Adressen.objects.create( + adresse='Adresse1' + ) + adresse2 = Adressen.objects.create( + adresse='Adresse1' ) bevollmaechtigter_bezirksschornsteinfeger = ( Bevollmaechtigte_Bezirksschornsteinfeger.objects.create( auswaertig=False, - bestellungszeitraum_beginn=VALID_DATE, - bestellungszeitraum_ende=VALID_DATE, vorname='Vorname1', nachname='Nachname1', anschrift_strasse='Straße1', @@ -5926,7 +5927,7 @@ def setUpTestData(cls): ) ) cls.attributes_values_db_initial = { - 'adresse': adresse, + 'adresse': adresse1, 'bevollmaechtigter_bezirksschornsteinfeger': bevollmaechtigter_bezirksschornsteinfeger } cls.attributes_values_db_updated = { @@ -5934,13 +5935,13 @@ def setUpTestData(cls): } cls.attributes_values_view_initial = { 'aktiv': True, - 'adresse': str(adresse.pk), + 'adresse': str(adresse2.pk), 'bevollmaechtigter_bezirksschornsteinfeger': str( bevollmaechtigter_bezirksschornsteinfeger.pk) } cls.attributes_values_view_updated = { 'aktiv': True, - 'adresse': str(adresse.pk), + 'adresse': str(adresse2.pk), 'bevollmaechtigter_bezirksschornsteinfeger': str( bevollmaechtigter_bezirksschornsteinfeger.pk), 'vergabedatum': VALID_DATE diff --git a/datenmanagement/views/views_list_map.py b/datenmanagement/views/views_list_map.py index db30414b..ca447251 100644 --- a/datenmanagement/views/views_list_map.py +++ b/datenmanagement/views/views_list_map.py @@ -81,8 +81,10 @@ def prepare_results(self, qs): if value is not None: # format foreign keys if self.columns_with_foreign_key and column in self.columns_with_foreign_key: + # format foreign keys to addresses if column in {'adresse', 'strasse'}: data = getattr(getattr(item, column), self.columns_with_foreign_key.get(column)) + # format foreign keys as links elif ( self.fields_with_foreign_key_to_linkify and column in self.fields_with_foreign_key_to_linkify @@ -100,6 +102,9 @@ def prepare_results(self, qs): ) + '" target="_blank" rel="noopener noreferrer" class="required" title="'\ + foreign_model_title + ' ansehen oder bearbeiten">' + str( getattr(value, foreign_model_attribute_for_text)) + '' + # take all foreign key values as they are + else: + data = escape(value) # format numbers elif self.columns_with_number and column in self.columns_with_number: if isinstance(value, Decimal) or match(r"^[0-9]+\.[0-9]+$", str(value)):