Skip to content

Commit

Permalink
Agency: Ensure a failing pdf file access does not crash application
Browse files Browse the repository at this point in the history
TYPE: Bugfix
LINK: ogc-1906
  • Loading branch information
Tschuppi81 authored Nov 11, 2024
1 parent 962fbac commit c85c47e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/onegov/agency/models/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ def pdf_file(self) -> 'StoredFile | None':
"""

return self.pdf.reference.file if self.pdf else None
try:
return self.pdf.reference.file if self.pdf else None
except (OSError, Exception):
return None

# FIXME: asymmetric property
@pdf_file.setter
Expand Down
12 changes: 6 additions & 6 deletions src/onegov/agency/templates/agency.pt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@

<div tal:condition="request.app.org.meta.report_changes|True" class="borderless-side-panel">
<h2 i18n:translate>Changes</h2>
<div class="submit-yours">
<p i18n:translate>The contact form can be used to report changes to incorrect information of the persons or organizations listed. The form is not intended for contacting or sending messages to the respective persons and organizations.</p>
<a href="${request.link(agency.proxy(), 'report-change')}">
<b i18n:translate>Report change</b>
</a>
</div>
<div class="submit-yours">
<p i18n:translate>The contact form can be used to report changes to incorrect information of the persons or organizations listed. The form is not intended for contacting or sending messages to the respective persons and organizations.</p>
<a href="${request.link(agency.proxy(), 'report-change')}">
<b i18n:translate>Report change</b>
</a>
</div>
</div>
<div tal:condition="agency.coordinates" class="borderless-side-panel">
<h2>Karte</h2>
Expand Down
3 changes: 2 additions & 1 deletion src/onegov/core/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def parse_structure(
raise ValidationError('Namespaced attributes are not allowed')

if element.tag not in valid_tags:
raise ValidationError("Invalid element '<{}>'".format(element.tag))
raise ValidationError(
"Invalid element '<{}>'".format(element.tag)) # type:ignore

return xml_tree

Expand Down
2 changes: 1 addition & 1 deletion src/onegov/pdf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def colorize(
for element in body:
if element.tag == 'p':
self.p_markup(self.inner_html(element), self.style.paragraph)
elif element.tag in 'ol':
elif element.tag == 'ol':
style = deepcopy(self.style.li)
style.leftIndent += self.style.ol.leftIndent
items = [
Expand Down
7 changes: 4 additions & 3 deletions src/onegov/people/models/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ def ancestors(self) -> 'Iterator[Agency]': ...
def organigram_file(self) -> 'StoredFile | None':
""" Returns the file-like content of the organigram. """

if self.organigram:
return self.organigram.reference.file
return None
try:
return self.organigram.reference.file if self.organigram else None
except (OSError, Exception):
return None

# FIXME: asymmetric property
@organigram_file.setter
Expand Down

0 comments on commit c85c47e

Please sign in to comment.