Passed
Push — 2.x ( 4f65d0...ad582b )
by Jordi
06:22
created

ContactsView.__init__()   B

Complexity

Conditions 1

Size

Total Lines 72
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 72
rs 8.7018
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-2024 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
import collections
22
23
from bika.lims import api
24
from bika.lims import senaiteMessageFactory as _
25
from bika.lims.utils import get_link
26
from senaite.core.i18n import translate
27
from senaite.app.listing import ListingView
28
from senaite.core.catalog import CONTACT_CATALOG
29
30
31
class ContactsView(ListingView):
32
    """Supplier Contacts
33
    """
34
35
    def __init__(self, context, request):
36
        super(ContactsView, self).__init__(context, request)
37
38
        self.catalog = CONTACT_CATALOG
39
40
        self.contentFilter = {
41
            "portal_type": "SupplierContact",
42
            "sort_on": "sortable_title",
43
            "sort_order": "ascending",
44
            "path": {
45
                "query": "/".join(context.getPhysicalPath()),
46
                "level": 0,
47
            }
48
        }
49
50
        self.context_actions = {
51
            _("listing_suppliercontacts_action_add", default="Add"): {
52
                "url": "createObject?type_name=SupplierContact",
53
                "permission": "Add portal content",
54
                "icon": "senaite_theme/icon/plus"
55
            }
56
        }
57
58
        self.title = translate(_(
59
            "listing_suppliercontacts_title",
60
            default="Contacts")
61
        )
62
        self.icon = api.get_icon("Contact", html_tag=False)
63
        self.show_select_column = True
64
65
        self.columns = collections.OrderedDict((
66
            ("getFullname", {
67
                "title": _(
68
                    u"listing_suppliercontacts_column_fullname",
69
                    default=u"FullName"
70
                )
71
            }),
72
            ("getEmailAddress", {
73
                "title": _(
74
                    u"listing_suppliercontacts_column_emailaddress",
75
                    default=u"Email Address"
76
                )
77
            }),
78
            ("getBusinessPhone", {
79
                "title": _(
80
                    u"listing_suppliercontacts_column_businessphone",
81
                    default=u"Business Phone"
82
                )
83
            }),
84
            ("getMobilePhone", {
85
                "title": _(
86
                    u"listing_suppliercontacts_column_mobilephone",
87
                    default=u"Mobile Phone"
88
                )
89
            }),
90
            ("getFax", {
91
                "title": _(
92
                    u"listing_suppliercontacts_column_fax",
93
                    default=u"Fax"
94
                )
95
            }),
96
        ))
97
98
        self.review_states = [
99
            {
100
                "id": "default",
101
                "title": _(
102
                    u"listing_suppliercontacts_state_all",
103
                    default=u"All"
104
                ),
105
                "contentFilter": {},
106
                "columns": self.columns.keys(),
107
            },
108
        ]
109
110
    def folderitem(self, obj, item, index):
111
        obj = api.get_object(obj)
112
        name = obj.getFullname()
113
        url = obj.absolute_url()
114
115
        item["replace"]["getFullname"] = get_link(url, value=name)
116
117
        return item
118