Skip to content

Commit

Permalink
Introduce qgis_print_layouts_tenant_subdir to support separate print …
Browse files Browse the repository at this point in the history
…layout template per tenant
  • Loading branch information
manisandro committed Oct 10, 2024
1 parent 98495fc commit b2559ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions schemas/qwc-config-generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
"description": "Directory containing print layouts. Example: /layouts",
"type": "string"
},
"qgis_print_layouts_tenant_subdir": {
"description": "Subdirectory path relative to qgis_print_layouts_dir. If specified, only layouts within this subdir will be processed. Useful to specify separate print layouts per tenant.",
"type": "string"
},
"qgis_projects_scan_base_dir": {
"description": "Path for QGIS projects, which should be automatically detected. Must be a subdir qgis_projects_base_dir. Example: /data/scan",
"type": "string"
Expand Down
24 changes: 19 additions & 5 deletions src/config_generator/config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,19 +742,33 @@ def search_qgs_projects(self, generator_config, themes_config):
def search_print_layouts(self, generator_config):
qgis_print_layouts_dir = generator_config.get(
'qgis_print_layouts_dir', '/layouts')

self.logger.info(
"<b>Searching for print layouts %s</b>" % qgis_print_layouts_dir)
qgis_print_layouts_tenant_subdir = generator_config.get(
'qgis_print_layouts_tenant_subdir', None)
subdirpath = None
if qgis_print_layouts_tenant_subdir:
subdirpath = os.path.join(
qgis_print_layouts_dir,
qgis_print_layouts_tenant_subdir.lstrip('/')
).rstrip('/')
self.logger.info(
"<b>Searching for print layouts in %s</b>" % subdirpath)
else:
self.logger.info(
"<b>Searching for print layouts in %s</b>" % qgis_print_layouts_dir)

print_layouts = {}
legend_layout_names = []
for dirpath, dirs, files in os.walk(qgis_print_layouts_dir,
followlinks=True):
if subdirpath and not dirpath.startswith(subdirpath):
continue
relpath = dirpath[len(qgis_print_layouts_dir.rstrip('/')) + 1:]

for filename in files:
if Path(filename).suffix != ".qpt":
continue

path = os.path.join(qgis_print_layouts_dir, dirpath, filename)
path = os.path.join(dirpath, filename)
with open(path, encoding='utf-8') as fh:
doc = ElementTree.parse(fh)

Expand All @@ -766,7 +780,7 @@ def search_print_layouts(self, generator_config):

size = composer_map.get('size').split(',')
print_template = OrderedDict()
print_template['name'] = layout.get('name')
print_template['name'] = os.path.join(relpath, layout.get('name'))
print_map = OrderedDict()
print_map['name'] = "map0"
print_map['width'] = float(size[0])
Expand Down

0 comments on commit b2559ef

Please sign in to comment.