Skip to content
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

Use most recent AR as primary storage #52

Merged
merged 1 commit into from
Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.1.1 (unreleased)
------------------

- #52: Use the most recent AR as the primary storage
- #48: Fix PDF storage in primary AR when "Store Multi-Report PDFs Individually" option is turned off


Expand Down
17 changes: 8 additions & 9 deletions src/senaite/impress/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import inspect
import json
from operator import methodcaller

from DateTime import DateTime
from senaite import api
Expand Down Expand Up @@ -227,23 +228,21 @@ def ajax_save_reports(self):
pdf = publisher.write_pdf(report_node)
# get contained AR UIDs in this report
uids = filter(None, report_node.get("uids", "").split(","))
# get the AR objects
objs = map(api.get_object_by_uid, uids)
# sort the objects by created to have the most recent object first
# -> supersedes https://github.com/senaite/senaite.impress/pull/48
objs = sorted(objs, key=methodcaller("created"), reverse=True)
# remember generated report objects
reports = []

# fetch the objects rendered in the report by their UID
# N.B. we use the reversed order to have the primary AR first
for uid in reversed(uids):
obj = api.get_object_by_uid(uid, None)
if obj is None:
logger.warn("!!!No object found for UID {}!!!".format(uid))
continue

for obj in objs:
# TODO: refactor to adapter
# Create a report object which holds the generated PDF
title = "Report-{}".format(obj.getId())
report = api.create(obj, "ARReport", title=title)
report.edit(
AnalysisRequest=uid,
AnalysisRequest=api.get_uid(obj),
Pdf=pdf,
Html=publisher.to_html(report_node),
ContainedAnalysisRequests=uids,
Expand Down