Skip to content

Commit

Permalink
toc length calculation includes law_status (#2038)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschaer committed Aug 30, 2024
1 parent 6bb3c87 commit 2ebf392
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
12 changes: 5 additions & 7 deletions pyramid_oereb/contrib/print_proxy/mapfish_print/mapfish_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ def __call__(self, value, system):
extract_as_dict = self._render(extract_record, value[1])
feature_geometry = mapping(extract_record.real_estate.limit)

display_qrcode = Config.get('print', {}).get('display_qrcode', False)

if Config.get('print', {}).get('compute_toc_pages', False):
extract_as_dict['nbTocPages'] = TocPages(extract_as_dict, display_qrcode).getNbPages()
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)
Expand All @@ -98,6 +91,11 @@ def __call__(self, value, system):
'display_qrcode', False
)

if print_config.get('compute_toc_pages', False):
extract_as_dict['nbTocPages'] = TocPages(extract_as_dict).getNbPages()
else:
extract_as_dict['nbTocPages'] = 1

spec = {
'layout': Config.get('print', {})['template_name'],
'outputFormat': 'pdf',
Expand Down
30 changes: 17 additions & 13 deletions pyramid_oereb/contrib/print_proxy/mapfish_print/toc_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TocPages():

def __init__(self, extract, display_qrcode):
def __init__(self, extract):
self.disposable_height = 842 - 70 # A4 size - (footer + header); toc.jrxml
self.d1_height = 77 # toc.jrxml
self.d2_height = 29 # toc.jrxml
Expand All @@ -18,7 +18,7 @@ def __init__(self, extract, display_qrcode):
self.d6_left_height = 38 # toc.jrxml
self.d6_right_height = 20 # toc.jrxml
self.extract = extract
self.display_qrcode = display_qrcode
self.display_qrcode = self.extract['Display_QRCode']
self.total_length = self.compute_total_lenght()

def compute_d1(self):
Expand All @@ -34,7 +34,11 @@ def compute_d2(self):
page_label_height = 10 # toc.jrxml
total_size += blank_space_above + page_label_height
toc_item_height = 17 # toc.jrxml (20 in tocConcernedTheme.jrxml)
total_size += len(self.extract['ConcernedTheme']) * toc_item_height
unique_concerned_themes = []
for concerned_theme in self.extract['ConcernedTheme']:
if concerned_theme not in unique_concerned_themes:
unique_concerned_themes.append(concerned_theme)
total_size += len(unique_concerned_themes) * toc_item_height
log.debug(f"d2 total_size: {total_size}")
if total_size > self.d2_height:
return total_size
Expand Down Expand Up @@ -80,19 +84,19 @@ def compute_d6_left(self):
general_information_item_line_heigth = 8 # general_info_and_disclaimer.jrxml
total_size += general_information_title_height
for i in self.extract.get('GeneralInformation', []):
total_size += self.compute_length_of_wrapped_text(i[0]['Text'],
total_size += self.compute_length_of_wrapped_text(i['Info'],
78,
general_information_item_line_heigth)
# LandRegister-Disclaimer (1 title, 1 item)
land_register_disclaimer_title_line_height = 8 # general_info_and_disclaimer.jrxml
land_register_disclaimer_item_line_height = 8 # general_info_and_disclaimer.jrxml
for i in self.extract.get('DisclaimerLandRegister', []):
total_size += self.compute_length_of_wrapped_text(i['Title'][0]['Text'],
65,
land_register_disclaimer_title_line_height)
total_size += self.compute_length_of_wrapped_text(i['Content'][0]['Text'],
78,
land_register_disclaimer_item_line_height)

total_size += self.compute_length_of_wrapped_text(self.extract.get('DisclaimerLandRegister_Title', ''),
65,
land_register_disclaimer_title_line_height)
total_size += self.compute_length_of_wrapped_text(self.extract.get('DisclaimerLandRegister_Content', ''),
78,
land_register_disclaimer_item_line_height)
log.debug('d6 left total_size : {}'.format(total_size))
if total_size > self.d6_left_height:
return total_size
Expand All @@ -115,10 +119,10 @@ def compute_d6_right(self):

# Disclaimers (multiple items)
for i in self.extract.get('Disclaimer', []):
total_size += self.compute_length_of_wrapped_text(i['Title'][0]['Text'],
total_size += self.compute_length_of_wrapped_text(i['Title'],
65,
disclaimer_title_line_height)
total_size += self.compute_length_of_wrapped_text(i['Content'][0]['Text'],
total_size += self.compute_length_of_wrapped_text(i['Content'],
78,
disclaimer_item_line_height)
total_size += blank_space_below_disclaimers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def geometry(coordinates):


def test_toc_pages(extract):
assert TocPages(extract, False).getNbPages() == 1
assert TocPages(extract).getNbPages() == 1


def getSameEntryInList(reference, objects):
Expand Down

0 comments on commit 2ebf392

Please sign in to comment.