goa/db.py
changeset 3720 5376aaadd16b
parent 2792 135580d15d42
parent 3689 deb13e88e037
child 4252 6c4f109c2b03
equal deleted inserted replaced
3678:29f74716fd70 3720:5376aaadd16b
   146 
   146 
   147     @classmethod
   147     @classmethod
   148     def __initialize__(cls):
   148     def __initialize__(cls):
   149         super(Model, cls).__initialize__()
   149         super(Model, cls).__initialize__()
   150         cls._attributes = frozenset(rschema for rschema in cls.e_schema.subject_relations()
   150         cls._attributes = frozenset(rschema for rschema in cls.e_schema.subject_relations()
   151                                     if rschema.is_final())
   151                                     if rschema.final)
   152 
   152 
   153     def __init__(self, *args, **kwargs):
   153     def __init__(self, *args, **kwargs):
   154         # db.Model prototype:
   154         # db.Model prototype:
   155         #   __init__(self, parent=None, key_name=None, **kw)
   155         #   __init__(self, parent=None, key_name=None, **kw)
   156         #
   156         #
   161             self._gaeinitargs = None
   161             self._gaeinitargs = None
   162         else:
   162         else:
   163             super(Model, self).__init__(None, None)
   163             super(Model, self).__init__(None, None)
   164             # if Model instances are given in kwargs, turn them into db model
   164             # if Model instances are given in kwargs, turn them into db model
   165             for key, val in kwargs.iteritems():
   165             for key, val in kwargs.iteritems():
   166                 if key in self.e_schema.subject_relations() and not self.e_schema.schema[key].is_final():
   166                 if key in self.e_schema.subject_relations() and not self.e_schema.schema[key].final:
   167                     if isinstance(kwargs, (list, tuple)):
   167                     if isinstance(kwargs, (list, tuple)):
   168                         val = [isinstance(x, Model) and x._dbmodel or x for x in val]
   168                         val = [isinstance(x, Model) and x._dbmodel or x for x in val]
   169                     elif isinstance(val, Model):
   169                     elif isinstance(val, Model):
   170                         val = val._dbmodel
   170                         val = val._dbmodel
   171                     kwargs[key] = val.key()
   171                     kwargs[key] = val.key()