From 69e23c46b546cfc3e7845be890396bc5a5620b1e Mon Sep 17 00:00:00 2001 From: voisardf Date: Tue, 27 Aug 2024 16:49:00 +0200 Subject: [PATCH 01/10] first draft of new toc parameters implementation --- dev/config/pyramid_oereb.yml.mako | 10 ++++++++++ doc/source/changes.rst | 6 ++++++ .../print_proxy/mapfish_print/mapfish_print.py | 12 +++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/dev/config/pyramid_oereb.yml.mako b/dev/config/pyramid_oereb.yml.mako index 94c1228c16..95a0d75825 100644 --- a/dev/config/pyramid_oereb.yml.mako +++ b/dev/config/pyramid_oereb.yml.mako @@ -88,6 +88,16 @@ pyramid_oereb: # more time to generate the PDF. If set to false, it will assume that only one TOC page exists, and this can # lead to wrong numbering in the TOC. compute_toc_pages: true + # To avoid the potentially time consuming computing of the estimated toc pages number and its verification + # you can specify a default length for the number of TOC pages. - For most of the cantons the length of the + # TOC is pretty consistent unless a real estate is concerned by none or a huge number of restrictions. + # An additional page break might also occur if the number of published topics is close to a threshold number. + # So be aware that fixing this value and deactivating the compute_toc_pages above may lead to wrong page numbers + # in the table of content. + default_toc_length: 2 + # Depending on your toc configuration and number of disclaimer entries, the first page break of the table of content + # may appear when a real estate is concerned by one, two or more topics. + concerned_themes_for_first_toc_pagebreak: 3 # Specify any additional URL parameters that the print shall use for WMS calls wms_url_params: TRANSPARENT: 'true' diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 9eb919fbee..3e6a3057d8 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -6,6 +6,12 @@ Changes/Hints for migration This chapter will give you hints on how to handle version migration, in particular regarding what you may need to adapt in your project configuration, database etc. when upgrading to a new version. +Version 2.6.0 +------------- +* New parameter 'default_toc_length' allows to define a expected table of content pages number avoiding the extra +computation of the expected length. This value should only be set if >95% of the PDF have the same number of TOC pages. +Default setting: 1 + Version 2.5.2 ------------- Feature and maintenance release: diff --git a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py index 06c9f31591..2668372d38 100644 --- a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py +++ b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py @@ -73,17 +73,23 @@ def __call__(self, value, system): extract_as_dict = self._render(extract_record, value[1]) feature_geometry = mapping(extract_record.real_estate.limit) + print_config = Config.get('print', {}) + if Config.get('print', {}).get('compute_toc_pages', False): extract_as_dict['nbTocPages'] = TocPages(extract_as_dict).getNbPages() else: - extract_as_dict['nbTocPages'] = 1 + if print_config.get('default_toc_length', 1): + if len(extract_as_dict['ConcernedTheme']) < print_config.get('concerned_themes_for_first_toc_pagebreak', 2): + extract_as_dict['nbTocPages'] = 1 + else: + extract_as_dict['nbTocPages'] = print_config.get('default_toc_length', 1) + else: + extract_as_dict['nbTocPages'] = 1 # set the global_datetime variable so that it can be used later for the archive self.set_global_datetime(extract_as_dict['CreationDate']) self.convert_to_printable_extract(extract_as_dict, feature_geometry) - print_config = Config.get('print', {}) - extract_as_dict['Display_RealEstate_SubunitOfLandRegister'] = print_config.get( 'display_real_estate_subunit_of_land_register', True ) From 3b55d99efb3fc73bc8543104cb45718021ed44fe Mon Sep 17 00:00:00 2001 From: voisardf Date: Wed, 28 Aug 2024 17:11:06 +0200 Subject: [PATCH 02/10] Refactured the process and added more logging --- dev/config/pyramid_oereb.yml.mako | 3 -- doc/source/changes.rst | 7 ++-- .../mapfish_print/mapfish_print.py | 38 ++++++++++++++++--- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/dev/config/pyramid_oereb.yml.mako b/dev/config/pyramid_oereb.yml.mako index 95a0d75825..0cc3d97a6b 100644 --- a/dev/config/pyramid_oereb.yml.mako +++ b/dev/config/pyramid_oereb.yml.mako @@ -95,9 +95,6 @@ pyramid_oereb: # So be aware that fixing this value and deactivating the compute_toc_pages above may lead to wrong page numbers # in the table of content. default_toc_length: 2 - # Depending on your toc configuration and number of disclaimer entries, the first page break of the table of content - # may appear when a real estate is concerned by one, two or more topics. - concerned_themes_for_first_toc_pagebreak: 3 # Specify any additional URL parameters that the print shall use for WMS calls wms_url_params: TRANSPARENT: 'true' diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 3e6a3057d8..e82036c99d 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -8,9 +8,10 @@ to adapt in your project configuration, database etc. when upgrading to a new ve Version 2.6.0 ------------- -* New parameter 'default_toc_length' allows to define a expected table of content pages number avoiding the extra -computation of the expected length. This value should only be set if >95% of the PDF have the same number of TOC pages. -Default setting: 1 +* New parameter 'default_toc_length' allows to define a default table of content pages number avoiding a second +call for the pdf extract in most cases. This value should be set if >95% of the PDF have the same number of TOC +pages. +Default setting: 2 Version 2.5.2 ------------- diff --git a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py index 2668372d38..b1dd94fa3d 100644 --- a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py +++ b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py @@ -78,11 +78,8 @@ def __call__(self, value, system): if Config.get('print', {}).get('compute_toc_pages', False): extract_as_dict['nbTocPages'] = TocPages(extract_as_dict).getNbPages() else: - if print_config.get('default_toc_length', 1): - if len(extract_as_dict['ConcernedTheme']) < print_config.get('concerned_themes_for_first_toc_pagebreak', 2): - extract_as_dict['nbTocPages'] = 1 - else: - extract_as_dict['nbTocPages'] = print_config.get('default_toc_length', 1) + if Config.get('print', {}).get('default_toc_length', False): + extract_as_dict['nbTocPages'] = print_config.get('default_toc_length', 2) else: extract_as_dict['nbTocPages'] = 1 @@ -122,6 +119,8 @@ def __call__(self, value, system): data=json.dumps(spec) ) try: + log.debug('Validation of the TOC length with compute_toc_pages set to {} and default_toc_length set to {}'.format( \ + print_config.get('compute_toc_pages'),print_config.get('default_toc_length'))) if Config.get('print', {}).get('compute_toc_pages', False): with io.BytesIO() as pdf: pdf.write(print_result.content) @@ -137,14 +136,43 @@ def __call__(self, value, system): except ValueError: true_nb_of_toc = 1 + log.debug('True number of TOC pages is {}'.format(true_nb_of_toc)) + if true_nb_of_toc != extract_as_dict['nbTocPages']: + log.warning('nbTocPages in result pdf: {} are not equal to the one predicted : {}, request new pdf'.format(true_nb_of_toc,extract_as_dict['nbTocPages'])) # noqa + log.debug('Secondary PDF extract call STARTED') + extract_as_dict['nbTocPages'] = true_nb_of_toc + print_result = requests.post( + pdf_url, + headers=pdf_headers, + data=json.dumps(spec) + ) + log.debug('Secondary PDF extract call to fix TOC pages number FINISHED') + elif Config.get('print', {}).get('default_toc_length', 2): + with io.BytesIO() as pdf: + pdf.write(print_result.content) + pdf_reader = PdfReader(pdf) + x = [] + for i in range(len(pdf_reader.outline)): + if isinstance(pdf_reader.outline[i], list): + x.append(pdf_reader.outline[i][0]['/Page']['/StructParents']) + else: + x.append(pdf_reader.outline[i]['/Page']['/StructParents']) + try: + true_nb_of_toc = min(x)-1 + except ValueError: + true_nb_of_toc = 1 + + log.debug('True number of TOC pages is {}'.format(true_nb_of_toc)) if true_nb_of_toc != extract_as_dict['nbTocPages']: log.warning('nbTocPages in result pdf: {} are not equal to the one predicted : {}, request new pdf'.format(true_nb_of_toc,extract_as_dict['nbTocPages'])) # noqa extract_as_dict['nbTocPages'] = true_nb_of_toc + log.debug('Secondary PDF extract call STARTED') print_result = requests.post( pdf_url, headers=pdf_headers, data=json.dumps(spec) ) + log.debug('Secondary PDF extract call FINISHED') except PdfReadError as e: err_msg = 'a problem occurred while generating the pdf file' log.error(err_msg + ': ' + str(e)) From d8c72dbcb3d480084b048e30b4a493b10fbe03e5 Mon Sep 17 00:00:00 2001 From: voisardf Date: Wed, 28 Aug 2024 17:26:31 +0200 Subject: [PATCH 03/10] added linting comments --- .../contrib/print_proxy/mapfish_print/mapfish_print.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py index b1dd94fa3d..a34f986cfb 100644 --- a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py +++ b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py @@ -119,8 +119,7 @@ def __call__(self, value, system): data=json.dumps(spec) ) try: - log.debug('Validation of the TOC length with compute_toc_pages set to {} and default_toc_length set to {}'.format( \ - print_config.get('compute_toc_pages'),print_config.get('default_toc_length'))) + log.debug('Validation of the TOC length with compute_toc_pages set to {} and default_toc_length set to {}'.format(print_config.get('compute_toc_pages'), print_config.get('default_toc_length'))) # noqa if Config.get('print', {}).get('compute_toc_pages', False): with io.BytesIO() as pdf: pdf.write(print_result.content) From 7296571201a87af99d308a02e0bd5d9b2e2206ee Mon Sep 17 00:00:00 2001 From: voisardf Date: Thu, 29 Aug 2024 11:46:02 +0200 Subject: [PATCH 04/10] added two config tests --- .../resources/test_config.yml | 2 ++ .../test_mapfish_print_configuration.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml b/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml index 3b1dd144ee..4776cc2245 100644 --- a/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml +++ b/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml @@ -4,6 +4,8 @@ pyramid_oereb: wms_url_params: TRANSPARENT: 'true' OTHERCUSTOM: 'myvalue' + compute_toc_pages: false + default_toc_length: 2 theme: source: diff --git a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py index a2ff8d4aae..d03f26f08d 100644 --- a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py +++ b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py @@ -100,3 +100,14 @@ def test_default_wms_url_param_config(DummyRenderInfo): config = renderer.get_wms_url_params() # Do the check for this test. Value should be the default setting. assert config == {'TRANSPARENT': 'true'} + + +def test_toc_pages_default_config(): + Config._config = None + Config.init('./tests/contrib.print_proxy.mapfish_print/resources/test_config.yml', 'pyramid_oereb') + compute_toc_pages = Config.get('print', {}).get('compute_toc_pages') + default_toc_length = Config.get('print', {}).get('default_toc_length') + + assert compute_toc_pages == False + assert default_toc_length == 2 + From 087b45d5836de7b128f177972a2dd18b2b972398 Mon Sep 17 00:00:00 2001 From: voisardf Date: Thu, 29 Aug 2024 12:12:20 +0200 Subject: [PATCH 05/10] fixed some test and linting --- .../test_mapfish_print_configuration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py index d03f26f08d..06146040fa 100644 --- a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py +++ b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py @@ -108,6 +108,6 @@ def test_toc_pages_default_config(): compute_toc_pages = Config.get('print', {}).get('compute_toc_pages') default_toc_length = Config.get('print', {}).get('default_toc_length') - assert compute_toc_pages == False + assert isinstance(compute_toc_pages,bool) + assert bool(compute_toc_pages) == False assert default_toc_length == 2 - From c4b9261f8cecf9e30ed502afe5ef303a8d9e279a Mon Sep 17 00:00:00 2001 From: voisardf Date: Thu, 29 Aug 2024 12:16:07 +0200 Subject: [PATCH 06/10] more linting, sorry --- .../test_mapfish_print_configuration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py index 06146040fa..f19e8268e8 100644 --- a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py +++ b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py @@ -108,6 +108,6 @@ def test_toc_pages_default_config(): compute_toc_pages = Config.get('print', {}).get('compute_toc_pages') default_toc_length = Config.get('print', {}).get('default_toc_length') - assert isinstance(compute_toc_pages,bool) - assert bool(compute_toc_pages) == False + assert isinstance(compute_toc_pages, bool) + assert bool(compute_toc_pages) is False assert default_toc_length == 2 From a5157d012d09fad58e4d28d2e26e2e9c698d337c Mon Sep 17 00:00:00 2001 From: voisardf Date: Thu, 29 Aug 2024 16:35:56 +0200 Subject: [PATCH 07/10] improved code as discussed and suggested --- dev/config/pyramid_oereb.yml.mako | 25 +++-- doc/source/changes.rst | 6 +- .../mapfish_print/mapfish_print.py | 92 +++++++------------ .../resources/test_config.yml | 2 +- .../test_mapfish_print_configuration.py | 4 +- 5 files changed, 51 insertions(+), 78 deletions(-) diff --git a/dev/config/pyramid_oereb.yml.mako b/dev/config/pyramid_oereb.yml.mako index 335fd302c6..991f220fd4 100644 --- a/dev/config/pyramid_oereb.yml.mako +++ b/dev/config/pyramid_oereb.yml.mako @@ -85,19 +85,18 @@ pyramid_oereb: # Will make an estimation of the total length of the Table of Content (TOC) and control that the page # numbering in the output pdf is consistent with TOC numbering. If it is known that the TOC is very long and # could run over more than one page, it is preferred to set this to true. The drawback is that it might need - # more time to generate the PDF. If set to false, it will assume that only one TOC page exists, and this can - # lead to wrong numbering in the TOC. - compute_toc_pages: true - # To avoid the potentially time consuming second computing of the PDF extract and skip the the computation - # of the estimated TOC length, you can specify a default length for the number of TOC pages. - # For most of the cantons the length of the TOC is pretty consistent unless a real estate is concerned by none - # or a huge number of restrictions. - # An additional page break might also occur if the number of published topics is close to a threshold number - # where the TOC fits just about on one or two pages. - for those case estimate the TOC length ist preferable. - # In both cases (computing an estimated length or setting a default length) the exact number of TOC pages is - # extracted from the created PDF and if it is different from the expected value the PDF extract is called a - # second time with the correct page numbers. - default_toc_length: 2 + # more time to generate the PDF. If set to false, the general_toc_length setting below will be used. If it is + # not set it will assume that only one TOC page exists, and this can lead to wrong numbering in the TOC, which + # will be fixed by a second PDF extract call that has an impact on performance. + compute_toc_pages: false + # In order to skip the computation of the estimated number of TOC pages which might return an erroneous result + # for your setting, you can specify a default for the number of TOC pages. For most of the cantons the number of + # TOC pages is pretty constant unless a real estate is concerned by none or a huge number of restrictions. + # In both cases (computing an estimate or setting a default for the number of TOC pages) the exact number of TOC + # pages is extracted from the created PDF and if it differs from the expected value the PDF is created a second + # time with the correct page numbers. + # Note that if "compute_toc_pages" is set true the "general_toc_length" is not taken into account. + general_toc_length: 2 # Specify any additional URL parameters that the print shall use for WMS calls wms_url_params: TRANSPARENT: 'true' diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 70e651fd30..af31a10664 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -8,9 +8,9 @@ to adapt in your project configuration, database etc. when upgrading to a new ve Version 2.6.0 ------------- -* New parameter 'default_toc_length' allows to define a default table of content pages number avoiding a second -call for the pdf extract in most cases. This value should be set if >95% of the PDF have the same number of TOC -pages. +* New parameter 'general_toc_length' allows to define a default table of content pages number avoiding a second +call for the pdf extract in most cases. This value should be set if most of the PDF extracts have the same number +of TOC pages. Default setting: 2 Version 2.5.3 diff --git a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py index a34f986cfb..61491862d0 100644 --- a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py +++ b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py @@ -75,11 +75,11 @@ def __call__(self, value, system): print_config = Config.get('print', {}) - if Config.get('print', {}).get('compute_toc_pages', False): + if print_config.get('compute_toc_pages', False): extract_as_dict['nbTocPages'] = TocPages(extract_as_dict).getNbPages() else: - if Config.get('print', {}).get('default_toc_length', False): - extract_as_dict['nbTocPages'] = print_config.get('default_toc_length', 2) + if print_config.get('general_toc_length') and int(print_config.get('general_toc_length')) > 0: + extract_as_dict['nbTocPages'] = print_config.get('general_toc_length', 2) else: extract_as_dict['nbTocPages'] = 1 @@ -100,7 +100,7 @@ def __call__(self, value, system): ) spec = { - 'layout': Config.get('print', {})['template_name'], + 'layout': print_config['template_name'], 'outputFormat': 'pdf', 'lang': self._language, 'attributes': extract_as_dict, @@ -111,67 +111,41 @@ def __call__(self, value, system): if self._request.GET.get('getspec', 'no') != 'no': response.headers['Content-Type'] = 'application/json; charset=UTF-8' return json.dumps(spec, sort_keys=True, indent=4) - pdf_url = urlparse.urljoin(Config.get('print', {})['base_url'] + '/', 'buildreport.pdf') - pdf_headers = Config.get('print', {})['headers'] + pdf_url = urlparse.urljoin(print_config['base_url'] + '/', 'buildreport.pdf') + pdf_headers = print_config['headers'] print_result = requests.post( pdf_url, headers=pdf_headers, data=json.dumps(spec) ) try: - log.debug('Validation of the TOC length with compute_toc_pages set to {} and default_toc_length set to {}'.format(print_config.get('compute_toc_pages'), print_config.get('default_toc_length'))) # noqa - if Config.get('print', {}).get('compute_toc_pages', False): - with io.BytesIO() as pdf: - pdf.write(print_result.content) - pdf_reader = PdfReader(pdf) - x = [] - for i in range(len(pdf_reader.outline)): - if isinstance(pdf_reader.outline[i], list): - x.append(pdf_reader.outline[i][0]['/Page']['/StructParents']) - else: - x.append(pdf_reader.outline[i]['/Page']['/StructParents']) - try: - true_nb_of_toc = min(x)-1 - except ValueError: - true_nb_of_toc = 1 - - log.debug('True number of TOC pages is {}'.format(true_nb_of_toc)) - if true_nb_of_toc != extract_as_dict['nbTocPages']: - log.warning('nbTocPages in result pdf: {} are not equal to the one predicted : {}, request new pdf'.format(true_nb_of_toc,extract_as_dict['nbTocPages'])) # noqa - log.debug('Secondary PDF extract call STARTED') - extract_as_dict['nbTocPages'] = true_nb_of_toc - print_result = requests.post( - pdf_url, - headers=pdf_headers, - data=json.dumps(spec) - ) - log.debug('Secondary PDF extract call to fix TOC pages number FINISHED') - elif Config.get('print', {}).get('default_toc_length', 2): - with io.BytesIO() as pdf: - pdf.write(print_result.content) - pdf_reader = PdfReader(pdf) - x = [] - for i in range(len(pdf_reader.outline)): - if isinstance(pdf_reader.outline[i], list): - x.append(pdf_reader.outline[i][0]['/Page']['/StructParents']) - else: - x.append(pdf_reader.outline[i]['/Page']['/StructParents']) - try: - true_nb_of_toc = min(x)-1 - except ValueError: - true_nb_of_toc = 1 - - log.debug('True number of TOC pages is {}'.format(true_nb_of_toc)) - if true_nb_of_toc != extract_as_dict['nbTocPages']: - log.warning('nbTocPages in result pdf: {} are not equal to the one predicted : {}, request new pdf'.format(true_nb_of_toc,extract_as_dict['nbTocPages'])) # noqa - extract_as_dict['nbTocPages'] = true_nb_of_toc - log.debug('Secondary PDF extract call STARTED') - print_result = requests.post( - pdf_url, - headers=pdf_headers, - data=json.dumps(spec) - ) - log.debug('Secondary PDF extract call FINISHED') + log.debug('Validation of the TOC length with compute_toc_pages set to {} and general_toc_length set to {}'.format(print_config.get('compute_toc_pages'), print_config.get('general_toc_length'))) # noqa + with io.BytesIO() as pdf: + pdf.write(print_result.content) + pdf_reader = PdfReader(pdf) + x = [] + for i in range(len(pdf_reader.outline)): + if isinstance(pdf_reader.outline[i], list): + x.append(pdf_reader.outline[i][0]['/Page']['/StructParents']) + else: + x.append(pdf_reader.outline[i]['/Page']['/StructParents']) + try: + true_nb_of_toc = min(x)-1 + except ValueError: + true_nb_of_toc = 1 + + log.debug('True number of TOC pages is {}, expected number was {}'.format(true_nb_of_toc, extract_as_dict['nbTocPages'])) #noqa + if true_nb_of_toc != extract_as_dict['nbTocPages']: + log.warning('nbTocPages in result pdf: {} are not equal to the one predicted : {}, request new pdf'.format(true_nb_of_toc,extract_as_dict['nbTocPages'])) # noqa + log.debug('Secondary PDF extract call STARTED') + extract_as_dict['nbTocPages'] = true_nb_of_toc + print_result = requests.post( + pdf_url, + headers=pdf_headers, + data=json.dumps(spec) + ) + log.debug('Secondary PDF extract call to fix TOC pages number DONE') + except PdfReadError as e: err_msg = 'a problem occurred while generating the pdf file' log.error(err_msg + ': ' + str(e)) diff --git a/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml b/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml index 4776cc2245..6189143f97 100644 --- a/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml +++ b/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml @@ -5,7 +5,7 @@ pyramid_oereb: TRANSPARENT: 'true' OTHERCUSTOM: 'myvalue' compute_toc_pages: false - default_toc_length: 2 + general_toc_length: 2 theme: source: diff --git a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py index f19e8268e8..cab5ea78c3 100644 --- a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py +++ b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py @@ -106,8 +106,8 @@ def test_toc_pages_default_config(): Config._config = None Config.init('./tests/contrib.print_proxy.mapfish_print/resources/test_config.yml', 'pyramid_oereb') compute_toc_pages = Config.get('print', {}).get('compute_toc_pages') - default_toc_length = Config.get('print', {}).get('default_toc_length') + general_toc_length = Config.get('print', {}).get('general_toc_length') assert isinstance(compute_toc_pages, bool) assert bool(compute_toc_pages) is False - assert default_toc_length == 2 + assert general_toc_length == 2 From 77f6db111c1fa61955531e94fe14e7e0010fe09e Mon Sep 17 00:00:00 2001 From: voisardf Date: Thu, 29 Aug 2024 17:15:52 +0200 Subject: [PATCH 08/10] typo with lint --- .../contrib/print_proxy/mapfish_print/mapfish_print.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py index 61491862d0..64b3c9458f 100644 --- a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py +++ b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py @@ -134,7 +134,7 @@ def __call__(self, value, system): except ValueError: true_nb_of_toc = 1 - log.debug('True number of TOC pages is {}, expected number was {}'.format(true_nb_of_toc, extract_as_dict['nbTocPages'])) #noqa + log.debug('True number of TOC pages is {}, expected number was {}'.format(true_nb_of_toc, extract_as_dict['nbTocPages'])) # noqa if true_nb_of_toc != extract_as_dict['nbTocPages']: log.warning('nbTocPages in result pdf: {} are not equal to the one predicted : {}, request new pdf'.format(true_nb_of_toc,extract_as_dict['nbTocPages'])) # noqa log.debug('Secondary PDF extract call STARTED') From a5f42fac29b3c52819a1da07aa6e9e94f247a9a0 Mon Sep 17 00:00:00 2001 From: voisardf Date: Fri, 30 Aug 2024 10:32:14 +0200 Subject: [PATCH 09/10] renamed parameter as requested --- dev/config/pyramid_oereb.yml.mako | 6 +++--- doc/source/changes.rst | 2 +- .../contrib/print_proxy/mapfish_print/mapfish_print.py | 6 +++--- .../resources/test_config.yml | 2 +- .../test_mapfish_print_configuration.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dev/config/pyramid_oereb.yml.mako b/dev/config/pyramid_oereb.yml.mako index 991f220fd4..079a06f913 100644 --- a/dev/config/pyramid_oereb.yml.mako +++ b/dev/config/pyramid_oereb.yml.mako @@ -85,7 +85,7 @@ pyramid_oereb: # Will make an estimation of the total length of the Table of Content (TOC) and control that the page # numbering in the output pdf is consistent with TOC numbering. If it is known that the TOC is very long and # could run over more than one page, it is preferred to set this to true. The drawback is that it might need - # more time to generate the PDF. If set to false, the general_toc_length setting below will be used. If it is + # more time to generate the PDF. If set to false, the expected_toc_length setting below will be used. If it is # not set it will assume that only one TOC page exists, and this can lead to wrong numbering in the TOC, which # will be fixed by a second PDF extract call that has an impact on performance. compute_toc_pages: false @@ -95,8 +95,8 @@ pyramid_oereb: # In both cases (computing an estimate or setting a default for the number of TOC pages) the exact number of TOC # pages is extracted from the created PDF and if it differs from the expected value the PDF is created a second # time with the correct page numbers. - # Note that if "compute_toc_pages" is set true the "general_toc_length" is not taken into account. - general_toc_length: 2 + # Note that if "compute_toc_pages" is set true the "expected_toc_length" is not taken into account. + expected_toc_length: 2 # Specify any additional URL parameters that the print shall use for WMS calls wms_url_params: TRANSPARENT: 'true' diff --git a/doc/source/changes.rst b/doc/source/changes.rst index af31a10664..df897b75d8 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -8,7 +8,7 @@ to adapt in your project configuration, database etc. when upgrading to a new ve Version 2.6.0 ------------- -* New parameter 'general_toc_length' allows to define a default table of content pages number avoiding a second +* New parameter 'expected_toc_length' allows to define a default table of content pages number avoiding a second call for the pdf extract in most cases. This value should be set if most of the PDF extracts have the same number of TOC pages. Default setting: 2 diff --git a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py index 64b3c9458f..62dee7749e 100644 --- a/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py +++ b/pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py @@ -78,8 +78,8 @@ def __call__(self, value, system): if print_config.get('compute_toc_pages', False): extract_as_dict['nbTocPages'] = TocPages(extract_as_dict).getNbPages() else: - if print_config.get('general_toc_length') and int(print_config.get('general_toc_length')) > 0: - extract_as_dict['nbTocPages'] = print_config.get('general_toc_length', 2) + if print_config.get('expected_toc_length') and int(print_config.get('expected_toc_length')) > 0: + extract_as_dict['nbTocPages'] = print_config.get('expected_toc_length') else: extract_as_dict['nbTocPages'] = 1 @@ -119,7 +119,7 @@ def __call__(self, value, system): data=json.dumps(spec) ) try: - log.debug('Validation of the TOC length with compute_toc_pages set to {} and general_toc_length set to {}'.format(print_config.get('compute_toc_pages'), print_config.get('general_toc_length'))) # noqa + log.debug('Validation of the TOC length with compute_toc_pages set to {} and expected_toc_length set to {}'.format(print_config.get('compute_toc_pages'), print_config.get('expected_toc_length'))) # noqa with io.BytesIO() as pdf: pdf.write(print_result.content) pdf_reader = PdfReader(pdf) diff --git a/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml b/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml index 6189143f97..027758c227 100644 --- a/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml +++ b/tests/contrib.print_proxy.mapfish_print/resources/test_config.yml @@ -5,7 +5,7 @@ pyramid_oereb: TRANSPARENT: 'true' OTHERCUSTOM: 'myvalue' compute_toc_pages: false - general_toc_length: 2 + expected_toc_length: 2 theme: source: diff --git a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py index cab5ea78c3..9066a8050b 100644 --- a/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py +++ b/tests/contrib.print_proxy.mapfish_print/test_mapfish_print_configuration.py @@ -106,8 +106,8 @@ def test_toc_pages_default_config(): Config._config = None Config.init('./tests/contrib.print_proxy.mapfish_print/resources/test_config.yml', 'pyramid_oereb') compute_toc_pages = Config.get('print', {}).get('compute_toc_pages') - general_toc_length = Config.get('print', {}).get('general_toc_length') + expected_toc_length = Config.get('print', {}).get('expected_toc_length') assert isinstance(compute_toc_pages, bool) assert bool(compute_toc_pages) is False - assert general_toc_length == 2 + assert expected_toc_length == 2 From ea54626afb1693644d5db177ff866ddc5f60361e Mon Sep 17 00:00:00 2001 From: voisardf Date: Mon, 2 Sep 2024 16:41:23 +0200 Subject: [PATCH 10/10] adapted documentation of new parameter --- doc/source/changes.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/source/changes.rst b/doc/source/changes.rst index df897b75d8..cf0c1542ca 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -9,9 +9,9 @@ to adapt in your project configuration, database etc. when upgrading to a new ve Version 2.6.0 ------------- * New parameter 'expected_toc_length' allows to define a default table of content pages number avoiding a second -call for the pdf extract in most cases. This value should be set if most of the PDF extracts have the same number -of TOC pages. -Default setting: 2 +call for the pdf extract in most cases. This value may be be set if most of the PDF extracts have the same number +of TOC pages. It complements the 'compute_toc_pages' parameter. If the latter is set to true 'expected_toc_length' +is ignored. Version 2.5.3 -------------