diff -r 672acc730ce5 -r d628defebc17 goa/db.py --- a/goa/db.py Thu May 14 10:24:56 2009 +0200 +++ b/goa/db.py Thu May 14 11:38:40 2009 +0200 @@ -13,11 +13,11 @@ * all methods returning `google.appengine.ext.db.Model` instance(s) will return `cubicweb.goa.db.Model` instance instead (though you should see almost no difference since those instances have the same api) - + * class methods returning model instance take a `req` as first argument, unless they are called through an instance, representing the current request (accessible through `self.req` on almost all objects) - + * XXX no instance._set attributes, use instance.reverse_ instead * XXX reference property always return a list of objects, not the instance @@ -47,7 +47,7 @@ from google.appengine.api.datastore_errors import BadKeyError # XXX remove this dependancy -from google.appengine.ext import db +from google.appengine.ext import db def rset_from_objs(req, objs, attrs=('eid',), rql=None, args=None): @@ -76,15 +76,15 @@ value = obj[attr] descr = str(eschema.destination(attr)) line.append(value) - linedescr.append(descr) + linedescr.append(descr) rows.append(line) description.append(linedescr) for j, attr in enumerate(attrs): if attr == 'eid': entity = vreg.etype_class(eschema.type)(req, rset, i, j) - rset._get_entity_cache_ = {(i, j): entity} + rset._get_entity_cache_ = {(i, j): entity} rset.rowcount = len(rows) - req.decorate_rset(rset) + req.decorate_rset(rset) return rset @@ -102,7 +102,7 @@ return wrapped(cls, req, *args, **kwargs) return iclassmethod(wrapper) - + class gaedbmetaentity(metaentity): """metaclass for goa.db.Model classes: filter entity / db model part, put aside the db model part for later creation of db model class. @@ -139,15 +139,15 @@ class Model(entities.AnyEntity): id = 'Any' __metaclass__ = gaedbmetaentity - + row = col = 0 - + @classmethod def __initialize__(cls): super(Model, cls).__initialize__() cls._attributes = frozenset(rschema for rschema in cls.e_schema.subject_relations() if rschema.is_final()) - + def __init__(self, *args, **kwargs): # db.Model prototype: # __init__(self, parent=None, key_name=None, **kw) @@ -168,7 +168,7 @@ val = val._dbmodel kwargs[key] = val.key() self._gaeinitargs = (args, kwargs) - + def __repr__(self): return '' % ( self.e_schema, self.eid, self.keys(), id(self)) @@ -179,7 +179,7 @@ tschema = self.e_schema.destination(attr) if tschema == 'String': if len(value) > 500: - value = Text(value) + value = Text(value) elif tschema == 'Password': # if value is a Binary instance, this mean we got it # from a query result and so it is already encrypted @@ -203,7 +203,7 @@ value = self._cubicweb_to_datastore(attr, value) gaedict[attr] = value return gaedict - + def to_gae_model(self): dbmodel = self._dbmodel dbmodel.update(self._to_gae_dict()) @@ -211,7 +211,7 @@ @property @cached - def _dbmodel(self): + def _dbmodel(self): if self.has_eid(): assert self._gaeinitargs is None try: @@ -240,7 +240,7 @@ if '_app' in kwargs: assert _app is None _app = kwargs.pop('_app') - + for key, value in kwargs.iteritems(): if key in self._attributes: values['s_'+key] = value @@ -267,10 +267,10 @@ value will be prefixed by 'key_' to build the actual key name. """ return None - + def metainformation(self): return {'type': self.id, 'source': {'uri': 'system'}, 'extid': None} - + def view(self, vid, __registry='views', **kwargs): """shortcut to apply a view on this entity""" return self.vreg.render(__registry, vid, self.req, rset=self.rset, @@ -282,7 +282,7 @@ if needcheck: return 'eid', False return mainattr, needcheck - + def get_value(self, name): try: value = self[name] @@ -306,7 +306,7 @@ return True except BadKeyError: return False - + def complete(self, skip_bytes=True): pass @@ -319,7 +319,7 @@ objs = Query(str(targettype)).Run() return rset_from_objs(self.req, objs, ('eid',), 'Any X WHERE X is %s' % targettype) - + def key(self): return Key(self.eid) @@ -334,7 +334,7 @@ 'Any X WHERE X eid %(x)s', {'x': self.eid}) self.row = self.col = 0 return dbmodel - + @needrequest def get(cls, req, keys): # if check if this is a dict.key call @@ -393,7 +393,7 @@ def dynamic_properties(self): raise NotImplementedError('use eschema') - + def is_saved(self): return self.has_eid() @@ -425,7 +425,7 @@ IntegerProperty = db.IntegerProperty FloatProperty = db.FloatProperty ListProperty = db.ListProperty -SelfReferenceProperty = db.SelfReferenceProperty +SelfReferenceProperty = db.SelfReferenceProperty UserProperty = db.UserProperty