From 14581195a4c99736e5dc82fa20e5bc198788ed9a Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 15 Feb 2015 21:56:38 -0600 Subject: [PATCH] Edit zone form --- src/dyns/controllers.py | 15 +++- src/dyns/templates/edit-zone.html.j2 | 7 ++ src/dyns/templates/new-zone.html.j2 | 70 +------------------ src/dyns/templates/zone-form.html.j2 | 101 +++++++++++++++++++++++++++ src/dyns/templates/zone.html.j2 | 1 + 5 files changed, 124 insertions(+), 70 deletions(-) create mode 100644 src/dyns/templates/edit-zone.html.j2 create mode 100644 src/dyns/templates/zone-form.html.j2 diff --git a/src/dyns/controllers.py b/src/dyns/controllers.py index f1c8def..db9c8ee 100644 --- a/src/dyns/controllers.py +++ b/src/dyns/controllers.py @@ -128,6 +128,8 @@ class ZoneController(BaseController): else: if 'new' in request.GET: tmpl = 'new-record.html.j2' + elif 'edit' in request.GET: + tmpl = 'edit-zone.html.j2' else: tmpl = 'zone.html.j2' response.text = self.render(tmpl, zone=zone) @@ -137,13 +139,22 @@ class ZoneController(BaseController): def PUT(self, request, name): response = request.ResponseClass() - response.content_type = 'application/json' - data = json.loads(request.text) + response.content_type = None + 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 + zone = self.get_zone(name) for k, v in data.items(): assert k != 'records' assert hasattr(zone, k) setattr(zone, k, v) self.session.commit() + if request.want in 'xhtml': + raise milla.HTTPSeeOther(location='/zones/{}'.format(zone.name)) + response.status_int = 204 return response def POST(self, request, name): diff --git a/src/dyns/templates/edit-zone.html.j2 b/src/dyns/templates/edit-zone.html.j2 new file mode 100644 index 0000000..c0ef295 --- /dev/null +++ b/src/dyns/templates/edit-zone.html.j2 @@ -0,0 +1,7 @@ +{#- vim: set sw=2 ts=2 sts=2 et : -#} +{% set page_title = zone.name %} +{% extends 'zone-form.html.j2' %} +{%- block breadcrumbs %} +
  • Zones
  • +
  • {{ zone.name }}
  • +{%- endblock %} diff --git a/src/dyns/templates/new-zone.html.j2 b/src/dyns/templates/new-zone.html.j2 index 1078bfd..c4fb3aa 100644 --- a/src/dyns/templates/new-zone.html.j2 +++ b/src/dyns/templates/new-zone.html.j2 @@ -1,74 +1,8 @@ {#- vim: set sw=2 ts=2 sts=2 et : -#} {% set page_title = 'New Zone' %} -{% extends 'base.html.j2' %} +{% set zone = None %} +{% extends 'zone-form.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 %} diff --git a/src/dyns/templates/zone-form.html.j2 b/src/dyns/templates/zone-form.html.j2 new file mode 100644 index 0000000..adcd519 --- /dev/null +++ b/src/dyns/templates/zone-form.html.j2 @@ -0,0 +1,101 @@ +{#- vim: set sw=2 ts=2 sts=2 et : -#} +{% extends 'base.html.j2' %} +{% 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 %} diff --git a/src/dyns/templates/zone.html.j2 b/src/dyns/templates/zone.html.j2 index 758e209..fa55b3c 100644 --- a/src/dyns/templates/zone.html.j2 +++ b/src/dyns/templates/zone.html.j2 @@ -11,6 +11,7 @@
    +Edit