Skip to content

Commit fd5b476

Browse files
committed
added custom parsing properties from arguments
committer: Ralf Schlatterbeck <[email protected]>
1 parent f563df9 commit fd5b476

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

roundup/rest.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@
1111
from roundup.exceptions import *
1212
from roundup import xmlrpc
1313

14+
def props_from_args(db, cl, args, itemid=None):
15+
props = {}
16+
for arg in args:
17+
try:
18+
key = arg.name
19+
value = arg.value
20+
except ValueError:
21+
raise UsageError('argument "%s" not propname=value' % arg)
22+
if isinstance(key, unicode):
23+
try:
24+
key = key.encode('ascii')
25+
except UnicodeEncodeError:
26+
raise UsageError('argument %r is no valid ascii keyword' % key)
27+
if isinstance(value, unicode):
28+
value = value.encode('utf-8')
29+
if value:
30+
try:
31+
props[key] = hyperdb.rawToHyperdb(db, cl, itemid, key, value)
32+
except hyperdb.HyperdbValueError:
33+
pass # pass if a parameter is not a property of the class
34+
else:
35+
props[key] = None
36+
37+
return props
1438

1539
class RestfulInstance(object):
1640
"""Dummy Handler for REST
@@ -58,8 +82,7 @@ def post_collection(self, class_name, input):
5882
class_obj = self.db.getclass(class_name)
5983

6084
# convert types
61-
input_data = ["%s=%s" % (item.name, item.value) for item in input.value]
62-
props = xmlrpc.props_from_args(self.db, class_obj, input_data)
85+
props = props_from_args(self.db, class_obj, input.value)
6386

6487
# check for the key property
6588
key = class_obj.getkey()
@@ -91,8 +114,7 @@ def put_collection(self, class_name, input):
91114
def put_element(self, class_name, item_id, input):
92115
class_obj = self.db.getclass(class_name)
93116

94-
input_data = ["%s=%s" % (item.name, item.value) for item in input.value]
95-
props = xmlrpc.props_from_args(self.db, class_obj, input_data, item_id)
117+
props = props_from_args(self.db, class_obj, input.value, item_id)
96118
for p in props.iterkeys():
97119
if not self.db.security.hasPermission('Edit', self.db.getuid(),
98120
class_name, p, item_id):

0 commit comments

Comments
 (0)