2017-08-15 19:14:03 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-08-18 13:02:31 +00:00
|
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
2017-08-18 04:48:26 +00:00
|
|
|
from django.urls import reverse
|
2017-08-18 13:02:31 +00:00
|
|
|
from django.views.generic.base import RedirectView
|
2017-08-18 03:45:56 +00:00
|
|
|
from django.views.generic.detail import DetailView
|
2017-08-15 20:24:55 +00:00
|
|
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
2017-11-02 10:39:32 +00:00
|
|
|
|
|
|
|
from django_filters.views import FilterView
|
2017-08-15 19:14:03 +00:00
|
|
|
|
2017-08-17 01:57:01 +00:00
|
|
|
from .models import Child, DiaperChange, Feeding, Note, Sleep, Timer, TummyTime
|
2017-11-01 00:49:10 +00:00
|
|
|
from .forms import (ChildForm, ChildDeleteForm, DiaperChangeForm, FeedingForm,
|
|
|
|
SleepForm, TimerForm, TummyTimeForm)
|
2017-08-15 19:14:03 +00:00
|
|
|
|
2017-08-15 20:24:55 +00:00
|
|
|
|
2017-11-02 10:39:32 +00:00
|
|
|
class ChildList(PermissionRequiredMixin, FilterView):
|
2017-08-16 13:12:49 +00:00
|
|
|
model = Child
|
2017-11-02 10:39:32 +00:00
|
|
|
template_name = 'core/child_list.html'
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.view_child',)
|
2017-09-10 21:02:57 +00:00
|
|
|
paginate_by = 10
|
2017-11-03 11:02:35 +00:00
|
|
|
filter_fields = ('first_name', 'last_name')
|
2017-08-16 13:12:49 +00:00
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class ChildAdd(PermissionRequiredMixin, CreateView):
|
2017-08-16 12:49:58 +00:00
|
|
|
model = Child
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_child',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = ChildForm
|
2017-08-16 13:12:49 +00:00
|
|
|
success_url = '/children'
|
2017-08-15 20:24:55 +00:00
|
|
|
|
|
|
|
|
2017-10-20 19:23:26 +00:00
|
|
|
class ChildDetail(PermissionRequiredMixin, DetailView):
|
|
|
|
model = Child
|
|
|
|
permission_required = ('core.view_child',)
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class ChildUpdate(PermissionRequiredMixin, UpdateView):
|
2017-08-16 12:49:58 +00:00
|
|
|
model = Child
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_child',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = ChildForm
|
2017-08-16 13:12:49 +00:00
|
|
|
success_url = '/children'
|
2017-08-15 20:24:55 +00:00
|
|
|
|
|
|
|
|
2017-11-01 00:49:10 +00:00
|
|
|
class ChildDelete(PermissionRequiredMixin, UpdateView):
|
2017-08-16 12:49:58 +00:00
|
|
|
model = Child
|
2017-11-01 00:49:10 +00:00
|
|
|
form_class = ChildDeleteForm
|
|
|
|
template_name = 'core/child_confirm_delete.html'
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_child',)
|
2017-08-16 13:43:34 +00:00
|
|
|
success_url = '/children'
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-11-02 10:39:32 +00:00
|
|
|
class DiaperChangeList(PermissionRequiredMixin, FilterView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = DiaperChange
|
2017-11-02 10:39:32 +00:00
|
|
|
template_name = 'core/diaperchange_list.html'
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.view_diaperchange',)
|
2017-09-10 21:02:57 +00:00
|
|
|
paginate_by = 10
|
2017-11-03 11:02:35 +00:00
|
|
|
filter_fields = ('child', 'wet', 'solid', 'color')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class DiaperChangeAdd(PermissionRequiredMixin, CreateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = DiaperChange
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_diaperchange',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = DiaperChangeForm
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/changes'
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class DiaperChangeUpdate(PermissionRequiredMixin, UpdateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = DiaperChange
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_diaperchange',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = DiaperChangeForm
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/changes'
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class DiaperChangeDelete(PermissionRequiredMixin, DeleteView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = DiaperChange
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_diaperchange',)
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/changes'
|
|
|
|
|
|
|
|
|
2017-11-02 10:39:32 +00:00
|
|
|
class FeedingList(PermissionRequiredMixin, FilterView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Feeding
|
2017-11-02 10:39:32 +00:00
|
|
|
template_name = 'core/feeding_list.html'
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.view_feeding',)
|
2017-09-10 21:02:57 +00:00
|
|
|
paginate_by = 10
|
2017-11-03 11:02:35 +00:00
|
|
|
filter_fields = ('child', 'type', 'method')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class FeedingAdd(PermissionRequiredMixin, CreateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Feeding
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_feeding',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = FeedingForm
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/feedings'
|
|
|
|
|
2017-08-18 04:42:37 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(FeedingAdd, self).get_form_kwargs()
|
|
|
|
# Add timer to be used by FeedingForm.__init__
|
|
|
|
kwargs.update({'timer': self.request.GET.get('timer', None)})
|
|
|
|
return kwargs
|
|
|
|
|
2017-08-16 15:16:27 +00:00
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class FeedingUpdate(PermissionRequiredMixin, UpdateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Feeding
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_feeding',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = FeedingForm
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/feedings'
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class FeedingDelete(PermissionRequiredMixin, DeleteView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Feeding
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_feeding',)
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/feedings'
|
|
|
|
|
|
|
|
|
2017-11-02 10:39:32 +00:00
|
|
|
class NoteList(PermissionRequiredMixin, FilterView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Note
|
2017-11-02 10:39:32 +00:00
|
|
|
template_name = 'core/note_list.html'
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.view_note',)
|
2017-09-10 21:02:57 +00:00
|
|
|
paginate_by = 10
|
2017-11-03 11:02:35 +00:00
|
|
|
filter_fields = ('child',)
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class NoteAdd(PermissionRequiredMixin, CreateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Note
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_note',)
|
2017-08-16 15:16:27 +00:00
|
|
|
fields = ['child', 'note']
|
|
|
|
success_url = '/notes'
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class NoteUpdate(PermissionRequiredMixin, UpdateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Note
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_note',)
|
2017-08-16 15:16:27 +00:00
|
|
|
fields = ['child', 'note']
|
|
|
|
success_url = '/notes'
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class NoteDelete(PermissionRequiredMixin, DeleteView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Note
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_note',)
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/notes'
|
|
|
|
|
|
|
|
|
2017-11-02 10:39:32 +00:00
|
|
|
class SleepList(PermissionRequiredMixin, FilterView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Sleep
|
2017-11-02 10:39:32 +00:00
|
|
|
template_name = 'core/sleep_list.html'
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.view_sleep',)
|
2017-09-10 21:02:57 +00:00
|
|
|
paginate_by = 10
|
2017-11-03 11:02:35 +00:00
|
|
|
filter_fields = ('child',)
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class SleepAdd(PermissionRequiredMixin, CreateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Sleep
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_sleep',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = SleepForm
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/sleep'
|
|
|
|
|
2017-08-18 04:42:37 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(SleepAdd, self).get_form_kwargs()
|
|
|
|
# Add timer to be used by SleepForm.__init__
|
|
|
|
kwargs.update({'timer': self.request.GET.get('timer', None)})
|
|
|
|
return kwargs
|
|
|
|
|
2017-08-16 15:16:27 +00:00
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class SleepUpdate(PermissionRequiredMixin, UpdateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Sleep
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_sleep',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = SleepForm
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/sleep'
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class SleepDelete(PermissionRequiredMixin, DeleteView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = Sleep
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_sleep',)
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/sleep'
|
|
|
|
|
|
|
|
|
2017-11-02 10:39:32 +00:00
|
|
|
class TimerList(PermissionRequiredMixin, FilterView):
|
2017-09-09 15:54:34 +00:00
|
|
|
model = Timer
|
2017-11-02 10:39:32 +00:00
|
|
|
template_name = 'core/timer_list.html'
|
2017-09-09 15:54:34 +00:00
|
|
|
permission_required = ('core.view_timer',)
|
2017-09-10 21:02:57 +00:00
|
|
|
paginate_by = 10
|
2017-11-03 11:02:35 +00:00
|
|
|
filter_fields = ('active', 'user')
|
2017-09-09 15:54:34 +00:00
|
|
|
|
|
|
|
|
2017-08-18 03:45:56 +00:00
|
|
|
class TimerDetail(PermissionRequiredMixin, DetailView):
|
|
|
|
model = Timer
|
|
|
|
permission_required = ('core.view_timer',)
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class TimerAdd(PermissionRequiredMixin, CreateView):
|
2017-08-17 01:57:01 +00:00
|
|
|
model = Timer
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_timer',)
|
2017-08-17 01:57:01 +00:00
|
|
|
form_class = TimerForm
|
2017-09-10 08:56:06 +00:00
|
|
|
success_url = '/timers'
|
2017-08-17 01:57:01 +00:00
|
|
|
|
2017-08-18 00:42:47 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(TimerAdd, self).get_form_kwargs()
|
|
|
|
kwargs.update({'user': self.request.user})
|
|
|
|
return kwargs
|
|
|
|
|
2017-08-17 01:57:01 +00:00
|
|
|
|
2017-09-10 09:11:09 +00:00
|
|
|
class TimerUpdate(PermissionRequiredMixin, UpdateView):
|
|
|
|
model = Timer
|
|
|
|
permission_required = ('core.change_timer',)
|
|
|
|
form_class = TimerForm
|
|
|
|
success_url = '/timers'
|
|
|
|
|
2017-09-10 13:50:16 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(TimerUpdate, self).get_form_kwargs()
|
|
|
|
kwargs.update({'user': self.request.user})
|
|
|
|
return kwargs
|
|
|
|
|
2017-09-10 09:11:09 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
instance = self.get_object()
|
|
|
|
return '/timer/{}/'.format(instance.id)
|
|
|
|
|
|
|
|
|
2017-08-18 03:10:07 +00:00
|
|
|
class TimerAddQuick(PermissionRequiredMixin, RedirectView):
|
|
|
|
permission_required = ('core.add_timer',)
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
instance = Timer.objects.create(user=request.user)
|
|
|
|
instance.save()
|
2017-08-18 04:48:26 +00:00
|
|
|
self.url = request.GET.get(
|
|
|
|
'next', reverse('timer-detail', args={instance.id}))
|
2017-08-18 03:10:07 +00:00
|
|
|
return super(TimerAddQuick, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
2017-09-09 16:47:41 +00:00
|
|
|
class TimerRestart(PermissionRequiredMixin, RedirectView):
|
|
|
|
permission_required = ('core.change_timer',)
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
instance = Timer.objects.get(id=kwargs['pk'])
|
|
|
|
instance.restart()
|
|
|
|
return super(TimerRestart, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_redirect_url(self, *args, **kwargs):
|
|
|
|
return '/timer/{}'.format(kwargs['pk'])
|
|
|
|
|
|
|
|
|
2017-09-08 18:36:22 +00:00
|
|
|
class TimerStop(PermissionRequiredMixin, RedirectView):
|
|
|
|
permission_required = ('core.change_timer',)
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2017-09-09 16:47:41 +00:00
|
|
|
instance = Timer.objects.get(id=kwargs['pk'])
|
|
|
|
instance.stop()
|
2017-09-08 18:36:22 +00:00
|
|
|
return super(TimerStop, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_redirect_url(self, *args, **kwargs):
|
|
|
|
return '/timer/{}'.format(kwargs['pk'])
|
|
|
|
|
|
|
|
|
2017-08-18 04:55:57 +00:00
|
|
|
class TimerDelete(PermissionRequiredMixin, DeleteView):
|
|
|
|
model = Timer
|
|
|
|
permission_required = ('core.delete_timer',)
|
|
|
|
success_url = '/'
|
|
|
|
|
|
|
|
|
2017-11-02 10:39:32 +00:00
|
|
|
class TummyTimeList(PermissionRequiredMixin, FilterView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = TummyTime
|
2017-11-02 10:39:32 +00:00
|
|
|
template_name = 'core/tummytime_list.html'
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.view_tummytime',)
|
2017-09-10 21:02:57 +00:00
|
|
|
paginate_by = 10
|
2017-11-03 11:02:35 +00:00
|
|
|
filter_fields = ('child',)
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class TummyTimeAdd(PermissionRequiredMixin, CreateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = TummyTime
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_tummytime',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = TummyTimeForm
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/tummy-time'
|
|
|
|
|
2017-08-18 04:42:37 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(TummyTimeAdd, self).get_form_kwargs()
|
|
|
|
# Add timer to be used by TummyTimeForm.__init__
|
|
|
|
kwargs.update({'timer': self.request.GET.get('timer', None)})
|
|
|
|
return kwargs
|
|
|
|
|
2017-08-16 15:16:27 +00:00
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class TummyTimeUpdate(PermissionRequiredMixin, UpdateView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = TummyTime
|
2017-08-18 04:55:57 +00:00
|
|
|
permission_required = ('core.change_tummytime',)
|
2017-08-16 18:57:46 +00:00
|
|
|
form_class = TummyTimeForm
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/tummy-time'
|
|
|
|
|
|
|
|
|
2017-08-17 17:18:14 +00:00
|
|
|
class TummyTimeDelete(PermissionRequiredMixin, DeleteView):
|
2017-08-16 15:16:27 +00:00
|
|
|
model = TummyTime
|
2017-08-18 04:55:57 +00:00
|
|
|
permission_required = ('core.delete_tummytime',)
|
2017-08-16 15:16:27 +00:00
|
|
|
success_url = '/tummy-time'
|