Passed
Push — 2.x ( 2a1b20...d626d0 )
by Jordi
07:27
created

ClientContactsView.__init__()   B

Complexity

Conditions 1

Size

Total Lines 57
Code Lines 50

Duplication

Lines 57
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 50
dl 57
loc 57
rs 8.6363
c 0
b 0
f 0
cc 1
nop 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE.
4
#
5
# SENAITE.CORE is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free Software
7
# Foundation, version 2.
8
#
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
# details.
13
#
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 51
16
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
#
18
# Copyright 2018-2025 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from collections import OrderedDict
22
23
from bika.lims import api
24
from bika.lims import bikaMessageFactory as _
25
from bika.lims.browser.bika_listing import BikaListingView
26
from bika.lims.utils import get_email_link
27
from bika.lims.utils import get_link
28
from bika.lims.vocabularies import CatalogVocabulary
29
from senaite.core.catalog import CONTACT_CATALOG
30
from senaite.core.interfaces import IContacts
31
from zope.interface import implements
32
33
34
class ClientContactsView(BikaListingView):
35
    """Client Contacts listing view
36
    """
37
    implements(IContacts)
38
39 View Code Duplication
    def __init__(self, context, request):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
40
        super(ClientContactsView, self).__init__(context, request)
41
        self.catalog = CONTACT_CATALOG
42
        self.contentFilter = {
43
            "portal_type": "Contact",
44
            "sort_on": "sortable_title",
45
            "path": {
46
                "query": "/".join(context.getPhysicalPath()),
47
                "level": 0
48
            }
49
        }
50
        self.context_actions = {
51
            _("Add"):
52
                {"url": "++add++Contact",
53
                 "permission": "Add portal content",
54
                 "icon": "++resource++bika.lims.images/add.png"}}
55
56
        self.show_select_row = False
57
        self.show_select_column = True
58
        self.pagesize = 50
59
        self.form_id = "contacts"
60
61
        self.icon = self.portal_url + \
62
                    "/++resource++bika.lims.images/client_contact_big.png"
63
        self.title = self.context.translate(_("Contacts"))
64
        self.description = ""
65
66
        self.columns = OrderedDict((
67
            ("getFullname", {
68
                "title": _("Full Name"),
69
                "index": "getFullname",
70
                "sortable": True, }),
71
            ("Username", {
72
                "title": _("User Name"), }),
73
            ("getEmailAddress", {
74
                "title": _("Email Address"), }),
75
            ("getBusinessPhone", {
76
                "title": _("Business Phone"), }),
77
            ("getMobilePhone", {
78
                "title": _("MobilePhone"), }),
79
        ))
80
81
        self.review_states = [
82
            {"id": "default",
83
             "title": _("Active"),
84
             "contentFilter": {"is_active": True},
85
             "transitions": [{"id": "deactivate"}, ],
86
             "columns": self.columns.keys()},
87
            {"id": "inactive",
88
             "title": _("Inactive"),
89
             "contentFilter": {"is_active": False},
90
             "transitions": [{"id": "activate"}, ],
91
             "columns": self.columns.keys()},
92
            {"id": "all",
93
             "title": _("All"),
94
             "contentFilter": {},
95
             "columns": self.columns.keys()},
96
        ]
97
98
    def folderitem(self, obj, item, index):
99
        obj = api.get_object(obj)
100
        url = item.get("url")
101
        email = obj.getEmailAddress()
102
        fullname = obj.getFullname()
103
        item["getFullname"] = fullname
104
        item["getEmailAddress"] = email
105
        item["getBusinessPhone"] = obj.getBusinessPhone()
106
        item["getMobilePhone"] = obj.getMobilePhone()
107
        item["Username"] = obj.getUsername() or ""
108
        item["replace"]["getFullname"] = get_link(url, fullname)
109
        if email:
110
            item["replace"]["getEmailAddress"] = get_email_link(email)
111
        return item
112
113
114
class ClientContactVocabularyFactory(CatalogVocabulary):
115
    """Vocabulary factory for client contacts
116
    """
117
    def __call__(self):
118
        return super(ClientContactVocabularyFactory, self).__call__(
119
            portal_type="Contact",
120
            path={"query": "/".join(self.context.getPhysicalPath()),
121
                  "level": 0}
122
        )
123