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

zopefoundation / z3c.form / 16248976312

02 Jul 2025 05:53AM UTC coverage: 95.275%. Remained the same
16248976312

push

github

icemac
Back to development: 6.1

717 of 800 branches covered (89.63%)

Branch coverage included in aggregate %.

3699 of 3835 relevant lines covered (96.45%)

0.96 hits per line

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

91.18
/src/z3c/form/browser/image.py
1
##############################################################################
2
#
3
# Copyright (c) 2007 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
"""Submit Widget Implementation
15

16
$Id$
17
"""
18
__docformat__ = "reStructuredText"
1✔
19
import zope.component
1✔
20
import zope.interface
1✔
21
import zope.traversing.api
1✔
22
from zope.component import hooks
1✔
23
from zope.schema.fieldproperty import FieldProperty
1✔
24

25
from z3c.form import interfaces
1✔
26
from z3c.form import util
1✔
27
from z3c.form.browser import button
1✔
28
from z3c.form.browser.interfaces import IHTMLImageWidget
1✔
29
from z3c.form.widget import FieldWidget
1✔
30

31

32
@zope.interface.implementer_only(interfaces.IImageWidget)
1✔
33
class ImageWidget(button.ButtonWidget):
1✔
34
    """A image button of a form."""
35

36
    src = FieldProperty(IHTMLImageWidget['src'])
1✔
37

38
    klass = 'image-widget'
1✔
39
    css = 'image'
1✔
40

41
    def extract(self, default=interfaces.NO_VALUE):
1✔
42
        """See z3c.form.interfaces.IWidget."""
43
        if self.name + '.x' not in self.request:
1✔
44
            return default
1✔
45
        return {
1✔
46
            'x': int(self.request[self.name + '.x']),
47
            'y': int(self.request[self.name + '.y']),
48
            'value': self.request[self.name]}
49

50
    def json_data(self):
1✔
51
        data = super().json_data()
×
52
        data['type'] = 'image'
×
53
        return data
×
54

55

56
@zope.component.adapter(interfaces.IImageButton, interfaces.IFormLayer)
1✔
57
@zope.interface.implementer(interfaces.IFieldWidget)
1✔
58
def ImageFieldWidget(field, request):
1✔
59
    image = FieldWidget(field, ImageWidget(request))
1✔
60
    image.value = field.title
1✔
61
    # Get the full resource URL for the image:
62
    site = hooks.getSite()
1✔
63
    image.src = util.toUnicode(zope.traversing.api.traverse(
1✔
64
        site, '++resource++' + field.image, request=request)())
65
    return image
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