Commit 5662eacd by Bence Dányi

firewall_gui: save record&domain details

parent 805181a0
......@@ -112,4 +112,6 @@ urlpatterns = patterns('',
url(r'^firewall/vlans/save/$', 'firewall_gui.views.save_vlan'),
url(r'^firewall/vlangroups/save/$', 'firewall_gui.views.save_vlangroup'),
url(r'^firewall/hostgroups/save/$', 'firewall_gui.views.save_hostgroup'),
url(r'^firewall/domains/save/$', 'firewall_gui.views.save_domain'),
url(r'^firewall/records/save/$', 'firewall_gui.views.save_record'),
)
......@@ -618,3 +618,46 @@ def save_hostgroup(request):
return HttpResponse(json.dumps(errors), content_type='application/json', status=400)
hostgroup.save()
return HttpResponse('KTHXBYE')
@user_passes_test(req_staff)
def save_domain(request):
data = json.loads(request.body)
if data['id']:
domain = get_object_or_404(Domain, id=data['id'])
else:
domain = Domain.objects.create()
errors = {}
domain.name = data['name']
domain.ttl = data['ttl']
domain.description = data['description']
set_field(domain, 'owner', errors, username=data['owner']['name'])
try:
domain.full_clean()
except Exception as e:
errors = dict(errors.items() + e.message_dict.items())
if len(errors) > 0:
return HttpResponse(json.dumps(errors), content_type='application/json', status=400)
domain.save()
return HttpResponse('KTHXBYE')
@user_passes_test(req_staff)
def save_record(request):
data = json.loads(request.body)
if data['id']:
record = get_object_or_404(Record, id=data['id'])
else:
record = Record.objects.create()
errors = {}
record.name = data['name']
record.ttl = data['ttl']
record.description = data['description']
set_field(record, 'owner', errors, username=data['owner']['name'])
set_field(record, 'domain', errors, name=data['domain']['name'])
try:
record.full_clean()
except Exception as e:
errors = dict(errors.items() + e.message_dict.items())
if len(errors) > 0:
return HttpResponse(json.dumps(errors), content_type='application/json', status=400)
record.save()
return HttpResponse('KTHXBYE')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment