• 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/objectwidget.py
1
##############################################################################
2
#
3
# Copyright (c) 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
"""Five-compatible version of ObjectWidget
15

16
This is needed because ObjectWidget uses ViewPageTemplateFile whose
17
macro definition is unfortunately incompatible with ZopeTwoPageTemplateFile.
18
So this subclass uses ZopeTwoPageTemplateFile for the template that renders
19
the widget's sub-editform.
20
"""
21
from AccessControl.class_init import InitializeClass
1✔
22
from AccessControl.SecurityInfo import ClassSecurityInfo
1✔
23
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
1✔
24
from zope.formlib.objectwidget import ObjectWidget as OWBase
1✔
25
from zope.formlib.objectwidget import ObjectWidgetView as OWVBase
1✔
26

27

28
class ObjectWidgetView(OWVBase):
1✔
29
    security = ClassSecurityInfo()
1✔
30
    security.declareObjectPublic()
1✔
31

32
    template = ViewPageTemplateFile('objectwidget.pt')
1✔
33

34

35
InitializeClass(ObjectWidgetView)
1✔
36

37

38
class ObjectWidgetClass(OWBase):
1✔
39

40
    def setRenderedValue(self, value):
1✔
41
        """Slightly more robust re-implementation this method."""
42
        # re-call setupwidgets with the content
43
        self._setUpEditWidgets()
1✔
44
        for name in self.names:
1✔
45
            val = getattr(value, name, None)
1✔
46
            if val is None:
1✔
47
                # this is where we are more robust than Zope 3.2's
48
                # object widget: we supply subwidgets with the default
49
                # from the schema, not None (Zope 3.2's list widget
50
                # breaks when the rendered value is None)
51
                val = self.context.schema[name].default
1✔
52
            self.getSubWidget(name).setRenderedValue(val)
1✔
53

54

55
ObjectWidget = ObjectWidgetClass
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