From c94e24c98574da2595729547c9e41decce7ffa26 Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Thu, 11 Feb 2016 16:54:15 +0700 Subject: [PATCH] Adjustment to add multiple records which described issue #5 --- app/models.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index fee409b..ff7d3eb 100644 --- a/app/models.py +++ b/app/models.py @@ -3,6 +3,7 @@ import ldap import time import bcrypt import urlparse +import itertools import traceback from datetime import datetime @@ -699,7 +700,28 @@ class Record(object): ] } records.append(record) - postdata_for_new = {"rrsets": records} + + # Adjustment to add multiple records which described in https://github.com/ngoduykhanh/PowerDNS-Admin/issues/5#issuecomment-181637576 + final_records = [] + records = sorted(records, key = lambda item: (item["name"], item["type"])) + for key, group in itertools.groupby(records, lambda item: (item["name"], item["type"])): + final_records.append({ + "name": key[0], + "type": key[1], + "changetype": "REPLACE", + "records": [ + { + "content": item['records'][0]['content'], + "disabled": item['records'][0]['disabled'], + "name": key[0], + "ttl": item['records'][0]['ttl'], + "type": key[1], + "priority": 10, + } for item in group + ] + }) + + postdata_for_new = {"rrsets": final_records} try: headers = {}