Skip to content

Commit

Permalink
Merge pull request #389 from rldhont/server-for-third-party
Browse files Browse the repository at this point in the history
Server - Support du relevé parcellaire pour un tiers et réduction de la fiche HTML
  • Loading branch information
rldhont committed Nov 25, 2022
2 parents 6998739 + 37a18a8 commit afdcc66
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Server - Ajout de la carte au relevé parcellaire
* Server - Support du relevé parcellaire pour un tiers et réduction de la fiche HTML

## 1.16.1 - 2022-10-19

Expand Down
7 changes: 5 additions & 2 deletions cadastre/cadastre_common_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def getProprietaireComptesCommunaux(comptecommunal: str, connectionParams: Dict[


def getItemHtml(item: str, feature, connectionParams: Dict[str, str],
connector: 'DBConnector') -> str:
connector: 'DBConnector', for_third_party: bool = False) -> str:
"""
Build Html for a item (parcelle, proprietaires, etc.)
based on SQL query
Expand Down Expand Up @@ -433,7 +433,10 @@ def getItemHtml(item: str, feature, connectionParams: Dict[str, str],

sqlfile = 'templates/parcelle_info_%s.sql' % item
with open(os.path.join(plugin_dir, sqlfile), encoding='utf8') as sqltemplate:
sql = sqltemplate.read() % feature['geo_parcelle']
if item == 'proprietaires':
sql = sqltemplate.read().format(parcelle_id=feature['geo_parcelle'], not_for_third_part=(not for_third_party))
else:
sql = sqltemplate.read() % feature['geo_parcelle']
if not sql:
html += 'Impossible de lire le SQL dans le fichier %s' % sqlfile
return html
Expand Down
10 changes: 7 additions & 3 deletions cadastre/server/cadastre_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def create_pdf(self, params: Dict[str, str], response: QgsServerResponse, projec
# Export PDF
qex = CadastreExport(project, res.layer, res.type, compte_communal, res.geo_parcelle)
qex.print_parcelle_page = True
qex.for_third_party = params.get('ADVANCED', 'f').lower() not in ('t', 'true', '1')
paths = qex.export_as_pdf()

if not paths:
Expand Down Expand Up @@ -227,21 +228,24 @@ def create_pdf(self, params: Dict[str, str], response: QgsServerResponse, projec
def get_html(self, params: Dict[str, str], response: QgsServerResponse, project: QgsProject) -> None:
# Load ressources based on passed params
res = self.get_ressources(params, project)
for_third_party = params.get('ADVANCED', 'f').lower() not in ('t', 'true', '1')

def get_item_html(n):
return cadastre_common.getItemHtml(
n,
res.feature,
res.connectionParams,
res.connector
res.connector,
for_third_party
)

html = ''
html += get_item_html('parcelle_majic')
html += get_item_html('proprietaires')
html += get_item_html('subdivisions')
html += get_item_html('locaux')
html += get_item_html('locaux_detail')
if not for_third_party:
html += get_item_html('locaux')
html += get_item_html('locaux_detail')

write_json_response({
'status': 'success',
Expand Down
10 changes: 5 additions & 5 deletions cadastre/templates/parcelle_info_proprietaires.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ SELECT
'<th>Code</th>' ||
'<th>Nom</th>' ||
'<th>Adresse</th>' ||
'<th>Date de naissance</th>' ||
'<th>Lieux de naissance</th>' ||
CASE WHEN {not_for_third_part} THEN '<th>Date de naissance</th>' ELSE '' END ||
CASE WHEN {not_for_third_part} THEN '<th>Lieux de naissance</th>' ELSE '' END ||
'<th>Code droit</th>' ||
'<th>Code démembrement</th>' ||
'</tr>' ||
Expand All @@ -26,8 +26,8 @@ FROM (
trim(coalesce(p.ddenom, '')) ||
'</td>' ||
'<td>' || ltrim(trim(coalesce(p.dlign4, '')), '0') || trim(coalesce(p.dlign5, '')) || ' ' || trim(coalesce(p.dlign6, '')) || '</td>' ||
'<td>' || Coalesce( trim(cast(p.jdatnss AS text) ), '-') || '</td>' ||
'<td>' || coalesce(trim(p.dldnss), '-') || '</td>' ||
CASE WHEN {not_for_third_part} THEN '<td>' || Coalesce( trim(cast(p.jdatnss AS text) ), '-') || '</td>' ELSE '' END ||
CASE WHEN {not_for_third_part} THEN '<td>' || coalesce(trim(p.dldnss), '-') || '</td>' ELSE '' END ||
'<td>' || Coalesce(ccodro_lib, '') || '</td>' ||
'<td>' || Coalesce(ccodem_lib, '') || '</td>' ||
'</tr>'
Expand All @@ -37,7 +37,7 @@ FROM (
LEFT JOIN ccodem ON ccodem.ccodem = p.ccodem
WHERE 2>1
AND comptecommunal = (
SELECT comptecommunal FROM parcelle WHERE parcelle = '%s'
SELECT comptecommunal FROM parcelle WHERE parcelle = '{parcelle_id}'
)
ORDER BY p.dnulp
) foo

0 comments on commit afdcc66

Please sign in to comment.