Adjustment to add multiple records which have same name and type. Add trailing dot in the record's content

This commit is contained in:
Khanh Ngo 2016-06-08 11:00:55 +07:00
parent fb51bce1f8
commit b0e863863c
2 changed files with 24 additions and 4 deletions

View file

@ -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"])):

View file

@ -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