This commit is contained in:
Khanh Ngo 2016-06-26 20:53:29 +07:00
parent e88a4741c6
commit 7f5a57f80c
2 changed files with 22 additions and 5 deletions

View File

@ -37,7 +37,8 @@ API_EXTENDED_URL = utils.pdns_api_extended_uri(PDNS_VERSION)
# TODO: Find another way to do this # TODO: Find another way to do this
if StrictVersion(PDNS_VERSION) >= StrictVersion('4.0.0'): if StrictVersion(PDNS_VERSION) >= StrictVersion('4.0.0'):
NEW_SCHEMA = True NEW_SCHEMA = True
else:
NEW_SCHEMA = False
class Anonymous(AnonymousUserMixin): class Anonymous(AnonymousUserMixin):
def __init__(self): def __init__(self):

View File

@ -16,11 +16,20 @@ from .models import User, Role, Domain, DomainUser, Record, Server, History, Ano
from io import BytesIO from io import BytesIO
from distutils.util import strtobool from distutils.util import strtobool
from distutils.version import StrictVersion
jinja2.filters.FILTERS['display_record_name'] = utils.display_record_name jinja2.filters.FILTERS['display_record_name'] = utils.display_record_name
jinja2.filters.FILTERS['display_master_name'] = utils.display_master_name jinja2.filters.FILTERS['display_master_name'] = utils.display_master_name
jinja2.filters.FILTERS['display_second_to_time'] = utils.display_time jinja2.filters.FILTERS['display_second_to_time'] = utils.display_time
# Flag for pdns v4.x.x
# TODO: Find another way to do this
PDNS_VERSION = app.config['PDNS_VERSION']
if StrictVersion(PDNS_VERSION) >= StrictVersion('4.0.0'):
NEW_SCHEMA = True
else:
NEW_SCHEMA = False
@app.context_processor @app.context_processor
def inject_fullscreen_layout_setting(): def inject_fullscreen_layout_setting():
fullscreen_layout_setting = Setting.query.filter(Setting.name == 'fullscreen_layout').first() fullscreen_layout_setting = Setting.query.filter(Setting.name == 'fullscreen_layout').first()
@ -250,10 +259,17 @@ def domain(domain_name):
return redirect(url_for('error', code=500)) return redirect(url_for('error', code=500))
records = [] records = []
for jr in jrecords: #TODO: This should be done in the "model" instead of "view"
if jr['type'] in app.config['RECORDS_ALLOW_EDIT']: if NEW_SCHEMA:
for subrecord in jr['records']: for jr in jrecords:
record = Record(name=jr['name'], type=jr['type'], status='Disabled' if subrecord['disabled'] else 'Active', ttl=jr['ttl'], data=subrecord['content']) if jr['type'] in app.config['RECORDS_ALLOW_EDIT']:
for subrecord in jr['records']:
record = Record(name=jr['name'], type=jr['type'], status='Disabled' if subrecord['disabled'] else 'Active', ttl=jr['ttl'], data=subrecord['content'])
records.append(record)
else:
for jr in jrecords:
if jr['type'] in app.config['RECORDS_ALLOW_EDIT']:
record = Record(name=jr['name'], type=jr['type'], status='Disabled' if jr['disabled'] else 'Active', ttl=jr['ttl'], data=jr['content'])
records.append(record) records.append(record)
return render_template('domain.html', domain=domain, records=records, editable_records=app.config['RECORDS_ALLOW_EDIT']) return render_template('domain.html', domain=domain, records=records, editable_records=app.config['RECORDS_ALLOW_EDIT'])
else: else: