Passed
Push — master ( 6ac657...5de4b7 )
by Jordi
06:03
created

bika.lims.browser.calcs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ajaxGetMethodCalculation.__call__() 0 11 4
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
import json
9
10
import plone
11
from Products.CMFCore.utils import getToolByName
12
from bika.lims.browser import BrowserView
13
14
15
class ajaxGetMethodCalculation(BrowserView):
16
    """ Returns the calculation assigned to the defined method.
17
        uid: unique identifier of the method
18
    """
19
    def __call__(self):
20
        plone.protect.CheckAuthenticator(self.request)
21
        calcdict = {}
22
        uc = getToolByName(self, 'uid_catalog')
23
        method = uc(UID=self.request.get("uid", '0'))
24
        if method and len(method) == 1:
25
            calc = method[0].getObject().getCalculation()
26
            if calc:
27
                calcdict = {'uid': calc.UID(),
28
                            'title': calc.Title()}
29
        return json.dumps(calcdict)
30