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

zopefoundation / z3c.form / 5104192483

pending completion
5104192483

push

github

web-flow
Config with pure python template (#114)

* Bumped version for breaking release.

* Drop support for Python 2.7, 3.5, 3.6.

* Add support for Python 3.11.

1316 of 1408 branches covered (93.47%)

Branch coverage included in aggregate %.

420 of 420 new or added lines in 39 files covered. (100.0%)

3716 of 3838 relevant lines covered (96.82%)

0.97 hits per line

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

96.23
/src/z3c/form/zcml.py
1
##############################################################################
2
#
3
# Copyright (c) 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
"""
1✔
15
$Id$
16
"""
17
__docformat__ = "reStructuredText"
1✔
18

19
import os
1✔
20

21
import zope.component.zcml
1✔
22
import zope.configuration.fields
1✔
23
import zope.interface
1✔
24
import zope.schema
1✔
25
from zope.configuration.exceptions import ConfigurationError
1✔
26
from zope.pagetemplate.interfaces import IPageTemplate
1✔
27
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
1✔
28

29
from z3c.form import interfaces
1✔
30
from z3c.form.i18n import MessageFactory as _
1✔
31
from z3c.form.object import ObjectWidgetTemplateFactory
1✔
32
from z3c.form.widget import WidgetLayoutFactory
1✔
33
from z3c.form.widget import WidgetTemplateFactory
1✔
34

35

36
class IWidgetTemplateDirective(zope.interface.Interface):
1✔
37
    """Parameters for the widget template directive."""
38

39
    template = zope.configuration.fields.Path(
1✔
40
        title=_('Layout template.'),
41
        description=_('Refers to a file containing a page template (should '
42
                      'end in extension ``.pt`` or ``.html``).'),
43
        required=True)
44

45
    mode = zope.schema.ASCIILine(
1✔
46
        title=_('The mode of the template.'),
47
        description=_('The mode is used to define input and display '
48
                      'templates'),
49
        default=interfaces.INPUT_MODE,
50
        required=False)
51

52
    for_ = zope.configuration.fields.GlobalObject(
1✔
53
        title=_('View'),
54
        description=_('The view for which the template should be available'),
55
        default=zope.interface.Interface,
56
        required=False)
57

58
    layer = zope.configuration.fields.GlobalObject(
1✔
59
        title=_('Layer'),
60
        description=_('The layer for which the template should be available'),
61
        default=IDefaultBrowserLayer,
62
        required=False)
63

64
    view = zope.configuration.fields.GlobalObject(
1✔
65
        title=_('View'),
66
        description=_('The view for which the template should be available'),
67
        default=zope.interface.Interface,
68
        required=False)
69

70
    field = zope.configuration.fields.GlobalObject(
1✔
71
        title=_('Field'),
72
        description=_('The field for which the template should be available'),
73
        default=zope.schema.interfaces.IField,
74
        required=False)
75

76
    widget = zope.configuration.fields.GlobalObject(
1✔
77
        title=_('View'),
78
        description=_('The widget for which the template should be available'),
79
        default=interfaces.IWidget,
80
        required=False)
81

82
    contentType = zope.schema.ASCIILine(
1✔
83
        title=_('Content Type'),
84
        description=_('The content type identifies the type of data.'),
85
        default='text/html',
86
        required=False)
87

88

89
class IObjectWidgetTemplateDirective(IWidgetTemplateDirective):
1✔
90
    schema = zope.configuration.fields.GlobalObject(
1✔
91
        title=_('Schema'),
92
        description=_('The schema of the field for which the template should'
93
                      ' be available'),
94
        default=zope.interface.Interface,
95
        required=False)
96

97

98
def widgetTemplateDirective(
1✔
99
        _context, template, for_=zope.interface.Interface,
100
        layer=IDefaultBrowserLayer, view=None, field=None, widget=None,
101
        mode=interfaces.INPUT_MODE, contentType='text/html'):
102

103
    # Make sure that the template exists
104
    template = os.path.abspath(str(_context.path(template)))
1✔
105
    if not os.path.isfile(template):
1✔
106
        raise ConfigurationError("No such file", template)
1✔
107

108
    factory = WidgetTemplateFactory(template, contentType)
1✔
109
    zope.interface.directlyProvides(factory, IPageTemplate)
1✔
110

111
    # register the template
112
    zope.component.zcml.adapter(_context, (factory,), IPageTemplate,
1✔
113
                                (for_, layer, view, field, widget), name=mode)
114

115

116
def widgetLayoutTemplateDirective(
1✔
117
        _context, template, for_=zope.interface.Interface,
118
        layer=IDefaultBrowserLayer, view=None, field=None, widget=None,
119
        mode=interfaces.INPUT_MODE, contentType='text/html'):
120

121
    # Make sure that the template exists
122
    template = os.path.abspath(str(_context.path(template)))
1✔
123
    if not os.path.isfile(template):
1!
124
        raise ConfigurationError("No such file", template)
×
125

126
    factory = WidgetLayoutFactory(template, contentType)
1✔
127
    zope.interface.directlyProvides(factory, interfaces.IWidgetLayoutTemplate)
1✔
128

129
    # register the template
130
    zope.component.zcml.adapter(
1✔
131
        _context,
132
        (factory,
133
         ),
134
        interfaces.IWidgetLayoutTemplate,
135
        (for_,
136
         layer,
137
         view,
138
         field,
139
         widget),
140
        name=mode)
141

142

143
def objectWidgetTemplateDirective(
1✔
144
        _context, template, for_=zope.interface.Interface,
145
        layer=IDefaultBrowserLayer, view=None, field=None, widget=None,
146
        schema=None,
147
        mode=interfaces.INPUT_MODE, contentType='text/html'):
148

149
    # Make sure that the template exists
150
    template = os.path.abspath(str(_context.path(template)))
1✔
151
    if not os.path.isfile(template):
1✔
152
        raise ConfigurationError("No such file", template)
1✔
153

154
    factory = ObjectWidgetTemplateFactory(template, contentType)
1✔
155
    zope.interface.directlyProvides(factory, IPageTemplate)
1✔
156

157
    # register the template
158
    zope.component.zcml.adapter(
1✔
159
        _context,
160
        (factory,
161
         ),
162
        IPageTemplate,
163
        (for_,
164
         layer,
165
         view,
166
         field,
167
         widget,
168
         schema),
169
        name=mode)
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