Passed
Push — 2.x ( a7f0a0...02ca02 )
by Jordi
07:10
created

WeekdaysVocabulary.__call__()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nop 2
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 bika.lims import _
22
from senaite.core.api import geo
23
from zope.i18n.locales import locales
24
from zope.interface import implementer
25
from zope.schema.interfaces import IVocabularyFactory
26
from zope.schema.vocabulary import SimpleVocabulary
27
28
29
@implementer(IVocabularyFactory)
30
class CurrenciesVocabulary(object):
31
    """Vocabulary of currencies
32
    """
33
34
    def __call__(self, context):
35
        locale = locales.getLocale("en", "US")
36
        currencies = locale.numbers.currencies.values()
37
        items = [(c.type, c.type, u"{} ({})".format(c.displayName, c.symbol))
38
                 for c in currencies]
39
        items.sort(key=lambda x: x[2])
40
        return SimpleVocabulary.fromItems(items)
41
42
43
@implementer(IVocabularyFactory)
44
class CountriesVocabulary(object):
45
    """Vocabulary of countries
46
    """
47
48
    def __call__(self, context):
49
        countries = geo.get_countries()
50
        items = [(country.alpha_2, country.alpha_2, country.name)
51
                 for country in countries]
52
        return SimpleVocabulary.fromItems(items)
53
54
55
@implementer(IVocabularyFactory)
56
class DecimalMarksVocabulary(object):
57
    """Vocabulary of decimal marks
58
    """
59
60
    def __call__(self, context):
61
        items = [
62
            (".", ".", _(u"Dot (.)")),
63
            (",", ",", _(u"Comma (,)")),
64
        ]
65
        return SimpleVocabulary.fromItems(items)
66
67
68
@implementer(IVocabularyFactory)
69
class ScientificNotationVocabulary(object):
70
    """Vocabulary of scientific notation options
71
    """
72
73
    def __call__(self, context):
74
        items = [
75
            ("1", "1", u"aE+b / aE-b"),
76
            ("2", "2", u"ax10^b / ax10^-b"),
77
            ("3", "3", u"ax10^b / ax10^-b (with superscript)"),
78
            ("4", "4", u"a·10^b / a·10^-b"),
79
            ("5", "5", u"a·10^b / a·10^-b (with superscript)"),
80
        ]
81
        return SimpleVocabulary.fromItems(items)
82
83
84
@implementer(IVocabularyFactory)
85
class WorksheetLayoutVocabulary(object):
86
    """Vocabulary of worksheet layout options
87
    """
88
89
    def __call__(self, context):
90
        items = [
91
            ("analyses_classic_view", "analyses_classic_view", _(u"Classic")),
92
            ("analyses_transposed_view", "analyses_transposed_view",
93
             _(u"Transposed")),
94
        ]
95
        return SimpleVocabulary.fromItems(items)
96
97
98
@implementer(IVocabularyFactory)
99
class WeekdaysVocabulary(object):
100
    """Vocabulary of weekdays
101
    """
102
103
    def __call__(self, context):
104
        items = [
105
            ("0", "0", _(u"Monday")),
106
            ("1", "1", _(u"Tuesday")),
107
            ("2", "2", _(u"Wednesday")),
108
            ("3", "3", _(u"Thursday")),
109
            ("4", "4", _(u"Friday")),
110
            ("5", "5", _(u"Saturday")),
111
            ("6", "6", _(u"Sunday")),
112
        ]
113
        return SimpleVocabulary.fromItems(items)
114
115
116
@implementer(IVocabularyFactory)
117
class MultiVerificationTypeVocabulary(object):
118
    """Vocabulary of multi-verification types
119
    """
120
121
    def __call__(self, context):
122
        items = [
123
            ("self_multi_enabled", "self_multi_enabled",
124
             _(u"Allow same user to verify multiple times")),
125
            ("self_multi_not_cons", "self_multi_not_cons",
126
             _(u"Allow same user to verify multiple times, "
127
               u"but not consecutively")),
128
            ("self_multi_disabled", "self_multi_disabled",
129
             _(u"Disable multi-verification for the same user")),
130
        ]
131
        return SimpleVocabulary.fromItems(items)
132
133
134
@implementer(IVocabularyFactory)
135
class NumberOfVerificationsVocabulary(object):
136
    """Vocabulary for number of required verifications
137
    """
138
139
    def __call__(self, context):
140
        items = [(1, 1, u"1"), (2, 2, u"2"), (3, 3, u"3"), (4, 4, u"4")]
141
        return SimpleVocabulary.fromItems(items)
142
143
144
# Factory instances
145
CurrenciesVocabularyFactory = CurrenciesVocabulary()
146
CountriesVocabularyFactory = CountriesVocabulary()
147
DecimalMarksVocabularyFactory = DecimalMarksVocabulary()
148
ScientificNotationVocabularyFactory = ScientificNotationVocabulary()
149
WorksheetLayoutVocabularyFactory = WorksheetLayoutVocabulary()
150
WeekdaysVocabularyFactory = WeekdaysVocabulary()
151
MultiVerificationTypeVocabularyFactory = MultiVerificationTypeVocabulary()
152
NumberOfVerificationsVocabularyFactory = NumberOfVerificationsVocabulary()
153