From 983e078ada144a876f2c521a9ff8e90a2fd485ec Mon Sep 17 00:00:00 2001 From: Massimo DiPierro Date: Sat, 3 Dec 2011 00:22:29 -0600 Subject: [PATCH] mongodb insert fix, thanks breedved --- VERSION | 2 +- gluon/dal.py | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 27471d83..0204e618 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 1.99.3 (2011-12-03 00:15:24) dev +Version 1.99.3 (2011-12-03 00:22:28) dev diff --git a/gluon/dal.py b/gluon/dal.py index 49461426..026319dc 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -3762,12 +3762,33 @@ class MongoDBAdapter(NoSQLAdapter): return pymongo.Connection(**driver_args)[dbname] self.pool_connection(connect,cursor=False) + def represent(self, obj, fieldtype): + value = NoSQLAdapter.represent(self, obj, fieldtype) + if fieldtype =='date': + if value == None: + return value + t = datetime.time(0, 0, 0)#this piece of data can be stripped of based on the fieldtype + return datetime.datetime.combine(value, t) #mongodb doesn't has a date object and so it must datetime, string or integer + elif fieldtype == 'time': + if value == None: + return value + d = datetime.date(2000, 1, 1) #this piece of data can be stripped of based on the fieldtype + return datetime.datetime.combine(d, value) #mongodb doesn't has a time object and so it must datetime, string or integer + elif fieldtype == 'list:string' or fieldtype == 'list:integer' or fieldtype == 'list:reference': + return value #raise SyntaxError, "Not Supported" + return value + def insert(self,table,fields): ctable = self.connection[table._tablename] - values = dict((k,self.represent(v,table[k].type)) for k,v in fields) + values = dict((k.name,self.represent(v,table[k.name].type)) for k,v in fields) ctable.insert(values) - return uuid2int(id) - + return int(str(values['_id']), 16) + + def create_table(self, table, migrate=True, fake_migrate=False, polymodel=None, isCapped=False): + if isCapped: + raise RuntimeError, "Not implemented" + else: + pass def count(self,query): raise RuntimeError, "Not implemented"