From dfc7230f3bb141c48a579cf95bccbe872d766337 Mon Sep 17 00:00:00 2001 From: Michael Douchin Date: Mon, 29 Aug 2022 18:47:53 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Export=20des=20relev=C3=A9s=20-=20Ajout=20d?= =?UTF-8?q?'une=20option=20"Les=20relev=C3=A9s=20sont=20destin=C3=A9s=20?= =?UTF-8?q?=C3=A0=20des=20tiers"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Une nouvelle case à cocher "Les relevés sont destinés à des tiers" est visible * dans le panneau de recherche * dans la popup d'identification de la parcelle Elle est activée par défaut et a pour conséquence de ne pas exporter les dates et lieux de naissance des propriétaires dans les relevés PDF. --- .gitignore | 3 + CHANGELOG.md | 2 + cadastre/cadastre_export.py | 17 ++++- cadastre/dialogs/cadastre_export_dialog.py | 4 +- cadastre/dialogs/parcelle_dialog.py | 8 +- cadastre/dialogs/search_dialog.py | 21 +++++- cadastre/forms/cadastre_parcelle_form.ui | 74 +++++++++++++------ cadastre/forms/cadastre_search_form.ui | 50 +++++++++---- cadastre/standalone/export.py | 14 +++- cadastre/templates/proprietaires_line.tpl.sql | 3 +- 10 files changed, 146 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index a1457fca..39b1799e 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ cadastre.*.zip # Temp files *~ *.bak + +# VSCode +*.code-workspace diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1fe53b..08f9848a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +* Export des relevés - Ajout d'une option "Les relevés sont destinés à des tiers" + qui permet de ne pas faire figurer la date et le lieu de naissance des propriétaires dans les PDF. ## 1.15.1 - 2022-08-12 diff --git a/cadastre/cadastre_export.py b/cadastre/cadastre_export.py index 8d2f932a..ac0a67fc 100644 --- a/cadastre/cadastre_export.py +++ b/cadastre/cadastre_export.py @@ -60,7 +60,7 @@ def _printProgress(self, nb: int) -> Generator[Callable[[int], None], None, None class CadastreExport: def __init__(self, project: QgsProject, layer: QgsMapLayer, etype: str, comptecommunal: str, - geo_parcelle: str = None, target_dir: str = None) -> None: + geo_parcelle: str = None, target_dir: str = None, for_third_party: bool = False) -> None: self.plugin_dir = str(Path(__file__).resolve().parent) @@ -81,6 +81,11 @@ def __init__(self, project: QgsProject, layer: QgsMapLayer, etype: str, compteco # type of export : proprietaire or parcelle self.etype = etype + # third party export + # If true, remove some sensitive fields + # For example date and location of birth + self.for_third_party = for_third_party + # id of the parcelle self.geo_parcelle = geo_parcelle @@ -292,6 +297,7 @@ def getContentForGivenItem(self, key, item, page=None): content = '' replaceDict = '' + # Build template file path tplPath = os.path.join( self.plugin_dir, @@ -315,6 +321,12 @@ def getContentForGivenItem(self, key, item, page=None): sql = sql.replace('$schema', '"{}".'.format(self.connectionParams['schema'])) else: sql = sql.replace('$schema', '') + + # Add the for_third_party values + # only useful for proprietaire + # to empty sensitive data (date and location of birth) + sql = sql.replace('$for_third_party', str(self.for_third_party)) + # Add where clause depending on etype sql = sql.replace('$and', item['and'][self.etype]) @@ -326,9 +338,10 @@ def getContentForGivenItem(self, key, item, page=None): # Get data from previous fetched full data data = self.lineCount[key]['data'][offset:self.maxLineNumber + offset] - # Run SQL + # Convert PostgreSQL syntax to SQLite if self.dbType == 'spatialite': sql = cadastre_common.postgisToSpatialite(sql) + # Run SQL only if data has not already been defined if data is None: # print(sql) diff --git a/cadastre/dialogs/cadastre_export_dialog.py b/cadastre/dialogs/cadastre_export_dialog.py index c8953cfb..5609a728 100644 --- a/cadastre/dialogs/cadastre_export_dialog.py +++ b/cadastre/dialogs/cadastre_export_dialog.py @@ -67,12 +67,12 @@ def printProgress(self, nb: int) -> Generator[Callable[[int], None], None, None] class CadastreExport(cadastreExportBase): def __init__(self, layer: QgsMapLayer, etype: str, comptecommunal: str, - geo_parcelle: str = None, target_dir: str = None) -> None: + geo_parcelle: str = None, target_dir: str = None, for_third_party: bool = False) -> None: self.mProgress = printProgress super().__init__(QgsProject.instance(), - layer, etype, comptecommunal, geo_parcelle, target_dir) + layer, etype, comptecommunal, geo_parcelle, target_dir, for_third_party) self.print_parcelle_page = True diff --git a/cadastre/dialogs/parcelle_dialog.py b/cadastre/dialogs/parcelle_dialog.py index 046e092a..017ffb1d 100644 --- a/cadastre/dialogs/parcelle_dialog.py +++ b/cadastre/dialogs/parcelle_dialog.py @@ -103,6 +103,7 @@ def __init__(self, iface, layer, feature, cadastre_search_dialog, parent=None): self.rejected.connect(self.onReject) self.buttonBox.rejected.connect(self.onReject) self.buttonBox.accepted.connect(self.onAccept) + # Export buttons exportButtons = { 'parcelle': self.btExportParcelle, @@ -416,6 +417,9 @@ def export_as_pdf(self, key): self.proprietairesInfo.setText(u'Pas de données de propriétaires dans la base') return + # Check if PDF must be exported for a third party or not + for_third_party = self.cbForThirdParty.isChecked() + if self.feature: comptecommunal = CadastreCommon.getCompteCommunalFromParcelleId( self.feature['geo_parcelle'], @@ -435,7 +439,9 @@ def export_as_pdf(self, key): self.layer, key, comptecommunal, - self.feature['geo_parcelle'] + self.feature['geo_parcelle'], + None, + for_third_party ) qe.export_as_pdf() diff --git a/cadastre/dialogs/search_dialog.py b/cadastre/dialogs/search_dialog.py index 6ccdf29b..dfefb129 100644 --- a/cadastre/dialogs/search_dialog.py +++ b/cadastre/dialogs/search_dialog.py @@ -1215,7 +1215,16 @@ def export_proprietaire(self): return layer = self.searchComboBoxes['proprietaire']['layer'] - qex = CadastreExport(QgsProject.instance(), layer, 'proprietaire', cc) + + # If export are for third-party persons + # we need to remove sensitive data + for_third_party = self.cbForThirdParty.isChecked() + + qex = CadastreExport( + QgsProject.instance(), layer, 'proprietaire', cc, + None, None, + for_third_party + ) with OverrideCursor(Qt.WaitCursor): exports = qex.export_as_pdf() @@ -1250,13 +1259,21 @@ def exportParcelle(self, key): self.qc.updateLog('Aucune parcelle sélectionnée !') return + # Get id of the owner compte_communal = CadastreCommon.getCompteCommunalFromParcelleId( feature['geo_parcelle'], self.connectionParams, self.connector ) + + # If export are for third-party persons + # we need to remove sensitive data + for_third_party = self.cbForThirdParty.isChecked() qex = CadastreExport( - QgsProject.instance(), layer, 'parcelle', compte_communal, feature['geo_parcelle']) + QgsProject.instance(), layer, 'parcelle', + compte_communal, feature['geo_parcelle'], + None, for_third_party + ) with OverrideCursor(Qt.WaitCursor): exports = qex.export_as_pdf() diff --git a/cadastre/forms/cadastre_parcelle_form.ui b/cadastre/forms/cadastre_parcelle_form.ui index ad2aab92..9fd5d752 100644 --- a/cadastre/forms/cadastre_parcelle_form.ui +++ b/cadastre/forms/cadastre_parcelle_form.ui @@ -120,65 +120,90 @@ - + - + - Relevé parcellaire + Centrer - - - - - + - Relevé de propriété + Zoomer - + - Exporter pour toutes les communes + Sélect. - + - + - Centrer + Sélectionner les parcelles du propriétaire + + + + + + + + + Export + + + + + + Lorsque cette case est cochée, les dates et lieux de naissance des propriétaires ne sont pas exportés dans les relevés PDF. + + + Les relevés sont destinés à des tiers + + + true + + + + + - + - Zoomer + Relevé parcellaire + + + + - + - Sélect. + Relevé de propriété - - - - - + + + Cocher cette case permet d'exporter le relevé de propriété pour toutes les communes. Cela peut être très long ! + - Sélectionner les parcelles du propriétaire + Exporter pour toutes les communes @@ -208,5 +233,6 @@ btSelectionner buttonBox + diff --git a/cadastre/forms/cadastre_search_form.ui b/cadastre/forms/cadastre_search_form.ui index f1d838db..6cec29ca 100644 --- a/cadastre/forms/cadastre_search_form.ui +++ b/cadastre/forms/cadastre_search_form.ui @@ -25,8 +25,8 @@ 0 0 - 382 - 586 + 436 + 573 @@ -229,7 +229,6 @@ - @@ -237,7 +236,6 @@ - @@ -248,7 +246,6 @@ - @@ -272,17 +269,16 @@ - - - - - Rechercher par nom de naissance - - - false - - - + + + + Rechercher par nom de naissance + + + false + + + @@ -398,6 +394,28 @@ + + + + Options + + + + + + Lorsque cette case est cochée, les dates et lieux de naissance des propriétaires ne sont pas exportés dans les relevés PDF. + + + Les relevés sont destinés à des tiers + + + true + + + + + + diff --git a/cadastre/standalone/export.py b/cadastre/standalone/export.py index 0ffb47e2..94b1f7c8 100644 --- a/cadastre/standalone/export.py +++ b/cadastre/standalone/export.py @@ -48,6 +48,11 @@ metavar='\"Export type\"', help='Usage: Override Export type' ) +parser.add_argument( + '-S', + metavar='\"For third-party\"', + help='Usage: Specify the export is for third-party and must be simplified: use true or false' +) parser.add_argument( '-O', metavar='\"Output log file\"', @@ -64,6 +69,8 @@ parcelle_id = '2018300189000EY0670' # -T = Export type ("proprietaire") export_type = 'parcelle' +# -S = For third party ("True") +for_third_party = False # -D = Target directory for PDF ("/tmp/") target_dir = '/tmp/' # -O = Output log file ("/tmp/export_cadastre.log") @@ -78,6 +85,10 @@ parcelle_id = sys.argv[sys.argv.index("-I") + 1] if "-T" in sys.argv: export_type = sys.argv[sys.argv.index("-T") + 1] +if "-S" in sys.argv: + _for_third_party = sys.argv[sys.argv.index("-S") + 1] + if _for_third_party.lower() == 'true': + for_third_party = True if "-D" in sys.argv: target_dir = sys.argv[sys.argv.index("-D") + 1] if "-O" in sys.argv: @@ -143,7 +154,8 @@ export_type, comptecommunal, feat['geo_parcelle'], - target_dir + target_dir, + for_third_party ) paths = qex.export_as_pdf() print(paths) diff --git a/cadastre/templates/proprietaires_line.tpl.sql b/cadastre/templates/proprietaires_line.tpl.sql index 8ea81db0..4358024c 100644 --- a/cadastre/templates/proprietaires_line.tpl.sql +++ b/cadastre/templates/proprietaires_line.tpl.sql @@ -3,7 +3,7 @@ SELECT Coalesce(ccodro_lib, '') || ' - ' || p.dnuper || ' - ' || trim(Coalesce(p CASE WHEN epxnee = 'NEE' THEN 'EP ' || trim(Coalesce(dnomlp, '')) || ' ' || trim(Coalesce(dprnlp, '')) ELSE '' END AS epousede, trim(Coalesce(p.dlign3, '')) || ' / ' || ltrim(trim(Coalesce(p.dlign4, '')), '0') || trim(Coalesce(p.dlign5, '')) || ' ' || trim(Coalesce(p.dlign6, '')) AS adrprop, CASE - WHEN jdatnss IS NOT NULL + WHEN jdatnss IS NOT NULL AND NOT $for_third_party THEN ' Né(e) le ' || jdatnss || ' à ' || coalesce(p.dldnss, '') ELSE '' END AS nele @@ -11,4 +11,3 @@ FROM $schema"proprietaire" p INNER JOIN $schema"ccodro" cc ON cc.ccodro = p.ccodro WHERE 2>1 $and - From d53150f781daf4dbb90b0247060ca53d1716b229 Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Tue, 30 Aug 2022 11:22:06 +0200 Subject: [PATCH 2/2] Python - Use camelcase convention for variables --- cadastre/dialogs/parcelle_dialog.py | 2 +- cadastre/dialogs/search_dialog.py | 4 ++-- cadastre/forms/cadastre_parcelle_form.ui | 2 +- cadastre/forms/cadastre_search_form.ui | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cadastre/dialogs/parcelle_dialog.py b/cadastre/dialogs/parcelle_dialog.py index 017ffb1d..fb1f3f7e 100644 --- a/cadastre/dialogs/parcelle_dialog.py +++ b/cadastre/dialogs/parcelle_dialog.py @@ -418,7 +418,7 @@ def export_as_pdf(self, key): return # Check if PDF must be exported for a third party or not - for_third_party = self.cbForThirdParty.isChecked() + for_third_party = self.combo_for_third_party.isChecked() if self.feature: comptecommunal = CadastreCommon.getCompteCommunalFromParcelleId( diff --git a/cadastre/dialogs/search_dialog.py b/cadastre/dialogs/search_dialog.py index dfefb129..d3619b3a 100644 --- a/cadastre/dialogs/search_dialog.py +++ b/cadastre/dialogs/search_dialog.py @@ -1218,7 +1218,7 @@ def export_proprietaire(self): # If export are for third-party persons # we need to remove sensitive data - for_third_party = self.cbForThirdParty.isChecked() + for_third_party = self.combo_for_third_party.isChecked() qex = CadastreExport( QgsProject.instance(), layer, 'proprietaire', cc, @@ -1268,7 +1268,7 @@ def exportParcelle(self, key): # If export are for third-party persons # we need to remove sensitive data - for_third_party = self.cbForThirdParty.isChecked() + for_third_party = self.combo_for_third_party.isChecked() qex = CadastreExport( QgsProject.instance(), layer, 'parcelle', compte_communal, feature['geo_parcelle'], diff --git a/cadastre/forms/cadastre_parcelle_form.ui b/cadastre/forms/cadastre_parcelle_form.ui index 9fd5d752..7fbbb72a 100644 --- a/cadastre/forms/cadastre_parcelle_form.ui +++ b/cadastre/forms/cadastre_parcelle_form.ui @@ -165,7 +165,7 @@ - + Lorsque cette case est cochée, les dates et lieux de naissance des propriétaires ne sont pas exportés dans les relevés PDF. diff --git a/cadastre/forms/cadastre_search_form.ui b/cadastre/forms/cadastre_search_form.ui index 6cec29ca..41342e7b 100644 --- a/cadastre/forms/cadastre_search_form.ui +++ b/cadastre/forms/cadastre_search_form.ui @@ -401,7 +401,7 @@ - + Lorsque cette case est cochée, les dates et lieux de naissance des propriétaires ne sont pas exportés dans les relevés PDF.