Use a generic form template for existing forms.

This commit is contained in:
Christopher Charbonneau Wells 2017-09-17 09:00:34 -04:00
parent 36847f0bd2
commit a89a237b5c
8 changed files with 29 additions and 154 deletions

View File

@ -0,0 +1,22 @@
{% load widget_tweaks %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>
</form>

View File

@ -1,5 +1,4 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% block title %}
{% if request.resolver_match.url_name == 'child-update' %}
@ -15,27 +14,7 @@
{% else %}
<h1>Add a Child</h1>
{% endif %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% url 'child-list' %}" class="btn btn-default">Cancel</a>
</form>
{% include 'babyblotter/form.html' %}
{% endblock %}
{% block javascript %}

View File

@ -1,5 +1,4 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% block title %}
{% if request.resolver_match.url_name == 'diaperchange-update' %}
@ -15,27 +14,7 @@
{% else %}
<h1>Add a Diaper Change</h1>
{% endif %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% url 'diaperchange-list' %}" class="btn btn-default">Cancel</a>
</form>
{% include 'babyblotter/form.html' %}
{% endblock %}
{% block javascript %}

View File

@ -1,5 +1,4 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% block title %}
{% if request.resolver_match.url_name == 'feeding-update' %}
@ -15,27 +14,7 @@
{% else %}
<h1>Add a Feeding</h1>
{% endif %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% url 'feeding-list' %}" class="btn btn-default">Cancel</a>
</form>
{% include 'babyblotter/form.html' %}
{% endblock %}
{% block javascript %}

View File

@ -1,5 +1,4 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% block title %}
{% if request.resolver_match.url_name == 'note-update' %}
@ -15,25 +14,5 @@
{% else %}
<h1>Add a Note</h1>
{% endif %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% url 'note-list' %}" class="btn btn-default">Cancel</a>
</form>
{% include 'babyblotter/form.html' %}
{% endblock %}

View File

@ -1,5 +1,4 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% block title %}
{% if request.resolver_match.url_name == 'sleep-update' %}
@ -15,27 +14,7 @@
{% else %}
<h1>Add a Sleep Entry</h1>
{% endif %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% url 'sleep-list' %}" class="btn btn-default">Cancel</a>
</form>
{% include 'babyblotter/form.html' %}
{% endblock %}
{% block javascript %}

View File

@ -1,5 +1,4 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% load duration %}
{% block title %}Timer{% endblock %}
@ -10,25 +9,5 @@
{% else %}
<h1>Start Timer</h1>
{% endif %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-success">Submit</button>
<a href="{% url 'timer-list' %}" class="btn btn-default">Cancel</a>
</form>
{% include 'babyblotter/form.html' %}
{% endblock %}

View File

@ -1,5 +1,4 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% block title %}
{% if request.resolver_match.url_name == 'tummytime-update' %}
@ -15,27 +14,7 @@
{% else %}
<h1>Add a Tummy Time Entry</h1>
{% endif %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% url 'tummytime-list' %}" class="btn btn-default">Cancel</a>
</form>
{% include 'babyblotter/form.html' %}
{% endblock %}
{% block javascript %}