Unverified Commit 23c73f6c authored by Khanh Ngo's avatar Khanh Ngo
Browse files

Fix logging in models

parent 2de8bf55
from flask import current_app
from .base import db
from .user import User
from .account_user import AccountUser
......@@ -99,7 +101,7 @@ class Account(db.Model):
return True
except Exception as e:
db.session.rollback()
logging.error(
current_app.logger.error(
'Cannot delete account {0} from DB. DETAIL: {1}'.format(
self.username, e))
return False
......@@ -140,7 +142,7 @@ class Account(db.Model):
db.session.commit()
except Exception as e:
db.session.rollback()
logging.error(
current_app.logger.error(
'Cannot revoke user privileges on account {0}. DETAIL: {1}'.
format(self.name, e))
......@@ -151,7 +153,7 @@ class Account(db.Model):
db.session.commit()
except Exception as e:
db.session.rollback()
logging.error(
current_app.logger.error(
'Cannot grant user privileges to account {0}. DETAIL: {1}'.
format(self.name, e))
......@@ -177,7 +179,7 @@ class Account(db.Model):
return True
except Exception as e:
db.session.rollback()
logging.error(
current_app.logger.error(
'Cannot add user privileges on account {0}. DETAIL: {1}'.
format(self.name, e))
return False
......@@ -194,7 +196,7 @@ class Account(db.Model):
return True
except Exception as e:
db.session.rollback()
logging.error(
current_app.logger.error(
'Cannot revoke user privileges on account {0}. DETAIL: {1}'.
format(self.name, e))
return False
from flask import current_app
from .base import db
......@@ -26,8 +28,8 @@ class DomainSetting(db.Model):
db.session.commit()
return True
except Exception as e:
logging.error(
current_app.logger.error(
'Unable to set DomainSetting value. DETAIL: {0}'.format(e))
logging.debug(traceback.format_exc())
current_app.logger.debug(traceback.format_exc())
db.session.rollback()
return False
\ No newline at end of file
from flask import current_app
from .base import db
......@@ -36,7 +38,7 @@ class DomainTemplateRecord(db.Model):
try:
db.session.commit()
except Exception as e:
logging.error(
current_app.logger.error(
'Can not update domain template table. Error: {0}'.format(e))
db.session.rollback()
return {
......
......@@ -2,6 +2,7 @@ import sys
import pytimeparse
from ast import literal_eval
from distutils.util import strtobool
from flask import current_app
from .base import db
......@@ -193,9 +194,9 @@ class Setting(db.Model):
db.session.commit()
return True
except Exception as e:
logging.error('Cannot set maintenance to {0}. DETAIL: {1}'.format(
current_app.logger.error('Cannot set maintenance to {0}. DETAIL: {1}'.format(
mode, e))
logging.debug(traceback.format_exec())
current_app.logger.debug(traceback.format_exec())
db.session.rollback()
return False
......@@ -215,9 +216,9 @@ class Setting(db.Model):
db.session.commit()
return True
except Exception as e:
logging.error('Cannot toggle setting {0}. DETAIL: {1}'.format(
current_app.logger.error('Cannot toggle setting {0}. DETAIL: {1}'.format(
setting, e))
logging.debug(traceback.format_exec())
current_app.logger.debug(traceback.format_exec())
db.session.rollback()
return False
......@@ -235,9 +236,9 @@ class Setting(db.Model):
db.session.commit()
return True
except Exception as e:
logging.error('Cannot edit setting {0}. DETAIL: {1}'.format(
current_app.logger.error('Cannot edit setting {0}. DETAIL: {1}'.format(
setting, e))
logging.debug(traceback.format_exec())
current_app.logger.debug(traceback.format_exec())
db.session.rollback()
return False
......@@ -251,7 +252,7 @@ class Setting(db.Model):
else:
return self.defaults[setting]
else:
logging.error('Unknown setting queried: {0}'.format(setting))
current_app.logger.error('Unknown setting queried: {0}'.format(setting))
def get_records_allow_to_edit(self):
return list(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment