From 7b6f5dff4850cb975f9b0d12105d5c7a8db25a16 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sat, 16 Jun 2012 16:49:06 -0500 Subject: [PATCH] GAE references, thanks Christian --- VERSION | 2 +- gluon/dal.py | 16 ++++++++++++---- gluon/sqlhtml.py | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/VERSION b/VERSION index 1dca15c5..6edf0056 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.0 (2012-06-15 13:17:03) dev +Version 2.00.0 (2012-06-16 16:49:01) dev diff --git a/gluon/dal.py b/gluon/dal.py index b02c9649..ab014bce 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -1661,7 +1661,10 @@ class BaseAdapter(ConnectionPool): return value def parse_id(self, value, field_type): - return int(value) + if isinstance(self, GoogleDatastoreAdapter) : + return value + else: + return int(value) def parse_integer(self, value, field_type): return int(value) @@ -1722,7 +1725,12 @@ class BaseAdapter(ConnectionPool): colset[fieldname] = value if field.type == 'id': - id = value + if isinstance(self, GoogleDatastoreAdapter) : + id = value.key().id_or_name() + colset[fieldname] = id + colset.gae_item = value + else: + id = value colset.update_record = lambda _ = (colset, table, id), **a: update_record(_, a) colset.delete_record = lambda t = table, i = id: t._db(t._id==i).delete() for (referee_table, referee_name) in table._referenced_by: @@ -4219,7 +4227,7 @@ class GoogleDatastoreAdapter(NoSQLAdapter): (items, tablename, fields) = self.select_raw(query,fields,attributes) # self.db['_lastsql'] = self._select(query,fields,attributes) - rows = [[(t==self.db[tablename]._id.name and item.key().id_or_name()) or \ + rows = [[(t==self.db[tablename]._id.name and item) or \ (t=='nativeRef' and item) or getattr(item, t) \ for t in fields] for item in items] colnames = ['%s.%s' % (tablename, t) for t in fields] @@ -4274,7 +4282,7 @@ class GoogleDatastoreAdapter(NoSQLAdapter): tmp = table._tableobj(**dfields) tmp.put() rid = Reference(tmp.key().id()) - (rid._table, rid._record) = (table, None) + (rid._table, rid._record, rid._gaekey) = (table, None, tmp.key()) return rid def bulk_insert(self,table,items): diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 0a766cf1..647cc350 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -2271,7 +2271,7 @@ class SQLTABLE(TABLE): except TypeError: href = '%s/%s/%s' % (linkto, tablename, r_old) r = A(r, _href=href) - elif field.type.startswith('reference'): + elif isinstance(field.type, str) and field.type.startswith('reference'): if linkto: ref = field.type[10:] try: @@ -2294,7 +2294,7 @@ class SQLTABLE(TABLE): (k, record[tablename][k])) or (k, record[k]) \ for k in field._table._primarykey ] )) r = A(r, _href='%s/%s?%s' % (linkto, tablename, key)) - elif field.type.startswith('list:'): + elif isinstance(field.type, str) and field.type.startswith('list:'): r = represent(field,r or [],record) elif field.represent: r = represent(field,r,record)