equal
deleted
inserted
replaced
48 for objtype in objtypes: |
48 for objtype in objtypes: |
49 card = rschema.rdef(subjtype, objtype).cardinality[index] |
49 card = rschema.rdef(subjtype, objtype).cardinality[index] |
50 if card in '+*': |
50 if card in '+*': |
51 return card |
51 return card |
52 return '1' |
52 return '1' |
|
53 |
|
54 def can_use_rest_path(value): |
|
55 """return True if value can be used at the end of a Rest URL path""" |
|
56 if value is None: |
|
57 return False |
|
58 value = unicode(value) |
|
59 # the check for ?, /, & are to prevent problems when running |
|
60 # behind Apache mod_proxy |
|
61 if value == u'' or u'?' in value or u'/' in value or u'&' in value: |
|
62 return False |
|
63 return True |
|
64 |
53 |
65 |
54 |
66 |
55 class Entity(AppObject): |
67 class Entity(AppObject): |
56 """an entity instance has e_schema automagically set on |
68 """an entity instance has e_schema automagically set on |
57 the class and instances has access to their issuing cursor. |
69 the class and instances has access to their issuing cursor. |
500 mainattr, needcheck = self._rest_attr_info() |
512 mainattr, needcheck = self._rest_attr_info() |
501 etype = str(self.e_schema) |
513 etype = str(self.e_schema) |
502 path = etype.lower() |
514 path = etype.lower() |
503 if mainattr != 'eid': |
515 if mainattr != 'eid': |
504 value = getattr(self, mainattr) |
516 value = getattr(self, mainattr) |
505 if value is None or unicode(value) == u'': |
517 if not can_use_rest_path(value): |
506 mainattr = 'eid' |
518 mainattr = 'eid' |
507 path += '/eid' |
519 path += '/eid' |
508 elif needcheck: |
520 elif needcheck: |
509 # make sure url is not ambiguous |
521 # make sure url is not ambiguous |
510 try: |
522 try: |