blog/app/models/__init__.py
def new(self):
        """ Adds a new record to MDB. """

        if not hasattr(self, 'required_attribs'):
            self.required_attribs = []

        # sanity check
        for req_var in self.required_attribs:
            if req_var not in self.kwargs:
                err = "The '%s' kwarg is required when creating new %s!"
                msg = err % (req_var, self.collection)
                self.logger.error(msg)
                self.logger.error('Incoming kwargs dict: %s' % self.kwargs)
                raise ValueError(msg)

        # do it
        self.logger.warn('Creating new %s record!' % self.collection)

        for req_var in self.required_attribs:
            setattr(self, req_var, self.kwargs[req_var])

        self.created_on = datetime.now()
        self.updated_on = datetime.now()
        self.created_by = flask_login.current_user._id
        self._id = self.mdb.insert({})

        try:
            self.save()
        except pymongo.errors.DuplicateKeyError as e:
            self.mdb.remove({'_id': self._id})
            self.logger.error(e)
            self.logger.error('Cannot create asset: %s' % self)
            raise ValueError('Duplicate key error prevented asset creation!')
 Adds a new record to MDB. 
Adds a new record to MDB.
Adds a new record to MDB .
def new(self):
        if not hasattr(self, 'required_attribs'):
            self.required_attribs = []
        for req_var in self.required_attribs:
            if req_var not in self.kwargs:
                err = "The '%s' kwarg is required when creating new %s!"
                msg = err % (req_var, self.collection)
                self.logger.error(msg)
                self.logger.error('Incoming kwargs dict: %s' % self.kwargs)
                raise ValueError(msg)
        self.logger.warn('Creating new %s record!' % self.collection)
        for req_var in self.required_attribs:
            setattr(self, req_var, self.kwargs[req_var])
        self.created_on = datetime.now()
        self.updated_on = datetime.now()
        self.created_by = flask_login.current_user._id
        self._id = self.mdb.insert({})
        try:
            self.save()
        except pymongo.errors.DuplicateKeyError as e:
            self.mdb.remove({'_id': self._id})
            self.logger.error(e)
            self.logger.error('Cannot create asset: %s' % self)
            raise ValueError('Duplicate key error prevented asset creation!')
def new ( self ) : if not hasattr ( self , 'required_attribs' ) : self . required_attribs = [ ] for req_var in self . required_attribs : if req_var not in self . kwargs : err = "The '%s' kwarg is required when creating new %s!" msg = err % ( req_var , self . collection ) self . logger . error ( msg ) self . logger . error ( 'Incoming kwargs dict: %s' % self . kwargs ) raise ValueError ( msg ) self . logger . warn ( 'Creating new %s record!' % self . collection ) for req_var in self . required_attribs : setattr ( self , req_var , self . kwargs [ req_var ] ) self . created_on = datetime . now ( ) self . updated_on = datetime . now ( ) self . created_by = flask_login . current_user . _id self . _id = self . mdb . insert ( { } ) try : self . save ( ) except pymongo . errors . DuplicateKeyError as e : self . mdb . remove ( { '_id' : self . _id } ) self . logger . error ( e ) self . logger . error ( 'Cannot create asset: %s' % self ) raise ValueError ( 'Duplicate key error prevented asset creation!' )
Adds a new record to MDB.
Adds a new record to MDB .
""" Adds a new record to MDB. """ # sanity check # do it
self