-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default toc length config #2042
Changes from 14 commits
0b56eea
be33be2
b84a487
df0c13f
d667506
46444b5
f50347b
69e23c4
3b55d99
d8c72db
7296571
087b45d
c4b9261
e9023cb
a5157d0
77f6db1
a5f42fa
ea54626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 second computing of the PDF extract and skip the the computation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe: 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. |
||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the name of the variable could be more precise. E.g. "most_frequent_toc_length" |
||
# Specify any additional URL parameters that the print shall use for WMS calls | ||
wms_url_params: | ||
TRANSPARENT: 'true' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,13 @@ 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 default table of content pages number avoiding a second | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would omit the statemtents about the 95% and the default setting. I guess default is to not set this parameter. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is omitted now. A change in this pull request is that the pdf is built a second time whenever the numbers of toc pages disagree between extract_as_dict['nbTocPages'] (computed/expected/1, depending on the setting) and the one in the returned pdf. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current version it is only rebuild if 'compute_toc_pages' is true. |
||
|
||
Version 2.5.3 | ||
------------- | ||
Feature and maintenance release: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,17 +73,20 @@ | |
extract_as_dict = self._render(extract_record, value[1]) | ||
feature_geometry = mapping(extract_record.real_estate.limit) | ||
|
||
print_config = Config.get('print', {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the variable 'print_config' is defined, it should thoroughly be used in subsequent parts of the code. |
||
|
||
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 Config.get('print', {}).get('default_toc_length', False): | ||
extract_as_dict['nbTocPages'] = print_config.get('default_toc_length', 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not specify a default, but test if it is a positive number. |
||
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 | ||
) | ||
|
@@ -116,6 +119,7 @@ | |
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can leave the if statement away. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. |
||
with io.BytesIO() as pdf: | ||
pdf.write(print_result.content) | ||
|
@@ -131,14 +135,43 @@ | |
except ValueError: | ||
true_nb_of_toc = 1 | ||
|
||
log.debug('True number of TOC pages is {}'.format(true_nb_of_toc)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the expected number can also be written to the log (in case it is computed). |
||
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)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the in the comment, you could point out, that if the compute_toc_pages is set to true, it will always overwrite the default_toc_length.