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

zopefoundation / five.formlib / 16399733854

15 Feb 2025 02:34PM UTC coverage: 83.302%. Remained the same
16399733854

push

github

icemac
Back to development: 5.1

49 of 92 branches covered (53.26%)

Branch coverage included in aggregate %.

390 of 435 relevant lines covered (89.66%)

0.9 hits per line

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

95.92
/src/five/formlib/tests/schemacontent.py
1
##############################################################################
2
#
3
# Copyright (c) 2004, 2005 Zope Corporation 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

15
from AccessControl.class_init import InitializeClass
1✔
16
from OFS.SimpleItem import SimpleItem
1✔
17
from zope.formlib.widget import CustomWidgetFactory
1✔
18
from zope.i18nmessageid import MessageFactory
1✔
19
from zope.interface import Interface
1✔
20
from zope.interface import implementer
1✔
21
from zope.schema import Int
1✔
22
from zope.schema import List
1✔
23
from zope.schema import Object
1✔
24
from zope.schema import Text
1✔
25
from zope.schema import TextLine
1✔
26

27
from five.formlib.objectwidget import ObjectWidget
1✔
28

29

30
_ = MessageFactory('formtest')
1✔
31

32

33
class IFieldContent(Interface):
1✔
34

35
    title = TextLine(
1✔
36
        title=_("Title"),
37
        description=_("A short description of the event."),
38
        default="",
39
        required=True
40
    )
41

42
    description = Text(
1✔
43
        title=_("Description"),
44
        description=_("A long description of the event."),
45
        default="",
46
        required=False
47
    )
48

49
    somenumber = Int(
1✔
50
        title=_("Some number"),
51
        default=0,
52
        required=False
53
    )
54

55
    somelist = List(
1✔
56
        title=_("Some List"),
57
        value_type=TextLine(title=_("Some item")),
58
        default=[],
59
        required=False
60
    )
61

62

63
@implementer(IFieldContent)
1✔
64
class FieldContent(SimpleItem):
1✔
65
    """A Viewable piece of content with fields"""
66
    meta_type = 'Five FieldContent'
1✔
67

68
    def __init__(self, id, title):
1✔
69
        self.id = id
1✔
70
        self.title = title
1✔
71

72

73
InitializeClass(FieldContent)
1✔
74

75

76
def manage_addFieldContent(self, id, title, REQUEST=None):
1✔
77
    """Add the field content"""
78
    id = self._setObject(id, FieldContent(id, title))
×
79
    return ''
×
80

81

82
class IComplexSchemaContent(Interface):
1✔
83

84
    fishtype = TextLine(
1✔
85
        title="Fish type",
86
        description="The type of fish",
87
        default="It was a lovely little fish. And it went wherever I did go.",
88
        required=False)
89

90
    fish = Object(
1✔
91
        title="Fish",
92
        schema=IFieldContent,
93
        description="The fishy object",
94
        required=True)
95

96

97
@implementer(IComplexSchemaContent)
1✔
98
class ComplexSchemaContent(SimpleItem):
1✔
99
    meta_type = "Five ComplexSchemaContent"
1✔
100

101
    def __init__(self, id):
1✔
102
        self.id = id
1✔
103
        self.fish = FieldContent('fish', 'title')
1✔
104
        self.fish.description = ""
1✔
105
        self.fishtype = 'Lost fishy'
1✔
106

107

108
class ComplexSchemaView:
1✔
109
    """Needs a docstring"""
110

111
    fish_widget = CustomWidgetFactory(ObjectWidget, FieldContent)
1✔
112

113

114
InitializeClass(ComplexSchemaContent)
1✔
115

116

117
def manage_addComplexSchemaContent(self, id, REQUEST=None):
1✔
118
    """Add the complex schema content"""
119
    id = self._setObject(id, ComplexSchemaContent(id))
1✔
120
    return ''
1✔
121

122

123
def modifiedSubscriber(content, ev):
1✔
124
    """A simple event handler, which sets a flag on the object"""
125
    content._modified_flag = True
1✔
126

127

128
def createdSubscriber(content, ev):
1✔
129
    """A simple event handler, which sets a flag on the object"""
130
    content._created_flag = True
1✔
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