Add a timer form template.

This commit is contained in:
Christopher Charbonneau Wells 2017-09-10 04:56:06 -04:00
parent d29e47861d
commit 476b7ece70
5 changed files with 35 additions and 27 deletions

View File

@ -132,8 +132,6 @@ class SleepForm(forms.ModelForm):
class TimerForm(forms.ModelForm):
next = forms.CharField(required=False)
class Meta:
model = Timer
fields = ['name']

View File

@ -1,13 +0,0 @@
<div class="card border-primary text-center mb-2">
<div class="card-header text-white bg-primary ">New Timer</div>
<div class="card-body text-primary">
<form action="{% url 'timer-add' %}" class="form-inline" role="form" method="post">
{% csrf_token %}
<input type="hidden" name="success_url" value="{{ success_url }}" />
<div class="input-group input-group-sm">
<input name="name" value="" class="form-control" id="id_name" maxlength="255" type="text" placeholder="Timer Name (optional)">
<button type="submit" class="input-group-addon btn btn-primary">Start</button>
</div>
</form>
</div>
</div>

View File

@ -0,0 +1,34 @@
{% extends 'babyblotter/page.html' %}
{% load widget_tweaks %}
{% load duration %}
{% block title %}Timer{% endblock %}
{% block content %}
{% if object %}
<h1>Update <span class="text-info">{{ object }}</span></h1>
{% 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">Start Timer</button>
<a href="{% url 'timer-list' %}" class="btn btn-default">Cancel</a>
</form>
{% endblock %}

View File

@ -16,8 +16,3 @@ def timer_nav(context, active=True):
perms = context['perms'] or None
# The 'next' parameter is currently not used.
return {'timers': timers, 'perms': perms, 'next': request.path}
@register.inclusion_tag('core/timer_add.html')
def add_timer(success_url):
return {'success_url': success_url}

View File

@ -165,19 +165,13 @@ class TimerAdd(PermissionRequiredMixin, CreateView):
model = Timer
permission_required = ('core.add_timer',)
form_class = TimerForm
success_url = '/timers'
def get_form_kwargs(self):
kwargs = super(TimerAdd, self).get_form_kwargs()
kwargs.update({'user': self.request.user})
return kwargs
def get_success_url(self):
if resolve(self.request.POST['success_url']).url_name:
url = self.request.POST['success_url']
else:
url = '/'
return url
class TimerAddQuick(PermissionRequiredMixin, RedirectView):
permission_required = ('core.add_timer',)