Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSPOE-132 add index column for disclaimer and general_information #1753

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dev/database/fed/disclaimer.json.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"content": {<xsl:for-each select="ili:Inhalt/ili:LocalisationCH_V1.MultilingualMText/ili:LocalisedText/ili:LocalisationCH_V1.LocalisedMText">
"<xsl:value-of select="ili:Language"/>": "<xsl:value-of select="ili:Text"/>"<xsl:if test="not(position() = last())">,</xsl:if>
</xsl:for-each>
}
},
"extract_index": <xsl:choose><xsl:when test="ili:AuszugIndex"><xsl:value-of select="ili:AuszugIndex"/></xsl:when><xsl:otherwise><xsl:value-of select="position()"/></xsl:otherwise></xsl:choose>
}<xsl:if test="not(position() = last())">,</xsl:if>
</xsl:for-each>
]
Expand Down
3 changes: 2 additions & 1 deletion dev/database/fed/general_information.json.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"content": {<xsl:for-each select="ili:Inhalt/ili:LocalisationCH_V1.MultilingualMText/ili:LocalisedText/ili:LocalisationCH_V1.LocalisedMText">
"<xsl:value-of select="ili:Language"/>": "<xsl:value-of select="ili:Text"/>"<xsl:if test="not(position() = last())">,</xsl:if>
</xsl:for-each>
}
},
"extract_index": <xsl:choose><xsl:when test="ili:AuszugIndex"><xsl:value-of select="ili:AuszugIndex"/></xsl:when><xsl:otherwise><xsl:value-of select="position()"/></xsl:otherwise></xsl:choose>
}<xsl:if test="not(position() = last())">,</xsl:if>
</xsl:for-each>
]
Expand Down
6 changes: 4 additions & 2 deletions dev/sample_data/ch.disclaimer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"it": "Oltre alle informazioni contenute nel presente estratto, le restrizioni della proprietà possono essere annotate anche nel registro fondiario.",
"rm": "Supplementarmain a las indicaziuns en quest extract pon restricziuns da la proprietad er esser remartgadas en il register funsil.",
"en": "In addition to the information contained in this extract, ownership restrictions may also be cited in the land register."
}
},
"extract_index": 10
},
{
"title": {
Expand All @@ -28,7 +29,8 @@
"fr": "Le cadastre des sites pollués (CSP) est établi d'après les critères émis par l'Office fédéral de l'environnement OFEV. Il est mis à jour continuellement sur la base des nouvelles connaissances (investigations). Les surfaces des sites indiqués dans le cadastre des sites pollués peuvent ne pas correspondre à la surface effectivement polluée. Cela ne signifie pas que tout terrain non inscrit au cadastre ne soit pas pollué et qu'il soit libre de tout déchet et pollution. Les zones utilisées à des fins de transports publics, militaire et aéronautique sont de la responsabilité de la Confédération.",
"it": "Il catasto dei siti inquinati (CSIN) è stato elaborato sulla base dei criteri definiti dall'Ufficio federale dell'ambiente (UFAM) e viene continuamente aggiornato sulla base delle nuove conoscenze ottenute (p.es. in seguito a indagini). Le superfici riportate nel CSIN possono discostarsi dalla portata dell'inquinamento effettivo. Se un fondo non figura nel CSIN, non esiste alcuna garanzia assoluta che l'area sia libera da inquinamento dovuto a rifiuti o sostanze nocive. I siti sfruttati per finalità ferroviarie, militari o relative all'aviazione civile rientrano nella sfera di competenze della Confederazione.",
"rm": "Il cataster dals lieus contaminads (CLC) è vegnì fatg tenor ils criteris fixads da l'Uffizi federal d'ambient UFAM e vegn actualisà permanentamain sin basa da novas enconuschientschas (p.ex. retschertgas). Las surfatschas inscrittas en il CLC pon divergiar da la dimensiun effectiva da la contaminaziun. Sch'in bain immobigliar n'è betg inditgà en il CLC, na datti nagina garanzia absoluta che l'areal saja liber da mintga contaminaziun che deriva da rument u da substanzas nuschaivlas. Lieus duvrads per il manaschi da la viafier, per il militar e per l'aviatica tutgan tar il champ da cumpetenza da la Confederaziun."
}
},
"extract_index": 20
}
]

3 changes: 2 additions & 1 deletion dev/sample_data/ch.general_information.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"fr": "Le contenu du cadastre RDPPF est supposé connu. Le canton de ${canton} n'engage pas sa responsabilité sur l'exactitude ou la fiabilité des documents législatifs dans leur version électronique. L'extrait a un caractère informatif et ne crée aucun droit ou obligation. La primauté va aux documents qui ont été légalement adoptés ou publiés. Vous trouverez d'autres informations sur le cadastre RDPPF sous www.cadastre.ch",
"it": "Il contenuto del Catasto RDPP si considera noto. Il Canton ${canton} non può essere ritenuto responsabile per la precisione e l'affidabilità dei documenti legislativi in formato elettronico. L'estratto ha carattere puramente informativo e non è in particolare costitutivo di diritti e obblighi. Sono considerati determinante i documenti approvati o pubblicati passati in giudicato. Ulteriori informazioni relative al Catasto RDPP sono disponibili su www.cadastre.ch",
"rm": "Il cuntegn dal cataster RDPP vegn premess sco enconuschent. Il chantun ${canton} n'è betg responsabel per l'exactadad e per la fidadadad dals documents legislativs electronics. L'extract ha in caracter puramain infurmativ e na motivescha cunzunt nagins dretgs e naginas obligaziuns. Giuridicamain liants èn quels documents ch'èn vegnids deliberads u publitgads cun vigur legala. Ulteriuras infurmaziuns davart il cataster RDPP chattais Vus sut www.cadastre.ch"
}
},
"extract_index": 0
}
]

4 changes: 4 additions & 0 deletions pyramid_oereb/contrib/data_sources/standard/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ class Disclaimer(Base):
id (str): identifier and primary key, used in the database only
title (str): The title which the disclaimer item has.
content (str): The content which the disclaimer item has.
extract_index (int): index to sort the disclaimers in the extract
"""
__table_args__ = {'schema': app_schema_name}
__tablename__ = 'disclaimer'
id = Column(String, primary_key=True)
title = Column(JSONType, nullable=False)
content = Column(JSONType, nullable=False)
extract_index = Column(Integer, nullable=True)


class LawStatus(Base):
Expand Down Expand Up @@ -263,12 +265,14 @@ class GeneralInformation(Base):
id (str): identifier and primary key, used in the database only
title (dict): The title of the general information (multilingual)
content (dict): The actual information (multilingual)
extract_index (int): index to sort the items in the extract
"""
__table_args__ = {'schema': app_schema_name}
__tablename__ = 'general_information'
id = Column(String, primary_key=True)
title = Column(JSONType, nullable=False)
content = Column(JSONType, nullable=False)
extract_index = Column(Integer, nullable=True)


class ThemeDocument(Base):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def read(self):
for result in results:
self.records.append(self._record_class_(
result.title,
result.content
result.content,
result.extract_index
))
finally:
session.close()
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def read(self):
for result in results:
self.records.append(self._record_class_(
result.title,
result.content
result.content,
result.extract_index
))
finally:
session.close()
1 change: 1 addition & 0 deletions pyramid_oereb/core/readers/disclaimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ def read(self):
contains all records delivered by the source.
"""
self._source_.read()
self._source_.records.sort(key=lambda el: (getattr(el, 'extract_index') or 0))
return self._source_.records
1 change: 1 addition & 0 deletions pyramid_oereb/core/readers/general_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ def read(self):
contains all records delivered by the source.
"""
self._source_.read()
self._source_.records.sort(key=lambda el: (getattr(el, 'extract_index') or 0))
return self._source_.records
3 changes: 2 additions & 1 deletion pyramid_oereb/core/records/disclaimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DisclaimerRecord(object):
title (dict of unicode): The multilingual disclaimer message label
content (dict of unicode): The multilingual disclaimer message.
"""
def __init__(self, title, content):
def __init__(self, title, content, extract_index=None):
"""
Attributes:
title (dict of unicode): The multilingual disclaimer message label
Expand All @@ -23,3 +23,4 @@ def __init__(self, title, content):

self.title = title
self.content = content
self.extract_index = extract_index
7 changes: 4 additions & 3 deletions pyramid_oereb/core/records/general_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GeneralInformationRecord(object):
title (dict of unicode): The title of the information (multilingual)
content (dict of unicode): The actual information (multilingual)
"""
def __init__(self, title, content):
def __init__(self, title, content, extract_index=None):
"""
Args:
title (dict of unicode): The title of the information (multilingual)
Expand All @@ -26,7 +26,8 @@ def __init__(self, title, content):

self.title = title
self.content = content
self.extract_index = extract_index

def __str__(self):
return '<{} -- title: {} content: {}>'.format(
self.__class__.__name__, self.title, self.content)
return '<{} -- title: {} content: {} extract index: {}>'.format(
self.__class__.__name__, self.title, self.content, self.extract_index)
50 changes: 49 additions & 1 deletion tests/core/readers/test_disclaimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,45 @@ def disclaimer_data(dbsession, transact):
'it': u'Il catasto dei siti inquinati (CSIN) è stato elaborato sulla \
base dei criteri definiti dall ...',
'rm': u'',
}
},
'extract_index': 2,
})
]
dbsession.add_all(disclaimers)
dbsession.flush()
yield disclaimers


@pytest.fixture(params=[1, 3])
def multi_disclaimer_data(request, dbsession, transact, disclaimer_data):
from pyramid_oereb.contrib.data_sources.standard.models.main import Disclaimer
del transact
disclaimers = [
Disclaimer(**{
'id': 2,
'title': {
'de': u'Haftungsausschluss Kataster der belasteten Standorte V2',
'fr': u'Clause de non-responsabilité du cadastre des sites pollués (CSP) V2',
'it': u'Clausola di esclusione della responsabilità ... V2',
'rm': u''
},
'content': {
'de': u'Der Kataster der belasteten Standorte (KbS) \
wurde anhand der vom Bundesamt für Umwelt BAFU fe ...',
'fr': u'Le cadastre des sites pollués (CSP) est établi d’après \
les critères émis par l’Office fédéral ...',
'it': u'Il catasto dei siti inquinati (CSIN) è stato elaborato sulla \
base dei criteri definiti dall ...',
'rm': u'',
},
'extract_index': request.param,
})
]
dbsession.add_all(disclaimers)
dbsession.flush()
yield disclaimer_data + disclaimers


@pytest.mark.run(order=2)
def test_init(pyramid_oereb_test_config):
reader = DisclaimerReader(
Expand All @@ -58,3 +89,20 @@ def test_read(pyramid_oereb_test_config, disclaimer_data):
assert len(results[0].content) == len(disclaimer_data[0].content)
assert 'du cadastre des sites' in results[0].title['fr']
assert 'Kataster der belasteten Standorte' in results[0].content['de']


@pytest.mark.run(order=2)
def test_sort(pyramid_oereb_test_config, multi_disclaimer_data):
reader = DisclaimerReader(
pyramid_oereb_test_config.get_disclaimer_config().get('source').get('class'),
**pyramid_oereb_test_config.get_disclaimer_config().get('source').get('params')
)
results = reader.read()
assert isinstance(results, list)
assert len(results) == len(multi_disclaimer_data)
assert isinstance(results[0], DisclaimerRecord)
assert len(results[0].title) == len(multi_disclaimer_data[0].title)
assert len(results[0].content) == len(multi_disclaimer_data[0].content)
assert 'du cadastre des sites' in results[0].title['fr']
assert 'Kataster der belasteten Standorte' in results[0].content['de']
assert sorted(r.extract_index for r in results) == [r.extract_index for r in results]
76 changes: 76 additions & 0 deletions tests/core/readers/test_general_information.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
import pytest

from pyramid_oereb.core.sources import Base
from pyramid_oereb.core.readers.general_information import GeneralInformationReader
from pyramid_oereb.core.records.general_information import GeneralInformationRecord


@pytest.fixture
def general_information_data(dbsession, transact):
from pyramid_oereb.contrib.data_sources.standard.models.main import GeneralInformation
del transact
general_information = [
GeneralInformation(**{
'id': 1,
'title': {
'de': u'GI1',
},
'content': {
'de': u'General Information # 1',
'fr': u'Information Generale #1',
},
'extract_index': 2,
}),
GeneralInformation(**{
'id': 2,
'title': {
'de': u'GI2',
},
'content': {
'de': u'General Information # 2',
'fr': u'Information Generale #2',
},
'extract_index': 3,
}),
GeneralInformation(**{
'id': 3,
'title': {
'de': u'GI3',
},
'content': {
'de': u'General Information # 3',
'fr': u'Information Generale #3',
},
'extract_index': 1,
})
]
dbsession.add_all(general_information)
dbsession.flush()
yield general_information


@pytest.mark.run(order=2)
def test_init(pyramid_oereb_test_config):
reader = GeneralInformationReader(
pyramid_oereb_test_config.get_info_config().get('source').get('class'),
**pyramid_oereb_test_config.get_info_config().get('source').get('params')
)
assert isinstance(reader._source_, Base)


@pytest.mark.run(order=2)
def test_read(pyramid_oereb_test_config, general_information_data):
reader = GeneralInformationReader(
pyramid_oereb_test_config.get_info_config().get('source').get('class'),
**pyramid_oereb_test_config.get_info_config().get('source').get('params')
)
results = reader.read()
assert isinstance(results, list)
assert len(results) == len(general_information_data)
assert isinstance(results[0], GeneralInformationRecord)
assert len(results[0].title) == len(general_information_data[0].title)
assert len(results[0].content) == len(general_information_data[0].content)
assert 'GI3' == results[0].title['de']
assert 'Information Generale #1' == results[1].content['fr']
assert sorted(r.extract_index for r in results) == [r.extract_index for r in results]
Loading