diff --git a/app/models.py b/app/models.py index e5fb130..0905e73 100644 --- a/app/models.py +++ b/app/models.py @@ -37,7 +37,8 @@ API_EXTENDED_URL = utils.pdns_api_extended_uri(PDNS_VERSION) # TODO: Find another way to do this if StrictVersion(PDNS_VERSION) >= StrictVersion('4.0.0'): NEW_SCHEMA = True - +else: + NEW_SCHEMA = False class Anonymous(AnonymousUserMixin): def __init__(self): diff --git a/app/views.py b/app/views.py index 3ab403d..a7e8860 100644 --- a/app/views.py +++ b/app/views.py @@ -16,11 +16,20 @@ from .models import User, Role, Domain, DomainUser, Record, Server, History, Ano from io import BytesIO from distutils.util import strtobool +from distutils.version import StrictVersion jinja2.filters.FILTERS['display_record_name'] = utils.display_record_name jinja2.filters.FILTERS['display_master_name'] = utils.display_master_name 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 def inject_fullscreen_layout_setting(): 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)) records = [] - for jr in jrecords: - 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']) + #TODO: This should be done in the "model" instead of "view" + if NEW_SCHEMA: + for jr in jrecords: + 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) return render_template('domain.html', domain=domain, records=records, editable_records=app.config['RECORDS_ALLOW_EDIT']) else: