/usr/share/pyshared/zope/app/rotterdam/editingwidgets.py is in python-zope.app.rotterdam 3.5.3-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Custom Widgets for the rotterdam layer.
"""
__docformat__ = 'restructuredtext'
from zope.interface import implements
from zope.app.form.interfaces import IInputWidget
from zope.app.form.browser import TextAreaWidget
from zope.app.form.browser.widget import renderElement, escape
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
class SimpleEditingWidget(TextAreaWidget):
"""Improved textarea editing, with async saving using JavaScript.
Multi-line text (unicode) input.
>>> from zope.publisher.browser import TestRequest
>>> from zope.schema import Text
>>> field = Text(__name__='foo', title=u'on')
>>> request = TestRequest(form={'field.foo': u'Hello\\r\\nworld!'})
>>> widget = SimpleEditingWidget(field, request)
>>> widget.style = ''
>>> widget.hasInput()
True
>>> widget.getInputValue()
u'Hello\\nworld!'
>>> def normalize(s):
... return '\\n '.join(filter(None, s.split(' ')))
>>> print normalize( widget() )
<textarea
cols="60"
id="field.foo"
name="field.foo"
rows="15"
>Hello\r
world!</textarea>
>>> print normalize( widget.hidden() )
<input
class="hiddenType"
id="field.foo"
name="field.foo"
type="hidden"
value="Hello world!"
/>
Calling `setRenderedValue` will change what gets output:
>>> widget.setRenderedValue("Hey\\ndude!")
>>> print normalize( widget() )
<textarea
cols="60"
id="field.foo"
name="field.foo"
rows="15"
>Hey\r
dude!</textarea>
Check that HTML is correctly encoded and decoded:
>>> request = TestRequest(
... form={'field.foo': u'<h1>©</h1>'})
>>> widget = SimpleEditingWidget(field, request)
>>> widget.style = ''
>>> widget.getInputValue()
u'<h1>©</h1>'
>>> print normalize( widget() )
<textarea
cols="60"
id="field.foo"
name="field.foo"
rows="15"
><h1>&copy;</h1></textarea>
"""
implements(IInputWidget)
default = ""
width = 60
height = 15
extra=""
style="width: 98%; font-family: monospace;"
rowTemplate = ViewPageTemplateFile("simpleeditingrow.pt")
rowFragment = ViewPageTemplateFile("simpleeditingrowfragment.pt")
def _toFieldValue(self, value):
if self.context.min_length and not value:
return None
return super(SimpleEditingWidget, self)._toFieldValue(value)
def __call__(self):
return renderElement("textarea",
name=self.name,
id=self.name,
cssClass=self.cssClass,
rows=self.height,
cols=self.width,
style=self.style,
contents=escape(self._getFormValue()),
extra=self.extra)
def contents(self):
"""Make the contents available to the template"""
return self._getFormData()
|