def insert(self, flush=True, commit=False): """ Save the current instance into the session """ sess = self.session disable_sa_deprecation_warnings() sess.add(self) enable_sa_deprecation_warnings() if flush is True: sess.flush() if commit is True: sess.commit()
def _get_relations(cls): """ Returns the relations defined with the Relation decorator """ disable_sa_deprecation_warnings() relations = [] for method in cls.__dict__.values(): if hasattr(method, 'decorator') and method.decorator == Relation: relations.append(method.relation_name) method.deferred_import() enable_sa_deprecation_warnings() return relations
def enable_log(): logger = logging.getLogger('affinitic.db') logpath = '/'.join([os.environ.get('CLIENT_HOME', '.'), 'sqlalchemy.log']) fh = TimedRotatingFileHandler(logpath, 'midnight', 1) formatter = logging.Formatter(" %(asctime)s \n %(message)s \n--") fh.setFormatter(formatter) fh.suffix = "%Y-%m-%d-%H-%M" logger.addHandler(fh) register_logging() enable_sa_deprecation_warnings()