Skip to content

Commit

Permalink
flexible print configuration (#885)
Browse files Browse the repository at this point in the history
* add new parameter to script
* Pass SQLALCHEMY_URL and PRINT_BACKEND to create_standard_yaml
* set MapFishPrint as default (simplifies local testing)
* simplify doc
* alter docker.yaml to be more like pyramid_oereb yaml
* better handling of dependency to docker mako file
  • Loading branch information
jwkaltz authored Oct 30, 2019
1 parent 8d047e6 commit 236b589
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ __pycache__/
/test-db/12-create.sql
/test-db/13-fill.sql
/docker/logo_*.png
/docker/config.yaml
.pytest_cache
.idea
2 changes: 2 additions & 0 deletions CONST_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ vars:

sqlalchemy_url: '{SQLALCHEMY_URL}'
png_root_dir: '{PNG_ROOT_DIR}'
print_backend: '{PRINT_BACKEND}'

environment:
- SQLALCHEMY_URL
- PNG_ROOT_DIR
- PRINT_BACKEND
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ else
endif
export SQLALCHEMY_URL = "postgresql://$(PG_CREDENTIALS)@$(@_POSTGIS_IP):5432/pyramid_oereb_test"
export PNG_ROOT_DIR = pyramid_oereb/standard/
export PRINT_BACKEND = MapFishPrint # Set to XML2PDF if preferred

.coverage: $(PYTHON_VENV) $(TESTS_DROP_DB) $(TESTS_SETUP_DB) pyramid_oereb/standard/pyramid_oereb.yml .coveragerc $(shell find -name "*.py" -print | fgrep -v /.venv)
@echo Run tests using docker: $(USE_DOCKER)
Expand Down Expand Up @@ -141,7 +142,7 @@ clean-all:
rm -rf .venv
rm -rf $(BUILDDIR)
rm -rf coverage_report
rm -f pyramid_oereb_standard.yml pyramid_oereb/standard/pyramid_oereb.yml
rm -f pyramid_oereb_standard.yml pyramid_oereb/standard/pyramid_oereb.yml docker/config.yaml
rm -f test-db/12-create.sql test-db/13-fill.sql

.PHONY: create-default-models
Expand All @@ -163,11 +164,11 @@ drop-standard-tables: $(PYTHON_VENV)
$(VENV_BIN)drop_tables$(PYTHON_BIN_POSTFIX) -c pyramid_oereb.yml

.PHONY: serve
serve: pyramid_oereb_standard.yml test-db/12-create.sql test-db/13-fill.sql
serve: install pyramid_oereb_standard.yml docker/config.yaml test-db/12-create.sql test-db/13-fill.sql
docker-compose up --build --remove-orphans

pyramid_oereb_standard.yml: .venv/install-timestamp
$(VENV_BIN)create_standard_yaml$(PYTHON_BIN_POSTFIX)
$(VENV_BIN)create_standard_yaml$(PYTHON_BIN_POSTFIX) --database $(SQLALCHEMY_URL) --print_backend $(PRINT_BACKEND)

test-db/12-create.sql: pyramid_oereb_standard.yml .venv/install-timestamp
$(VENV_BIN)create_standard_tables$(PYTHON_BIN_POSTFIX) --configuration $< --sql-file $@
Expand All @@ -189,5 +190,5 @@ logo_%.png: pyramid_oereb_standard.yml
touch --no-create $@

.PHONY: build-docker
build-docker: logo_oereb.png logo_confederation.png logo_canton.png
build-docker: logo_oereb.png logo_confederation.png logo_canton.png docker/config.yaml
docker build --tag camptocamp/pyramid-oereb:latest .
29 changes: 5 additions & 24 deletions doc/source/contrib/print_proxy.rst.mako
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,8 @@ Print configuration

**XML2PDF**

To properly configure the print service of GISDATEN AG you need to add the following in your yaml file inside
the print section:

.. code-block:: yaml

print:
renderer: pyramid_oereb.contrib.print_proxy.xml_2_pdf.Renderer
# Base URL with application of the print server
base_url: https://oereb-dev.gis-daten.ch/oereb/report/create
token: 24ba4328-a306-4832-905d-b979388d4cab
use_wms: "true"
validate: "false"
# Do not stop on errors of https connection. WARNING: This leads to potential insecure connections
verify_certificate: false
# The buffer on the map around the parcel in percent
buffer: 10
# The map size in pixel at 72 DPI (width, height), This is the defined size of a map image
# (requested in wms urls) inside the static extract. On a pdf report, tha map size will
# be calculated with the pdf_dpi and the pdf_map_size_millimeters below.
basic_map_size: [493, 280]
# The dpi used to calculate the size of the requested map (for pdf export only).
pdf_dpi: 300
# The map size (in millimeters) used to calculate the size of the requested map (for pdf export only).
pdf_map_size_millimeters: [174, 99]
To properly configure the XML2PDF print service of GISDATEN AG, you need specific configuration in the section
``print`` of your ``yaml`` file.
Please see the `standard configuration file
<https://github.com/openoereb/pyramid_oereb/blob/master/pyramid_oereb/standard/pyramid_oereb.yml.mako>`__
as an example, or use the ``create_standard_yaml`` script to regenerate your configuration file with the desired options.
183 changes: 106 additions & 77 deletions docker/config.yaml → docker/config.yaml.mako

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyramid_oereb/standard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def drop_tables_from_standard_configuration(configuration_yaml_path, section='py


def _create_standard_yaml_config_(name='pyramid_oereb_standard.yml',
database='postgresql://postgres:password@localhost/pyramid_oereb'):
database='postgresql://postgres:password@localhost/pyramid_oereb',
print_backend='MapFishPrint'):
"""
Creates the specified YAML file using a template. This YAML file contains the standard
configuration to run a oereb server out of the box.
Expand All @@ -197,7 +198,7 @@ def _create_standard_yaml_config_(name='pyramid_oereb_standard.yml',
input_encoding='utf-8',
output_encoding='utf-8'
)
config = template.render(sqlalchemy_url=database, png_root_dir='')
config = template.render(sqlalchemy_url=database, png_root_dir='', print_backend=print_backend)
pyramid_oereb_yml = open(name, 'wb+')
pyramid_oereb_yml.write(config)
pyramid_oereb_yml.close()
Expand Down
11 changes: 10 additions & 1 deletion pyramid_oereb/standard/create_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,14 @@ def create_standard_yaml():
help='The database connection string (default is: '
'postgresql://postgres:password@db:5432/pyramid_oereb).'
)
parser.add_option(
'-p', '--print_backend',
dest='print_backend',
metavar='PRINT_BACKEND',
type='string',
default='MapFishPrint',
help='The print backend (for PDF generation) to use (default is: MapFishPrint)'
)
options, args = parser.parse_args()
_create_standard_yaml_config_(name=options.name, database=options.database)
_create_standard_yaml_config_(name=options.name, database=options.database,
print_backend=options.print_backend)
63 changes: 45 additions & 18 deletions pyramid_oereb/standard/pyramid_oereb.yml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,24 @@ pyramid_oereb:
# The pyramid renderer which is used as proxy pass through to the desired service for printable static
# extract. Here you can define the path to the logic which prepares the output as payload for print
# service and returns the result to the user.
# renderer: pyramid_oereb.contrib.print_proxy.mapfish_print.Renderer
% if print_backend == 'XML2PDF':
# Configuration for XML2PDF print service
renderer: pyramid_oereb.contrib.print_proxy.xml_2_pdf.Renderer
# The buffer on the map around the parcel in percent
buffer: 10
# Base URL with application of the print server
base_url: https://oereb-dev.gis-daten.ch/oereb/report/create
token: 24ba4328-a306-4832-905d-b979388d4cab
use_wms: "true"
validate: "false"
# The following parameters are currently not used by xml2pdf, but might be in the future (see issue #873)
buffer: 30
basic_map_size: [493, 280]
pdf_dpi: 300
pdf_map_size_millimeters: [174, 99]
% else:
# Configuration for MapFish-Print print service
renderer: pyramid_oereb.contrib.print_proxy.mapfish_print.Renderer
# The minimum buffer in pixel at 72 DPI between the real estate and the map's border.
buffer: 30
# The map size in pixel at 72 DPI (width, height), This is the defined size of a map image
# (requested in wms urls) inside the static extract. On a pdf report, tha map size will
# be calculated with the pdf_dpi and the pdf_map_size_millimeters below.
Expand All @@ -77,11 +91,29 @@ pyramid_oereb:
# The map size (in millimeters) used to calculate the size of the requested map (for pdf export only).
pdf_map_size_millimeters: [174, 99]
# Base URL with application of the print server
base_url: https://oereb-dev.gis-daten.ch/oereb/report/create
token: 24ba4328-a306-4832-905d-b979388d4cab
use_wms: "true"
validate: "false"
verify_certificate: true
base_url: http://{PRINT_SERVICE_HOST}:{PRINT_SERVICE_PORT}/print/oereb
# Name of the print tempate to use
template_name: A4 portrait
# The headers send to the print
headers:
Content-Type: application/json; charset=UTF-8
# Whether to display the RealEstate_SubunitOfLandRegister (Grundbuchkreis) in the pdf extract or not.
# Default to true.
display_real_estate_subunit_of_land_register: true
# Whether to display the Certification section in the pdf extract or not.
# Default to true
display_certification: true
# Split themes up, so that each sub theme gets its own page
# Disabled by default.
split_sub_themes: false
# Determine if a multiple page table of content (TOC) is used with a slightly different layout but
# better page numbering. If it is known that the TOC is very long and runs over more than one page it
# is preferred to set this to true.
multi_page_TOC: false
# Specify any additional URL parameters that the print shall use for WMS calls
wms_url_params:
TRANSPARENT: 'true'
% endif

# The "app_schema" property contains only one sub property "name". This is directly related to the database
# creation process, because this name is used as schema name in the target database. The app_schema holds
Expand Down Expand Up @@ -124,10 +156,6 @@ pyramid_oereb:
oereblex:
# OEREBlex host
host: https://oereblex.bl.ch
# geoLink schema version
# version: 1.1.1
# Pass schema version in URL
# pass_version: true
# Language of returned values
language: de
# Value for canton attribute
Expand Down Expand Up @@ -231,7 +259,7 @@ pyramid_oereb:
type: Bergwerk
# The real estate must have a property source.
source:
# The source must have a class which represents the accessor to the source. In this example, it is a an
# The source must have a class which represents the accessor to the source. In this example, it is an
# already implemented source which reads data from a database.
class: pyramid_oereb.standard.sources.real_estate.DatabaseSource
# The necessary parameters to use this class
Expand All @@ -243,7 +271,7 @@ pyramid_oereb:

# The processor of the oereb project needs access to address data. In the standard configuration, this
# is assumed to be read from a database. Hint: If you want to read the addresses out of an existing database
# table to avoid imports of this data every time it gets updatesi, you only need to change the model bound to
# table to avoid imports of this data every time it gets updates, you only need to change the model bound to
# the source. The model must implement the same field names and information as the default model does.
address:
# The address must have a property source.
Expand Down Expand Up @@ -277,7 +305,7 @@ pyramid_oereb:
# The municipality must have a property source.
source:
# The source must have a class which represents the accessor to the source. In this example, it is an
# already implemented source hich reads data from a database.
# already implemented source which reads data from a database.
class: pyramid_oereb.standard.sources.municipality.DatabaseSource
# The necessary parameters to use this class
params:
Expand All @@ -288,7 +316,7 @@ pyramid_oereb:

# The processor of the oereb project needs access to glossary data. In the standard configuration this
# is assumed to be read from a database. Hint: If you want to read the glossary out of an existing database
# table to avoid imports of this data every time it gets updatesi, you only need to change the model bound to
# table to avoid imports of this data every time it gets updates, you only need to change the model bound to
# the source. The model must implement the same field names and information as the default model does.
glossary:
# The glossary must have a property source.
Expand All @@ -304,7 +332,7 @@ pyramid_oereb:
model: pyramid_oereb.standard.models.main.Glossary

# The processor of the oereb project needs access to exclusion of liability data. In the standard
# configuration this is assumed to be read from a database. Hint: If you wamt to read the exclusion of
# configuration this is assumed to be read from a database. Hint: If you want to read the exclusion of
# liability out of an existing database table to avoid imports of this data every time it gets updates, you
# only need to change the model bound to the source. The model must implement the same field names and
# information as the default model does.
Expand Down Expand Up @@ -352,7 +380,6 @@ pyramid_oereb:
it: Il contenuto del Catasto RDPP si considera noto. Il Canton ---NOME DEL 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 costituti-vo di diritti e obblighi. Sono considerati giuridicamente vincolanti i documenti approvati o pubblicati passati in giudicato. Con l'autenticazione dell'estratto viene confermata la conformità dell'estratto rispetto al Catasto RDPP al momento della sua redazione.
rm: ...


# All PLRs which are provided by this application. This is related to all application behaviour, especially
# the extract creation process which loops over this list.
plrs:
Expand Down

0 comments on commit 236b589

Please sign in to comment.