2020-06-19 01:47:51 +00:00
|
|
|
import traceback
|
|
|
|
|
2020-01-29 15:18:15 +00:00
|
|
|
from flask import current_app
|
|
|
|
|
2019-12-02 03:32:03 +00:00
|
|
|
from .base import db
|
|
|
|
|
|
|
|
|
|
|
|
class DomainSetting(db.Model):
|
|
|
|
__tablename__ = 'domain_setting'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
domain_id = db.Column(db.Integer, db.ForeignKey('domain.id'))
|
|
|
|
domain = db.relationship('Domain', back_populates='settings')
|
|
|
|
setting = db.Column(db.String(255), nullable=False)
|
|
|
|
value = db.Column(db.String(255))
|
|
|
|
|
|
|
|
def __init__(self, id=None, setting=None, value=None):
|
|
|
|
self.id = id
|
|
|
|
self.setting = setting
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return '<DomainSetting {0} for {1}>'.format(setting, self.domain.name)
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return type(self) == type(other) and self.setting == other.setting
|
|
|
|
|
|
|
|
def set(self, value):
|
|
|
|
try:
|
|
|
|
self.value = value
|
|
|
|
db.session.commit()
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
2020-01-29 15:18:15 +00:00
|
|
|
current_app.logger.error(
|
2019-12-02 03:32:03 +00:00
|
|
|
'Unable to set DomainSetting value. DETAIL: {0}'.format(e))
|
2020-01-29 15:18:15 +00:00
|
|
|
current_app.logger.debug(traceback.format_exc())
|
2019-12-02 03:32:03 +00:00
|
|
|
db.session.rollback()
|
2020-06-19 01:47:51 +00:00
|
|
|
return False
|