X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=rest%2F__init__.py;h=a8565963546a762a88ad2672103e85d694b25f0a;hb=a8b4d52df438751ce078700eab547e84075e9420;hp=98b9d085baa792848f6daa888877dff647203c0b;hpb=11b83a3dc742c2f139c67ced00dcca10713a9602;p=myslice.git diff --git a/rest/__init__.py b/rest/__init__.py index 98b9d085..a8565963 100644 --- a/rest/__init__.py +++ b/rest/__init__.py @@ -40,21 +40,33 @@ class ObjectRequest(object): self.filters['disabled'] = '0' self.filters['gateway_type'] = 'sfa' self.filters['platform'] = '!myslice' - elif(self.type.startswith('local:')): - # XXX TODO: find a generic Query to get the fields like - # select column.name from local:object where table == local:user + #elif(self.type.startswith('local:')): + elif ':' in self.type: table = self.type.split(':') + prefix = table[0] table = table[1] - if table == "user": - self.id = table + '_id' - self.fields = ['user_id', 'email', 'password', 'config','status']; - elif table == "account": - # XXX TODO: Multiple key for account = (platform_id, user_id) - self.id = None - self.fields = ['platform_id', 'user_id', 'auth_type', 'config']; - elif table == "platform": - self.id = 'platform' - self.fields = ['platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type']; + + if prefix is 'local': + # XXX TODO: find a generic Query to get the fields like + # select column.name from local:object where table == local:user + table = self.type.split(':') + table = table[1] + if table == "user": + self.id = table + '_id' + self.fields = ['user_id', 'email', 'password', 'config','status']; + elif table == "account": + # XXX TODO: Multiple key for account = (platform_id, user_id) + self.id = "platform_id, user_id" + self.fields = ['platform_id', 'user_id', 'auth_type', 'config']; + elif table == "platform": + self.id = 'platform' + self.fields = ['platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type']; + else: + # If we use prefix, set the key without the prefix then add it again + self.type = table + self.setKey() + self.setLocalFields() + self.type = prefix + ':' + table else : self.setKey() self.setLocalFields() @@ -120,7 +132,11 @@ class ObjectRequest(object): query = Query.create(self.type) # No filters for create if self.params : - query.set(self.params) + for p in self.params : + for k,v in p.iteritems() : + print "param: %s : %s" % (k,v) + query.set({k : v}) + print "query = ",query else: raise Exception, "Params are required for create" return execute_query(self.request, query) @@ -129,18 +145,18 @@ class ObjectRequest(object): query = Query.update(self.type) query = self.applyFilters(query, True) - print "rest/__init__ self = ",self - print "rest/__init__ params = ",self.params - if self.params : + for p in self.params : + for k,v in p.iteritems() : + print "param: %s : %s" % (k,v) + query.set({k : v}) print "query = ",query - query.set(self.params) -# query.set({ 'resource' : self.params}) -# for param in self.params : - else: raise Exception, "Params are required for update" - + + if self.id is not None: + query.select(self.id) + return execute_query(self.request, query) def delete(self): @@ -149,7 +165,7 @@ class ObjectRequest(object): if self.filters : query.set(self.filters) else: - raise Exception, "Filters are required for update" + raise Exception, "Filters are required for delete" return execute_query(self.request, query) def json(self):