• 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

100.0
/src/five/formlib/formbase.py
1
##############################################################################
2
#
3
# Copyright (c) 2006 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
"""Five baseclasses for zope.formlib.form
15
"""
16
import os.path
1✔
17

18
import zope.formlib
1✔
19
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
1✔
20
from zope import interface
1✔
21
from zope.formlib import form
1✔
22
from zope.formlib import interfaces
1✔
23
from zope.i18nmessageid import MessageFactory
1✔
24
from ZPublisher import HTTPRequest
1✔
25

26

27
_ = MessageFactory("zope")
1✔
28

29
_FORMLIB_DIR = os.path.dirname(zope.formlib.__file__)
1✔
30
_PAGEFORM_PATH = os.path.join(_FORMLIB_DIR, 'pageform.pt')
1✔
31
_SUBPAGEFORM_PATH = os.path.join(_FORMLIB_DIR, 'subpageform.pt')
1✔
32

33

34
class FiveFormlibMixin:
1✔
35

36
    # Overrides the formlib.form.FormBase.template attributes implemented
37
    # using NamedTemplates. NamedTemplates using ViewPageTemplateFile (like
38
    # formlib does by default) cannot work in Zope2.
39

40
    # XXX Maybe we need to have Five-compatible NamedTemplates?
41

42
    template = ViewPageTemplateFile(_PAGEFORM_PATH)
1✔
43

44
    # Overrides formlib.form.FormBase.update. Make sure user input is
45
    # decoded first and the page encoding is set before proceeding.
46

47
    def update(self):
1✔
48
        # BBB: for CMFDefault < 2.3 (explicit charset required)
49
        self.request.RESPONSE.setHeader(
1✔
50
            'Content-Type',
51
            'text/html; charset=%s' % HTTPRequest.default_encoding
52
        )
53
        super().update()
1✔
54

55

56
class FormBase(FiveFormlibMixin, form.FormBase):
1✔
57
    pass
1✔
58

59

60
class EditFormBase(FiveFormlibMixin, form.EditFormBase):
1✔
61
    pass
1✔
62

63

64
class DisplayFormBase(FiveFormlibMixin, form.DisplayFormBase):
1✔
65
    pass
1✔
66

67

68
class AddFormBase(FiveFormlibMixin, form.AddFormBase):
1✔
69
    pass
1✔
70

71

72
@interface.implementer(interfaces.IPageForm)
1✔
73
class PageForm(FormBase):
1✔
74
    pass
1✔
75

76

77
Form = PageForm
1✔
78

79

80
@interface.implementer(interfaces.IPageForm)
1✔
81
class PageEditForm(EditFormBase):
1✔
82
    pass
1✔
83

84

85
EditForm = PageEditForm
1✔
86

87

88
@interface.implementer(interfaces.IPageForm)
1✔
89
class PageDisplayForm(DisplayFormBase):
1✔
90
    pass
1✔
91

92

93
DisplayForm = PageDisplayForm
1✔
94

95

96
@interface.implementer(interfaces.IPageForm)
1✔
97
class PageAddForm(AddFormBase):
1✔
98
    pass
1✔
99

100

101
AddForm = PageAddForm
1✔
102

103

104
@interface.implementer(interfaces.ISubPageForm)
1✔
105
class SubPageForm(FormBase):
1✔
106

107
    template = ViewPageTemplateFile(_SUBPAGEFORM_PATH)
1✔
108

109

110
@interface.implementer(interfaces.ISubPageForm)
1✔
111
class SubPageEditForm(EditFormBase):
1✔
112

113
    template = ViewPageTemplateFile(_SUBPAGEFORM_PATH)
1✔
114

115

116
@interface.implementer(interfaces.ISubPageForm)
1✔
117
class SubPageDisplayForm(DisplayFormBase):
1✔
118

119
    template = ViewPageTemplateFile(_SUBPAGEFORM_PATH)
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