Passed
Push — master ( 6d6a8c...6374c8 )
by Ramon
05:17
created

bika.lims.browser.analyses.late.LateAnalysesView.isItemAllowed()   A

Complexity

Conditions 3

Size

Total Lines 31
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 31
rs 10
c 0
b 0
f 0
cc 3
nop 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 AccessControl import getSecurityManager
9
from DateTime import DateTime
10
from Products.CMFCore.utils import getToolByName
11
from bika.lims import api
12
from bika.lims import bikaMessageFactory as _
13
from bika.lims.utils import t
14
from bika.lims.browser.bika_listing import BikaListingView
15
from bika.lims.utils import isActive
16
from zope.component import getMultiAdapter
17
import plone
18
19
class LateAnalysesView(BikaListingView):
20
    """ Late analyses (click from portlet_late_analyses More... link)
21
    """
22
    def __init__(self, context, request):
23
        super(LateAnalysesView, self).__init__(context, request)
24
        self.catalog = 'bika_analysis_catalog'
25
        self.contentFilter = {
26
            'portal_type':'Analysis',
27
            'getDueDate': {'query': [DateTime(),], 'range': 'max'},
28
            'review_state':['assigned',
29
                            'unassigned',
30
                            'to_be_verified',
31
                            'verified'],
32
            'cancellation_state': 'active',
33
            'sort_on': 'getDateReceived'
34
        }
35
        self.title = self.context.translate(_("Late Analyses"))
36
        self.description = ""
37
        self.context_actions = {}
38
39
        self.show_select_row = False
40
        self.show_select_column = False
41
        self.pagesize = 100
42
        self.show_workflow_action_buttons = False
43
        self.view_url = self.view_url + "/late_analyses"
44
45
        request.set('disable_border', 1)
46
47
        self.columns = {'Analysis': {'title': _('Analysis'),
48
                                     'index': 'sortable_title'},
49
                        'getRequestID': {'title': _('Request ID'),
50
                                         'index': 'getRequestID'},
51
                        'Client': {'title': _('Client')},
52
                        'Contact': {'title': _('Contact')},
53
                        'DateReceived': {'title': _('Date Received'),
54
                                         'index': 'getDateReceived'},
55
                        'DueDate': {'title': _('Due Date'),
56
                                    'index': 'getDueDate'},
57
                        'Late': {'title': _('Late')},
58
                        }
59
60
        self.review_states = [
61
            {'id':'default',
62
             'title': _('All'),
63
             'contentFilter':{},
64
             'columns':['Analysis',
65
                        'getRequestID',
66
                        'Client',
67
                        'Contact',
68
                        'DateReceived',
69
                        'DueDate',
70
                        'Late'],
71
             },
72
        ]
73
74
    def folderitems(self):
75
        items = super(LateAnalysesView, self).folderitems()
76
        mtool = getToolByName(self.context, 'portal_membership')
77
        member = mtool.getAuthenticatedMember()
78
        roles = member.getRoles()
79
        hideclientlink = 'RegulatoryInspector' in roles \
80
            and 'Manager' not in roles \
81
            and 'LabManager' not in roles \
82
            and 'LabClerk' not in roles
83
84
        for x in range(len(items)):
85
            if not items[x].has_key('obj'):
86
                continue
87
            obj = items[x]['obj']
88
            ar = obj.aq_parent
89
            sample = ar.getSample()
90
            client = ar.aq_parent
91
            contact = ar.getContact()
92
            items[x]['Analysis'] = obj.Title()
93
            items[x]['getRequestID'] = ''
94
            items[x]['replace']['getRequestID'] = "<a href='%s'>%s</a>" % \
95
                 (ar.absolute_url(), ar.Title())
96
            items[x]['Client'] = ''
97
            if hideclientlink == False:
98
                items[x]['replace']['Client'] = "<a href='%s'>%s</a>" % \
99
                     (client.absolute_url(), client.Title())
100
            items[x]['Contact'] = ''
101
            if contact:
102
                items[x]['replace']['Contact'] = "<a href='mailto:%s'>%s</a>" % \
103
                                                 (contact.getEmailAddress(),
104
                                                  contact.getFullname())
105
            items[x]['DateReceived'] = self.ulocalized_time(sample.getDateReceived())
106
            items[x]['DueDate'] = self.ulocalized_time(obj.getDueDate())
107
            items[x]['Late'] = api.to_dhm_format(obj.getLateness())
108
        return items
109