Passed
Push — 2.x ( 7870b7...db7972 )
by Ramon
09:50
created

senaite.core.vocabularies.registry   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 27
dl 0
loc 60
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ClientLandingPagesVocabulary.__call__() 0 22 5
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-2023 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from zope.interface import implementer
22
from zope.schema.interfaces import IVocabularyFactory
23
from zope.schema.vocabulary import SimpleTerm
24
from zope.schema.vocabulary import SimpleVocabulary
25
from bika.lims import api
26
27
28
@implementer(IVocabularyFactory)
29
class ClientLandingPagesVocabulary(object):
30
    """Vocabulary factory for Client landing pages
31
    """
32
33
    skip = ["edit", "manage_access", "auditlog", ]
34
35
    def __call__(self, context):
36
        pt = api.get_tool("portal_types")
37
        type_info = pt.getTypeInfo("Client")
38
        terms = []
39
        for action in type_info.listActionInfos():
40
            if not action.get("visible", True):
41
                continue
42
            if action.get("id") in self.skip:
43
                continue
44
            url = action.get("url")
45
            if not url:
46
                continue
47
48
            # remove leading/trailing slashes
49
            url = url.strip("/")
50
51
            # create the vocab term
52
            title = action.get("title")
53
            term = SimpleTerm(url, url, title)
54
            terms.append(term)
55
56
        return SimpleVocabulary(terms)
57
58
59
ClientLandingPagesVocabularyFactory = ClientLandingPagesVocabulary()
60