Skip to content

Commit c8c0d7d

Browse files
author
Richard Jones
committed
added "foo@" prefix to all but "context" form variable names
1 parent 681eb52 commit c8c0d7d

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

roundup/cgi/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.94 2003-02-18 06:15:21 richard Exp $
1+
# $Id: client.py,v 1.95 2003-02-18 10:58:32 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -1575,7 +1575,6 @@ class <designator> (where <designator> must be
15751575
# we also don't want to create FileClass items with no content
15761576
if not props.get('content', ''):
15771577
del all_props[(cn, id)]
1578-
15791578
return all_props, all_links
15801579

15811580
def fixNewlines(text):

roundup/cgi/templating.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,13 @@ class utils(client.instance.interfaces.TemplatingUtils, utils):
160160
# add in the item if there is one
161161
if client.nodeid:
162162
if classname == 'user':
163-
c['context'] = HTMLUser(client, classname, client.nodeid)
163+
c['context'] = HTMLUser(client, classname, client.nodeid,
164+
anonymous=1)
164165
else:
165-
c['context'] = HTMLItem(client, classname, client.nodeid)
166+
c['context'] = HTMLItem(client, classname, client.nodeid,
167+
anonymous=1)
166168
elif client.db.classes.has_key(classname):
167-
c['context'] = HTMLClass(client, classname)
169+
c['context'] = HTMLClass(client, classname, anonymous=1)
168170
return c
169171

170172
def render(self, client, classname, request, **options):
@@ -200,9 +202,15 @@ def __init__(self, client):
200202
# we want config to be exposed
201203
self.config = client.db.config
202204

203-
def __getitem__(self, item):
204-
self._client.db.getclass(item)
205-
return HTMLClass(self._client, item)
205+
def __getitem__(self, item, desre=re.compile(r'(?P<cl>\w+)(?P<id>[-\d]+)')):
206+
# check to see if we're actually accessing an item
207+
m = desre.match(item)
208+
if m:
209+
self._client.db.getclass(m.group('cl'))
210+
return HTMLItem(self._client, m.group('cl'), m.group('id'))
211+
else:
212+
self._client.db.getclass(item)
213+
return HTMLClass(self._client, item)
206214

207215
def __getattr__(self, attr):
208216
try:
@@ -250,9 +258,10 @@ def is_only_view_ok(self):
250258
class HTMLClass(HTMLPermissions):
251259
''' Accesses through a class (either through *class* or *db.<classname>*)
252260
'''
253-
def __init__(self, client, classname):
261+
def __init__(self, client, classname, anonymous=0):
254262
self._client = client
255263
self._db = client.db
264+
self._anonymous = anonymous
256265

257266
# we want classname to be exposed, but _classname gives a
258267
# consistent API for extending Class/Item
@@ -297,7 +306,8 @@ def __getitem__(self, item):
297306
value = []
298307
else:
299308
value = None
300-
return htmlklass(self._client, '', prop, item, value)
309+
return htmlklass(self._client, self._classname, '', prop, item,
310+
value, self._anonymous)
301311

302312
# no good
303313
raise KeyError, item
@@ -455,14 +465,17 @@ def renderWith(self, name, **kwargs):
455465
class HTMLItem(HTMLPermissions):
456466
''' Accesses through an *item*
457467
'''
458-
def __init__(self, client, classname, nodeid):
468+
def __init__(self, client, classname, nodeid, anonymous=0):
459469
self._client = client
460470
self._db = client.db
461471
self._classname = classname
462472
self._nodeid = nodeid
463473
self._klass = self._db.getclass(classname)
464474
self._props = self._klass.getprops()
465475

476+
# do we prefix the form items with the item's identification?
477+
self._anonymous = anonymous
478+
466479
def __repr__(self):
467480
return '<HTMLItem(0x%x) %s %s>'%(id(self), self._classname,
468481
self._nodeid)
@@ -478,15 +491,18 @@ def __getitem__(self, item):
478491
prop = self._props[item]
479492

480493
# get the value, handling missing values
481-
value = self._klass.get(self._nodeid, item, None)
494+
value = None
495+
if int(self._nodeid) > 0:
496+
value = self._klass.get(self._nodeid, item, None)
482497
if value is None:
483498
if isinstance(self._props[item], hyperdb.Multilink):
484499
value = []
485500

486501
# look up the correct HTMLProperty class
487502
for klass, htmlklass in propclasses:
488503
if isinstance(prop, klass):
489-
return htmlklass(self._client, self._nodeid, prop, item, value)
504+
return htmlklass(self._client, self._classname,
505+
self._nodeid, prop, item, value, self._anonymous)
490506

491507
raise KeyError, item
492508

@@ -726,15 +742,15 @@ def __init__(self, client, classname, nodeid):
726742
self._security = client.db.security
727743

728744
_marker = []
729-
def hasPermission(self, role, classname=_marker):
730-
''' Determine if the user has the Role.
745+
def hasPermission(self, permission, classname=_marker):
746+
''' Determine if the user has the Permission.
731747
732748
The class being tested defaults to the template's class, but may
733749
be overidden for this test by suppling an alternate classname.
734750
'''
735751
if classname is self._marker:
736752
classname = self._default_classname
737-
return self._security.hasPermission(role, self._nodeid, classname)
753+
return self._security.hasPermission(permission, self._nodeid, classname)
738754

739755
def is_edit_ok(self):
740756
''' Is the user allowed to Edit the current class?
@@ -760,15 +776,22 @@ class HTMLProperty:
760776
761777
A wrapper object which may be stringified for the plain() behaviour.
762778
'''
763-
def __init__(self, client, nodeid, prop, name, value):
779+
def __init__(self, client, classname, nodeid, prop, name, value,
780+
anonymous=0):
764781
self._client = client
765782
self._db = client.db
783+
self._classname = classname
766784
self._nodeid = nodeid
767785
self._prop = prop
768-
self._name = name
769786
self._value = value
787+
self._anonymous = anonymous
788+
if not anonymous:
789+
self._name = '%s%s@%s'%(classname, nodeid, name)
790+
else:
791+
self._name = name
770792
def __repr__(self):
771-
return '<HTMLProperty(0x%x) %s %r %r>'%(id(self), self._name, self._prop, self._value)
793+
return '<HTMLProperty(0x%x) %s %r %r>'%(id(self), self._name,
794+
self._prop, self._value)
772795
def __str__(self):
773796
return self.plain()
774797
def __cmp__(self, other):
@@ -1013,8 +1036,8 @@ class LinkHTMLProperty(HTMLProperty):
10131036
entry identified by the assignedto property on item, and then the
10141037
name property of that user)
10151038
'''
1016-
def __init__(self, *args):
1017-
HTMLProperty.__init__(self, *args)
1039+
def __init__(self, *args, **kw):
1040+
HTMLProperty.__init__(self, *args, **kw)
10181041
# if we're representing a form value, then the -1 from the form really
10191042
# should be a None
10201043
if str(self._value) == '-1':

0 commit comments

Comments
 (0)