diff --git a/src/dyns/controllers.py b/src/dyns/controllers.py index 8b65a8e..84a6c8e 100644 --- a/src/dyns/controllers.py +++ b/src/dyns/controllers.py @@ -71,22 +71,36 @@ class ZoneListController(BaseController): response.content_type = 'application/json' json.dump(list(map(model.Zone.as_dict, zones)), response.body_file) else: - response.text = self.render('index.html.j2', zones=zones) + if 'new' in request.GET: + response.text = self.render('new-zone.html.j2') + else: + response.text = self.render('index.html.j2', zones=zones) return response HEAD = GET def POST(self, request): response = request.ResponseClass() - response.content_type = None - data = json.loads(request.text) + if request.content_type == 'application/x-www-form-urlencoded': + data = dict(request.POST) + elif request.content_type == 'application/json': + data = json.loads(request.text) + else: + raise milla.HTTPUnsupportedMediaType + required_fields = ('name', 'contact', 'source') + for k in list(data.keys()): + if not data[k]: + if k not in required_fields: + del data[k] zone = model.Zone(**data) self.session.add(zone) self.session.commit() - response.status_int = 201 - response.location = request.create_href_full( - '/zones/{}'.format(zone.name) - ) + location = request.create_href_full('/zones/{}'.format(zone.name)) + if request.want in ('html', 'xhtml'): + raise milla.HTTPSeeOther(location=location) + else: + response.status_int = 201 + response.location = location return response diff --git a/src/dyns/templates/base.html.j2 b/src/dyns/templates/base.html.j2 new file mode 100644 index 0000000..1a18389 --- /dev/null +++ b/src/dyns/templates/base.html.j2 @@ -0,0 +1,30 @@ +{#- vim: set sw=2 ts=2 sts=2 et : -#} + + +
+ +Name | +Contact | +Serial | +
---|---|---|
{{ zone.name }} | +{{ zone.contact }} | +{{ zone.serial }} | +