Skip to content

Commit 5dc69d3

Browse files
committed
Name the broken exhibit in the warning message
1 parent 822477d commit 5dc69d3

2 files changed

Lines changed: 55 additions & 19 deletions

File tree

docassemble/AssemblyLine/al_document.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,18 +2211,24 @@ def has_broken_documents(self) -> bool:
22112211
Returns:
22122212
bool: True if any document or nested bundle has broken content.
22132213
"""
2214+
return len(self.broken_exhibit_titles()) > 0
2215+
2216+
def broken_exhibit_titles(self) -> List[str]:
2217+
"""
2218+
Returns the titles of any broken exhibits in this bundle, including
2219+
ones inside nested bundles.
2220+
2221+
Returns:
2222+
List[str]: Titles of exhibits that will be skipped.
2223+
"""
2224+
titles: List[str] = []
22142225
for document in self.enabled_documents():
2215-
if (
2216-
hasattr(document, "has_broken_exhibits")
2217-
and document.has_broken_exhibits()
2218-
):
2219-
return True
2220-
if (
2221-
isinstance(document, ALDocumentBundle)
2222-
and document.has_broken_documents()
2223-
):
2224-
return True
2225-
return False
2226+
if hasattr(document, "broken_exhibits"):
2227+
for exhibit in document.broken_exhibits():
2228+
titles.append(getattr(exhibit, "title", None) or "an exhibit")
2229+
if isinstance(document, ALDocumentBundle):
2230+
titles.extend(document.broken_exhibit_titles())
2231+
return titles
22262232

22272233
def broken_documents_warning_html(self) -> str:
22282234
"""
@@ -2232,14 +2238,15 @@ def broken_documents_warning_html(self) -> str:
22322238
Returns:
22332239
str: The warning HTML, or an empty string if nothing is broken.
22342240
"""
2235-
if not self.has_broken_documents():
2241+
broken_titles = self.broken_exhibit_titles()
2242+
if not broken_titles:
22362243
return ""
2237-
return (
2238-
'<div class="alert alert-warning" role="alert">'
2239-
"One of your files did not upload correctly and it will not be included. "
2240-
"Please try uploading it again before you continue."
2241-
"</div>"
2242-
)
2244+
quoted = [f'"{escape(title)}"' for title in broken_titles]
2245+
if len(quoted) == 1:
2246+
message = f"{quoted[0]} did not upload correctly and won't be included. Please try uploading it again before you continue."
2247+
else:
2248+
message = f"{', '.join(quoted[:-1])} and {quoted[-1]} didn't upload correctly and won't be included. Please try uploading them again before you continue."
2249+
return f'<div class="alert alert-warning" role="alert">{message}</div>'
22432250

22442251
def download_list_html(
22452252
self,

docassemble/AssemblyLine/test_al_document.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,30 @@ def as_pdf(self, **kwargs):
9898
return self._pdf
9999

100100

101+
class FakeExhibit:
102+
def __init__(self, title):
103+
self.title = title
104+
105+
101106
class FakeDocWithBrokenExhibits:
102-
def __init__(self, broken):
107+
def __init__(self, broken, broken_titles=None):
103108
self._broken = broken
109+
if broken_titles is not None:
110+
self._broken_titles = broken_titles
111+
elif broken:
112+
self._broken_titles = ["Broken Exhibit"]
113+
else:
114+
self._broken_titles = []
104115

105116
def is_enabled(self, refresh=True):
106117
return True
107118

108119
def has_broken_exhibits(self):
109120
return self._broken
110121

122+
def broken_exhibits(self):
123+
return [FakeExhibit(title) for title in self._broken_titles]
124+
111125

112126
class TestSingleDocumentBundleFilename(unittest.TestCase):
113127
def test_bundle_as_pdf_renames_single_document_to_bundle_filename(self):
@@ -307,6 +321,21 @@ def test_bundle_detects_broken_document_in_nested_bundle(self):
307321

308322
self.assertTrue(outer_bundle.has_broken_documents())
309323

324+
def test_warning_names_the_broken_exhibit(self):
325+
bundle = ALDocumentBundle(
326+
"bundle",
327+
elements=[
328+
FakeDocWithBrokenExhibits(broken=True, broken_titles=["Pay Stub"])
329+
],
330+
title="Bundle title",
331+
filename="bundle-output.pdf",
332+
enabled=True,
333+
)
334+
335+
warning = bundle.broken_documents_warning_html()
336+
337+
self.assertIn("Pay Stub", warning)
338+
310339

311340
class test_aladdendum(unittest.TestCase):
312341
def test_safe_value(self):

0 commit comments

Comments
 (0)