From b0e863863c7815c0ddbbb833021067fd56204bd7 Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Wed, 8 Jun 2016 11:00:55 +0700 Subject: [PATCH] Adjustment to add multiple records which have same name and type. Add trailing dot in the record's content --- app/models.py | 22 +++++++++++++++++++++- app/views.py | 6 +++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index aca8912..8f3a0e8 100644 --- a/app/models.py +++ b/app/models.py @@ -814,7 +814,27 @@ class Record(object): # Adjustment to add multiple records which described in https://github.com/ngoduykhanh/PowerDNS-Admin/issues/5#issuecomment-181637576 final_records = [] if NEW_SCHEMA: - final_records = records + records = sorted(records, key = lambda item: (item["name"], item["type"])) + for key, group in itertools.groupby(records, lambda item: (item["name"], item["type"])): + new_record = { + "name": key[0], + "type": key[1], + "ttl": records[0]['ttl'], + "changetype": "REPLACE", + "records": [] + } + for item in group: + temp_content = item['records'][0]['content'] + temp_disabled = item['records'][0]['disabled'] + if key[1] in ['MX', 'CNAME', 'SRV', 'NS']: + if temp_content.strip()[-1:] != '.': + temp_content += '.' + + new_record['records'].append({ + "content": temp_content, + "disabled": temp_disabled + }) + final_records.append(new_record) else: records = sorted(records, key = lambda item: (item["name"], item["type"])) for key, group in itertools.groupby(records, lambda item: (item["name"], item["type"])): diff --git a/app/views.py b/app/views.py index 89adad5..f5fa030 100644 --- a/app/views.py +++ b/app/views.py @@ -198,8 +198,9 @@ def domain(domain_name): records = [] 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) + 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) return render_template('domain.html', domain=domain, records=records, editable_records=app.config['RECORDS_ALLOW_EDIT']) else: return redirect(url_for('error', code=404)) @@ -550,4 +551,3 @@ def index(): return redirect(url_for('dashboard')) # END VIEWS -