Skip to content

Commit bc77302

Browse files
author
Richard Jones
committed
give access to the input() method all over the place
1 parent 9515867 commit bc77302

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

roundup/cgi/templating.py

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
from roundup.cgi.TAL.TALInterpreter import TALInterpreter
2525
from roundup.cgi import ZTUtils
2626

27-
def input_html4(**attrs):
28-
"""Generate an 'input' (html4) element with given attributes"""
29-
return '<input %s>'%' '.join(['%s="%s"'%item for item in attrs.items()])
30-
31-
def input_xhtml(**attrs):
32-
"""Generate an 'input' (xhtml) element with given attributes"""
33-
return '<input %s/>'%' '.join(['%s="%s"'%item for item in attrs.items()])
34-
3527
class NoTemplate(Exception):
3628
pass
3729

@@ -289,7 +281,26 @@ def is_only_view_ok(self):
289281
'''
290282
return self.is_view_ok() and not self.is_edit_ok()
291283

292-
class HTMLClass(HTMLPermissions):
284+
def input_html4(**attrs):
285+
"""Generate an 'input' (html4) element with given attributes"""
286+
return '<input %s>'%' '.join(['%s="%s"'%item for item in attrs.items()])
287+
288+
def input_xhtml(**attrs):
289+
"""Generate an 'input' (xhtml) element with given attributes"""
290+
return '<input %s/>'%' '.join(['%s="%s"'%item for item in attrs.items()])
291+
292+
class HTMLInputMixin:
293+
''' requires a _client property '''
294+
def __init__(self):
295+
html_version = 'html4'
296+
if hasattr(self._client.instance.config, 'HTML_VERSION'):
297+
html_version = self._client.instance.config.HTML_VERSION
298+
if html_version == 'xhtml':
299+
self.input = input_xhtml
300+
else:
301+
self.input = input_html4
302+
303+
class HTMLClass(HTMLInputMixin, HTMLPermissions):
293304
''' Accesses through a class (either through *class* or *db.<classname>*)
294305
'''
295306
def __init__(self, client, classname, anonymous=0):
@@ -303,13 +314,7 @@ def __init__(self, client, classname, anonymous=0):
303314
self._klass = self._db.getclass(self.classname)
304315
self._props = self._klass.getprops()
305316

306-
html_version = 'html4'
307-
if hasattr(self._client.instance.config, 'HTML_VERSION'):
308-
html_version = self._client.instance.config.HTML_VERSION
309-
if html_version == 'xhtml':
310-
self.input = input_xhtml
311-
else:
312-
self.input = input_html4
317+
HTMLInputMixin.__init__(self)
313318

314319
def __repr__(self):
315320
return '<HTMLClass(0x%x) %s>'%(id(self), self.classname)
@@ -514,7 +519,7 @@ def renderWith(self, name, **kwargs):
514519
# use our fabricated request
515520
return pt.render(self._client, self.classname, req)
516521

517-
class HTMLItem(HTMLPermissions):
522+
class HTMLItem(HTMLInputMixin, HTMLPermissions):
518523
''' Accesses through an *item*
519524
'''
520525
def __init__(self, client, classname, nodeid, anonymous=0):
@@ -528,6 +533,8 @@ def __init__(self, client, classname, nodeid, anonymous=0):
528533
# do we prefix the form items with the item's identification?
529534
self._anonymous = anonymous
530535

536+
HTMLInputMixin.__init__(self)
537+
531538
def __repr__(self):
532539
return '<HTMLItem(0x%x) %s %s>'%(id(self), self._classname,
533540
self._nodeid)
@@ -836,7 +843,7 @@ def is_view_ok(self):
836843
self._classname) or (self._nodeid == self._client.userid and
837844
self._db.user.get(self._client.userid, 'username') != 'anonymous')
838845

839-
class HTMLProperty:
846+
class HTMLProperty(HTMLInputMixin):
840847
''' String, Number, Date, Interval HTMLProperty
841848
842849
Has useful attributes:
@@ -861,13 +868,7 @@ def __init__(self, client, classname, nodeid, prop, name, value,
861868
else:
862869
self._formname = name
863870

864-
html_version = 'html4'
865-
if hasattr(self._client.instance.config, 'HTML_VERSION'):
866-
html_version = self._client.instance.config.HTML_VERSION
867-
if html_version == 'xhtml':
868-
self.input = input_xhtml
869-
else:
870-
self.input = input_html4
871+
HTMLInputMixin.__init__(self)
871872

872873
def __repr__(self):
873874
return '<HTMLProperty(0x%x) %s %r %r>'%(id(self), self._formname,
@@ -1441,7 +1442,7 @@ def __init__(self, columns):
14411442
def __getitem__(self, name):
14421443
return self.columns.has_key(name)
14431444

1444-
class HTMLRequest:
1445+
class HTMLRequest(HTMLInputMixin):
14451446
''' The *request*, holding the CGI form and environment.
14461447
14471448
"form" the CGI form as a cgi.FieldStorage
@@ -1463,7 +1464,8 @@ class HTMLRequest:
14631464
14641465
'''
14651466
def __init__(self, client):
1466-
self.client = client
1467+
# _client is needed by HTMLInputMixin
1468+
self._client = self.client = client
14671469

14681470
# easier access vars
14691471
self.form = client.form
@@ -1478,13 +1480,7 @@ def __init__(self, client):
14781480
# the special char to use for special vars
14791481
self.special_char = '@'
14801482

1481-
html_version = 'html4'
1482-
if hasattr(self.client.instance.config, 'HTML_VERSION'):
1483-
html_version = self.client.instance.config.HTML_VERSION
1484-
if html_version == 'xhtml':
1485-
self.input = input_xhtml
1486-
else:
1487-
self.input = input_html4
1483+
HTMLInputMixin.__init__(self)
14881484

14891485
self._post_init()
14901486

0 commit comments

Comments
 (0)