mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 22:50:26 +00:00
56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
import traceback
|
|
|
|
from flask import current_app
|
|
from datetime import datetime
|
|
|
|
from .base import db
|
|
|
|
|
|
class History(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
msg = db.Column(db.String(256))
|
|
# detail = db.Column(db.Text().with_variant(db.Text(length=2**24-2), 'mysql'))
|
|
detail = db.Column(db.Text())
|
|
created_by = db.Column(db.String(128))
|
|
created_on = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
|
domain_id = db.Column(db.Integer,
|
|
db.ForeignKey('domain.id'),
|
|
nullable=True)
|
|
|
|
def __init__(self, id=None, msg=None, detail=None, created_by=None, domain_id=None):
|
|
self.id = id
|
|
self.msg = msg
|
|
self.detail = detail
|
|
self.created_by = created_by
|
|
self.domain_id = domain_id
|
|
|
|
def __repr__(self):
|
|
return '<History {0}>'.format(self.msg)
|
|
|
|
def add(self):
|
|
"""
|
|
Add an event to history table
|
|
"""
|
|
h = History()
|
|
h.msg = self.msg
|
|
h.detail = self.detail
|
|
h.created_by = self.created_by
|
|
h.domain_id = self.domain_id
|
|
db.session.add(h)
|
|
db.session.commit()
|
|
|
|
def remove_all(self):
|
|
"""
|
|
Remove all history from DB
|
|
"""
|
|
try:
|
|
db.session.query(History).delete()
|
|
db.session.commit()
|
|
current_app.logger.info("Removed all history")
|
|
return True
|
|
except Exception as e:
|
|
db.session.rollback()
|
|
current_app.logger.error("Cannot remove history. DETAIL: {0}".format(e))
|
|
current_app.logger.debug(traceback.format_exc())
|
|
return False
|