Skip to content

Commit

Permalink
add extract index into models, records, readers and sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
mki-c2c authored and michmuel committed Nov 27, 2023
1 parent 4a920ad commit 29b98ec
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 11 deletions.
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="element-available(ili:AuszugIndex) = 0"><xsl:value-of select="position()"/></xsl:when><xsl:otherwise><xsl:value-of select="ili:AuszugIndex"/></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="element-available(ili:AuszugIndex) = 0"><xsl:value-of select="position()"/></xsl:when><xsl:otherwise><xsl:value-of select="ili:AuszugIndex"/></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": 1
},
{
"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": 2
}
]

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": 1
}
]

11 changes: 11 additions & 0 deletions pyramid_oereb/contrib/data_sources/standard/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from pyramid_oereb.contrib.data_sources.standard.models import get_office, get_document
from sqlalchemy import Column, PrimaryKeyConstraint, ForeignKey, UniqueConstraint, DateTime
from sqlalchemy import Unicode, String, text, Integer, Boolean, Float
from sqlalchemy.types import UserDefinedType
from geoalchemy2 import Geometry
from sqlalchemy_utils import JSONType
from sqlalchemy.orm import declarative_base, relationship
Expand All @@ -38,6 +39,11 @@
srid = Config.get('srid')


class Serial(UserDefinedType):
def get_col_spec(self, **kw):
return "SERIAL"


class RealEstate(Base):
"""
The container where you can throw in all the real estates this application should have access to, for
Expand Down Expand Up @@ -219,12 +225,15 @@ 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(Serial)
extract_index = Column(Integer, nullable=True)


class LawStatus(Base):
Expand Down Expand Up @@ -263,12 +272,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)


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)

0 comments on commit 29b98ec

Please sign in to comment.