Passed
Push — master ( 4afe30...fc8a25 )
by Jordi
05:34 queued 52s
created

bika.lims.browser.analysisrequest.resultsinterpretation   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 34
dl 0
loc 60
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A ARResultsInterpretationView.__init__() 0 3 1
A ARResultsInterpretationView.handle_form_submit() 0 9 1
A ARResultsInterpretationView.get_text() 0 8 2
A ARResultsInterpretationView.add_status_message() 0 4 1
A ARResultsInterpretationView.is_edit_allowed() 0 5 1
A ARResultsInterpretationView.__call__() 0 4 2
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