X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=rest%2F__init__.py;h=c3484835a9863351e62da511febb4f9b6275d24e;hb=c457730e8d49ee507846edeb8a474374f0122f25;hp=62d66da5e68fcff1cfebe06fa7b47a35cfc5aae3;hpb=699fc5176886a8f2924973f5ba6ac974cd0266dc;p=unfold.git diff --git a/rest/__init__.py b/rest/__init__.py index 62d66da5..c3484835 100644 --- a/rest/__init__.py +++ b/rest/__init__.py @@ -1,5 +1,6 @@ from manifold.core.query import Query from manifoldapi.manifoldapi import execute_query +from portal.actions import is_pi from django.http import HttpResponse @@ -27,7 +28,7 @@ class ObjectRequest(object): self.type = object_type self.name = object_name self.fields = [] - self.params = {} + self.params = [] self.filters = {} self.options = None @@ -40,10 +41,35 @@ class ObjectRequest(object): self.filters['disabled'] = '0' self.filters['gateway_type'] = 'sfa' self.filters['platform'] = '!myslice' + #elif(self.type.startswith('local:')): + elif ':' in self.type: + table = self.type.split(':') + prefix = table[0] + table = table[1] + if prefix == '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() - def setKey(self): # What about key formed of multiple fields??? @@ -66,11 +92,11 @@ class ObjectRequest(object): raise Exception, 'Manifold db error' def setFields(self, fields): - selected_fields = [] - for p in fields : - if p in self.fields : - selected_fields.append(p) - self.fields = selected_fields +# selected_fields = [] +# for p in fields : +# if p in self.fields : +# selected_fields.append(p) + self.fields = fields def applyFilters(self, query, force_filters = False): @@ -88,13 +114,15 @@ class ObjectRequest(object): query.filter_by(k, '<=', f[2:]) elif (f[:1] == "<") : query.filter_by(k, '<', f[1:]) + elif (f[:8] == "CONTAINS") : + query.filter_by(k, 'CONTAINS', f[8:]) else : query.filter_by(k, '==', f) return query def get(self): query = Query.get(self.type) - if (self.id not in self.fields) : + if (self.id is not None) and (self.id not in self.fields) : query.select(self.fields + [self.id]) else : query.select(self.fields) @@ -106,7 +134,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) @@ -114,13 +146,19 @@ class ObjectRequest(object): def update(self): query = Query.update(self.type) query = self.applyFilters(query, True) - 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 update" - + + if self.id is not None: + query.select(self.id) + return execute_query(self.request, query) def delete(self): @@ -129,7 +167,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):