1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE |
4
|
|
|
# |
5
|
|
|
# Copyright 2018 by it's authors. |
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
7
|
|
|
|
8
|
|
|
from bika.lims import bikaMessageFactory as _ |
9
|
|
|
from bika.lims import logger |
10
|
|
|
from bika.lims.browser import BrowserView |
11
|
|
|
from plone import protect |
12
|
|
|
from plone.app.textfield import RichTextValue |
13
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class ARResultsInterpretationView(BrowserView): |
17
|
|
|
""" Renders the view for ResultsInterpration per Department |
18
|
|
|
""" |
19
|
|
|
template = ViewPageTemplateFile( |
20
|
|
|
"templates/analysisrequest_results_interpretation.pt") |
21
|
|
|
|
22
|
|
|
def __init__(self, context, request, **kwargs): |
23
|
|
|
super(ARResultsInterpretationView, self).__init__(context, request) |
24
|
|
|
self.context = context |
25
|
|
|
|
26
|
|
|
def __call__(self): |
27
|
|
|
if self.request.form.get("submitted", False): |
28
|
|
|
self.handle_form_submit() |
29
|
|
|
return self.template() |
30
|
|
|
|
31
|
|
|
def handle_form_submit(self): |
32
|
|
|
"""Handle form submission |
33
|
|
|
""" |
34
|
|
|
protect.CheckAuthenticator(self.request) |
35
|
|
|
logger.info("Handle ResultsInterpration Submit") |
36
|
|
|
# Save the results interpretation |
37
|
|
|
res = self.request.form.get("ResultsInterpretationDepts", []) |
38
|
|
|
self.context.setResultsInterpretationDepts(res) |
39
|
|
|
self.add_status_message(_("Changes Saved"), level="info") |
40
|
|
|
|
41
|
|
|
def add_status_message(self, message, level="info"): |
42
|
|
|
"""Set a portal status message |
43
|
|
|
""" |
44
|
|
|
return self.context.plone_utils.addPortalMessage(message, level) |
45
|
|
|
|
46
|
|
|
def is_edit_allowed(self): |
47
|
|
|
"""Check if edit is allowed |
48
|
|
|
""" |
49
|
|
|
checkPermission = self.context.portal_membership.checkPermission |
50
|
|
|
return checkPermission("Modify portal content", self.context) |
51
|
|
|
|
52
|
|
|
def get_text(self, department, mode="raw"): |
53
|
|
|
"""Returns the text saved for the selected department |
54
|
|
|
""" |
55
|
|
|
row = self.context.getResultsInterpretationByDepartment(department) |
56
|
|
|
rt = RichTextValue(row.get("richtext", ""), "text/plain", "text/html") |
57
|
|
|
if mode == "output": |
58
|
|
|
return rt.output |
59
|
|
|
return rt.raw |
60
|
|
|
|