Skip to content

Commit

Permalink
Only one results report is generated when SingleReport template is se…
Browse files Browse the repository at this point in the history
…lected (#123)

* Fix only the first sample is displayed in report preview

* Group the exit urls by path

* Remove pdb

* Safe exit_url
  • Loading branch information
xispa authored May 20, 2022
1 parent e4a02ba commit d89c77e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/senaite/impress/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from bika.lims import _
from bika.lims import api
from collections import OrderedDict
from DateTime import DateTime
from senaite.app.supermodel import SuperModel
from senaite.impress import logger
Expand Down Expand Up @@ -274,7 +275,16 @@ def ajax_save_reports(self):
if not exit_urls:
return api.get_url(self.context)

return exit_urls[0]
# Group the urls by path. This makes possible to at least return a
# single url for multiple uids when the base path (e.g. client) is the
# same. This is required for Single Reports, for which there are as many
# report groups as samples, regardless of clients
groups = OrderedDict()
for url in exit_urls:
base_path, uids = url.split("?uids=")
path_uids = groups.get(base_path, "")
groups[base_path] = ",".join(filter(None, [path_uids, uids]))
return "?uids=".join(groups.items()[0])

def get_exit_url_for(self, reports, action="save"):
"""Handle the response for the generated reports
Expand Down Expand Up @@ -309,9 +319,10 @@ def get_exit_url_for(self, reports, action="save"):
# generate exit URL
exit_url = self.context.absolute_url()
if clients:
exit_url = "{}/{}?uids={}".format(
api.get_url(clients[0]), endpoint, ",".join(report_uids))
exit_url = api.get_url(clients[0])

exit_url = "{}/{}?uids={}".format(exit_url, endpoint,
",".join(report_uids))
return exit_url

def ajax_get_reports(self, *args):
Expand Down
9 changes: 4 additions & 5 deletions src/senaite/impress/publishview.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def generate_reports_for(self,
grouped_collection = self.group_items_by(group_key, collection)
is_multi_template = self.is_multi_template(report_template)

htmls = []

html_collections = []
for key, collection in grouped_collection.items():
# render multi report
if is_multi_template:
Expand All @@ -147,7 +146,7 @@ def generate_reports_for(self,
paperformat=paperformat,
orientation=orientation,
report_options=report_options)
htmls.append(html)
html_collections.append((html, collection))
else:
# render single report
for model in collection:
Expand All @@ -156,7 +155,7 @@ def generate_reports_for(self,
paperformat=paperformat,
orientation=orientation,
report_options=report_options)
htmls.append(html)
html_collections.append((html, collection))

# generate a PDF for each HTML report
publisher = self.publisher
Expand All @@ -166,7 +165,7 @@ def generate_reports_for(self,

# wrap the reports for further processing
reports = []
for html, collection in zip(htmls, grouped_collection.values()):
for html, collection in html_collections:
report = getMultiAdapter((html,
collection,
template,
Expand Down

0 comments on commit d89c77e

Please sign in to comment.