• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / zc.form / 16248976557

21 Oct 2024 07:16AM UTC coverage: 82.759%. Remained the same
16248976557

push

github

icemac
Back to development: 2.2

126 of 180 branches covered (70.0%)

Branch coverage included in aggregate %.

786 of 922 relevant lines covered (85.25%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.98
/src/zc/form/interfaces.py
1
##############################################################################
2
#
3
# Copyright (c) 2003-2005 Zope Foundation and Contributors.
4
# All Rights Reserved.
5
#
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14
import datetime
1✔
15

16
import pytz
1✔
17

18
import zope.browser.interfaces
1✔
19
import zope.publisher.interfaces.browser
1✔
20
import zope.schema.interfaces
1✔
21
from zope import component
1✔
22
from zope import interface
1✔
23
from zope import schema
1✔
24

25
from zc.form.i18n import _
1✔
26

27

28
class IExtendedField(zope.schema.interfaces.IField):
1✔
29

30
    constraints = schema.Tuple(
1✔
31
        title=_("Constraints"),
32
        description=_("""A tuple of callables taking the combination field
33
        and the value, that should raise an exception if the values do not
34
        match the constraint.  Can assume that value is not the missing_value,
35
        and has a len equal to the number of sub-fields."""))
36

37
    def default_getter(context):
1✔
38
        """Return the default value."""
39

40
    default = interface.Attribute(
1✔
41
        """if default_getter has been set, returns the result of that call;
42
        otherwise returns whatever value has been set as the default.""")
43

44

45
class IOptionField(IExtendedField):
1✔
46
    """Field with excatly one predefined value
47

48
    Caution: The value will not get displayed by the widget of this field.
49
    """
50

51
    value = interface.Attribute(
1✔
52
        """the value for this field; one and only one of value and
53
        value_getter must be non-None""")
54

55
    value_getter = interface.Attribute(
1✔
56
        """a callable, taking a context, return the option's value; or None.
57
        one and only one of value and value_getter must be non-None""")
58

59
    identity_comparison = schema.Bool(
1✔
60
        description=_("""Whether validation comparison should be identity
61
        (as opposed to equality) based"""))
62

63
    def getValue():
1✔
64
        """Return value for option field."""
65

66

67
class IUnionField(IExtendedField):
1✔
68
    """A field that may have one of many field types of values.
69

70
    Order is important, in that the first field from left to right that
71
    validates a value is considered to be the "active" field.
72
    """
73

74
    fields = schema.Tuple(
1✔
75
        title=_("Composite Fields"),
76
        description=_("""\
77
            The possible schema fields that may describe the data"""))
78

79
    use_default_for_not_selected = schema.Bool(
1✔
80
        description=_(
81
            """When displaying the Union field in the browser the fields
82
            which are not selected will have no value (i. e. the field's
83
            missing_value.
84

85
            With this attribute set the default value of the field will
86
            be displayed instead.
87

88
            Default: False"""))
89

90
    def validField(value):
1✔
91
        """Return first valid field for the given value, or None"""
92

93

94
class ICombinationField(IExtendedField):
1✔
95
    """A field that describes a combination of two or more fields"""
96

97
    fields = schema.Tuple(
1✔
98
        title=_("Composite Fields"),
99
        description=_("""\
100
            The schema fields that may describe the data"""))
101

102

103
class IExtendedTextLineField(IExtendedField, zope.schema.interfaces.ITextLine):
1✔
104
    """TextLine field extended with IExtendedField capabilities"""
105

106

107
@interface.implementer(zope.schema.interfaces.ISource)
1✔
108
class AvailableTimeZones:
1✔
109

110
    def __contains__(self, value):
1✔
111
        return isinstance(value, datetime.tzinfo)
×
112

113

114
@interface.implementer(zope.schema.interfaces.ITitledTokenizedTerm)
1✔
115
class Term:
1✔
116

117
    def __init__(self, title, token):
1✔
118
        self.title = title
×
119
        self.token = token
×
120

121

122
@component.adapter(AvailableTimeZones,
1✔
123
                   zope.publisher.interfaces.browser.IBrowserRequest)
124
@interface.implementer(zope.browser.interfaces.ITerms)
1✔
125
class TimeZoneTerms:
1✔
126
    """Term and value support needed by query widgets."""
127

128
    def __init__(self, source, request):
1✔
129
        self.request = request
×
130

131
    def getTerm(self, value):
1✔
132
        token = value.zone
×
133
        title = token.replace('_', ' ')
×
134
        return Term(title, token)
×
135

136
    def getValue(self, token):
1✔
137
        return pytz.timezone(token)
×
138

139

140
class IHTMLSnippet(zope.schema.interfaces.IText):
1✔
141
    """HTML excerpt that can be placed within an HTML document's body element.
142

143
    Snippet should have no dangling open tags.
144

145
    XHTML preferred; field may have version attribute in future.
146
    """
147

148

149
class IHTMLDocument(zope.schema.interfaces.IText):
1✔
150
    """HTML Document.
151

152
    XHTML preferred; field may have version attribute in future.
153
    """
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc