blog/app/models/__init__.py
def save(self, verbose=app.config['DEBUG']):
        """ Saves the object's self.data_model attribs to its self.collection
        in the MDB. """

        # sanity check
        if not hasattr(self, '_id'):
            err = "'%s.%s' record requires '_id' attrib to save!"
            raise AttributeError(
                err % (app.config['MDB'].name, self.collection)
            )

        # make a record, enforce the data model
        record = {'_id': self._id}
        for key, value_type in self.data_model.items():
            record[key] = getattr(self, key, None)
            if record[key] != None:
                if isinstance(record[key], dict):
                    if record[key].get('$oid', None) is not None:
                        record[key] = record[key]['$oid']
                try:
                    if not isinstance(record[key], value_type):
                        try:
                            record[key] = value_type(record[key])
                        except TypeError:
                            msg = "Could not cast value '%s' to %s type!"
                            raise TypeError(msg % (record[key], value_type))
                except TypeError as e:
                    self.logger.exception(e)
                    self.logger.error("Is '%s' a type, e.g. str?" % value_type)
                    self.logger.error('Did you add parens? Do not add parens.')
                    raise

        # save and, if verbose, log about it

        # set self.update_on, created_by, because most models support it
        self.updated_on = datetime.now()
        self.created_by = flask_login.current_user._id

        self.mdb.save(record)
        if verbose:
            self.logger.info('Saved changes to %s' % self)
        return True
 Saves the object's self.data_model attribs to its self.collection
        in the MDB. 
Saves the object's self.data_model attribs to its self.collection
in the MDB.
Saves the object ' s self . data_model attribs to its self . collection in the MDB .
def save(self, verbose=app.config['DEBUG']):
        if not hasattr(self, '_id'):
            err = "'%s.%s' record requires '_id' attrib to save!"
            raise AttributeError(
                err % (app.config['MDB'].name, self.collection)
            )
        record = {'_id': self._id}
        for key, value_type in self.data_model.items():
            record[key] = getattr(self, key, None)
            if record[key] != None:
                if isinstance(record[key], dict):
                    if record[key].get('$oid', None) is not None:
                        record[key] = record[key]['$oid']
                try:
                    if not isinstance(record[key], value_type):
                        try:
                            record[key] = value_type(record[key])
                        except TypeError:
                            msg = "Could not cast value '%s' to %s type!"
                            raise TypeError(msg % (record[key], value_type))
                except TypeError as e:
                    self.logger.exception(e)
                    self.logger.error("Is '%s' a type, e.g. str?" % value_type)
                    self.logger.error('Did you add parens? Do not add parens.')
                    raise
        self.updated_on = datetime.now()
        self.created_by = flask_login.current_user._id
        self.mdb.save(record)
        if verbose:
            self.logger.info('Saved changes to %s' % self)
        return True
def save ( self , verbose = app . config [ 'DEBUG' ] ) : if not hasattr ( self , '_id' ) : err = "'%s.%s' record requires '_id' attrib to save!" raise AttributeError ( err % ( app . config [ 'MDB' ] . name , self . collection ) ) record = { '_id' : self . _id } for key , value_type in self . data_model . items ( ) : record [ key ] = getattr ( self , key , None ) if record [ key ] != None : if isinstance ( record [ key ] , dict ) : if record [ key ] . get ( '$oid' , None ) is not None : record [ key ] = record [ key ] [ '$oid' ] try : if not isinstance ( record [ key ] , value_type ) : try : record [ key ] = value_type ( record [ key ] ) except TypeError : msg = "Could not cast value '%s' to %s type!" raise TypeError ( msg % ( record [ key ] , value_type ) ) except TypeError as e : self . logger . exception ( e ) self . logger . error ( "Is '%s' a type, e.g. str?" % value_type ) self . logger . error ( 'Did you add parens? Do not add parens.' ) raise self . updated_on = datetime . now ( ) self . created_by = flask_login . current_user . _id self . mdb . save ( record ) if verbose : self . logger . info ( 'Saved changes to %s' % self ) return True
Saves the object's self.data_model attribs to its self.collection
in the MDB.
Saves the object ' s self . data_model attribs to its self . collection in the MDB .
""" Saves the object's self.data_model attribs to its self.collection
        in the MDB. """ # sanity check # make a record, enforce the data model # save and, if verbose, log about it # set self.update_on, created_by, because most models support it
self
verbose