From ad70b77db559a09a102734c5524cf97fac81a040 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 15 Feb 2015 18:31:26 -0600 Subject: [PATCH] Zone list page and new zone form Signed-off-by: Dustin C. Hatch --- src/dyns/controllers.py | 28 ++++++++--- src/dyns/templates/base.html.j2 | 30 ++++++++++++ src/dyns/templates/index.html.j2 | 36 +++++++++----- src/dyns/templates/new-zone.html.j2 | 74 +++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 18 deletions(-) create mode 100644 src/dyns/templates/base.html.j2 create mode 100644 src/dyns/templates/new-zone.html.j2 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 : -#} + + + + +{{ page_title }} :: DyNS + + + + + + +
+

DyNS

+ +
+ +
+

{{ page_title }}

+{% block body %}{% endblock -%} +
+ + + diff --git a/src/dyns/templates/index.html.j2 b/src/dyns/templates/index.html.j2 index 6f9ec9c..63a244e 100644 --- a/src/dyns/templates/index.html.j2 +++ b/src/dyns/templates/index.html.j2 @@ -1,13 +1,27 @@ - - - - -Zones - - -

Zones

+{#- vim: set sw=2 ts=2 sts=2 et : -#} +{% set page_title = 'Zones' -%} +{% extends 'base.html.j2' %} +{%- block breadcrumbs %} +
  • Zones
  • +{%- endblock %} +{% block body -%} +New Zone + + + + + + + + + {% for zone in zones -%} -
    {{ zone.name }}
    + + + + + {% endfor -%} - - + +
    NameContactSerial
    {{ zone.name }}{{ zone.contact }}{{ zone.serial }}
    +{% endblock %} diff --git a/src/dyns/templates/new-zone.html.j2 b/src/dyns/templates/new-zone.html.j2 new file mode 100644 index 0000000..1078bfd --- /dev/null +++ b/src/dyns/templates/new-zone.html.j2 @@ -0,0 +1,74 @@ +{#- vim: set sw=2 ts=2 sts=2 et : -#} +{% set page_title = 'New Zone' %} +{% extends 'base.html.j2' %} +{%- block breadcrumbs %} +
  • Zones
  • +
  • New Zone
  • +{%- endblock %} +{% block body -%} +
    +{% set domain_regex = '(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\\.)+[a-zA-Z]{2,63}$)' %} +{% set fqdn_regex = '(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\\.)+[a-zA-Z]{2,63}\\.?$)' %} +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    +{% endblock %}