mirror of https://github.com/snachodog/mybuddy.git
Add ability to create a Timer.
This commit is contained in:
parent
387535a200
commit
72b1f3e37b
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django import forms
|
||||
|
||||
from .models import Child, DiaperChange, Feeding, Sleep, TummyTime
|
||||
from .models import Child, DiaperChange, Feeding, Sleep, Timer, TummyTime
|
||||
|
||||
|
||||
class ChildForm(forms.ModelForm):
|
||||
|
@ -68,6 +68,14 @@ class SleepForm(forms.ModelForm):
|
|||
}
|
||||
|
||||
|
||||
class TimerForm(forms.ModelForm):
|
||||
next = forms.CharField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = Timer
|
||||
fields = ['name']
|
||||
|
||||
|
||||
class TummyTimeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = TummyTime
|
||||
|
|
|
@ -131,6 +131,7 @@ class Timer(models.Model):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
self.active = self.end is None
|
||||
self.name = self.name or 'Unnamed Timer'
|
||||
super(Timer, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
</div>
|
||||
<div class="col-lg-2">
|
||||
<h1>Timers</h1>
|
||||
{% add_timer request.path %}
|
||||
{% list_timers %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<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>
|
|
@ -1,16 +1,3 @@
|
|||
<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 class="form-inline" role="form" method="post">
|
||||
{% csrf_token %}
|
||||
<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>
|
||||
|
||||
{% for timer in timers %}
|
||||
<div class="card border-success text-center mb-2">
|
||||
<div class="card-header text-white bg-success ">{{ timer.name }}</div>
|
||||
|
|
|
@ -13,3 +13,9 @@ register = template.Library()
|
|||
def list_timers(active=True):
|
||||
timers = Timer.objects.filter(active=active)
|
||||
return {'timers': timers}
|
||||
|
||||
|
||||
@register.inclusion_tag('timer_add.html')
|
||||
def add_timer(success_url):
|
||||
return {'success_url': success_url}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ urlpatterns = [
|
|||
url(r'sleep/(?P<pk>[0-9]+)/delete/$', views.SleepDelete.as_view(),
|
||||
name='sleep-delete'),
|
||||
|
||||
url(r'timer/add/$', views.TimerAdd.as_view(), name='timer-add'),
|
||||
|
||||
url(r'tummy-time/$', views.TummyTimeList.as_view(), name='tummytime-list'),
|
||||
url(r'tummy-time/add/$', views.TummyTimeAdd.as_view(),
|
||||
name='tummytime-add'),
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.core.urlresolvers import resolve
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.views.generic.list import ListView
|
||||
|
||||
from .models import Child, DiaperChange, Feeding, Note, Sleep, TummyTime
|
||||
from .models import Child, DiaperChange, Feeding, Note, Sleep, Timer, TummyTime
|
||||
from .forms import (ChildForm, DiaperChangeForm, FeedingForm, SleepForm,
|
||||
TummyTimeForm)
|
||||
TimerForm, TummyTimeForm)
|
||||
|
||||
|
||||
class Dashboard(LoginRequiredMixin, TemplateView):
|
||||
|
@ -120,6 +121,18 @@ class SleepDelete(LoginRequiredMixin, DeleteView):
|
|||
success_url = '/sleep'
|
||||
|
||||
|
||||
class TimerAdd(LoginRequiredMixin, CreateView):
|
||||
model = Timer
|
||||
form_class = TimerForm
|
||||
|
||||
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 TummyTimeList(LoginRequiredMixin, ListView):
|
||||
model = TummyTime
|
||||
|
||||
|
|
Loading…
Reference in New Issue