2017-08-15 19:14:03 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-12-06 19:40:04 +00:00
|
|
|
from django.contrib import messages
|
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
2017-12-06 22:16:47 +00:00
|
|
|
from django.urls import reverse, reverse_lazy
|
2017-11-07 18:15:48 +00:00
|
|
|
from django.utils import timezone
|
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
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
from babybuddy.mixins import PermissionRequired403Mixin
|
2017-11-07 18:15:48 +00:00
|
|
|
from core import forms, models, timeline
|
2017-08-15 19:14:03 +00:00
|
|
|
|
2017-08-15 20:24:55 +00:00
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class CoreAddView(PermissionRequired403Mixin, SuccessMessageMixin, CreateView):
|
2017-12-06 19:40:04 +00:00
|
|
|
def get_success_message(self, cleaned_data):
|
|
|
|
cleaned_data['model'] = self.model._meta.verbose_name.title()
|
|
|
|
if 'child' in cleaned_data:
|
|
|
|
self.success_message = '%(model)s entry for %(child)s added!'
|
|
|
|
else:
|
|
|
|
self.success_message = '%(model)s entry added!'
|
|
|
|
return self.success_message % cleaned_data
|
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class CoreUpdateView(PermissionRequired403Mixin, SuccessMessageMixin,
|
|
|
|
UpdateView):
|
2017-12-06 19:40:04 +00:00
|
|
|
def get_success_message(self, cleaned_data):
|
|
|
|
cleaned_data['model'] = self.model._meta.verbose_name.title()
|
|
|
|
if 'child' in cleaned_data:
|
|
|
|
self.success_message = '%(model)s entry for %(child)s updated.'
|
|
|
|
else:
|
|
|
|
self.success_message = '%(model)s entry updated.'
|
|
|
|
return self.success_message % cleaned_data
|
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class CoreDeleteView(PermissionRequired403Mixin, DeleteView):
|
2017-12-06 19:40:04 +00:00
|
|
|
"""
|
|
|
|
SuccessMessageMixin is not compatible DeleteView.
|
|
|
|
See: https://code.djangoproject.com/ticket/21936
|
|
|
|
"""
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
|
|
success_message = '{} entry deleted.'.format(
|
|
|
|
self.model._meta.verbose_name.title())
|
|
|
|
messages.success(request, success_message)
|
|
|
|
return super(CoreDeleteView, self).delete(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class ChildList(PermissionRequired403Mixin, FilterView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.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-12-06 19:40:04 +00:00
|
|
|
class ChildAdd(CoreAddView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Child
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_child',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.ChildForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:child-list')
|
2017-12-06 19:40:04 +00:00
|
|
|
success_message = '%(first_name)s %(last_name)s added!'
|
2017-08-15 20:24:55 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class ChildDetail(PermissionRequired403Mixin, DetailView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Child
|
2017-10-20 19:23:26 +00:00
|
|
|
permission_required = ('core.view_child',)
|
|
|
|
|
2017-11-07 18:15:48 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(ChildDetail, self).get_context_data(**kwargs)
|
|
|
|
date = self.request.GET.get('date', str(timezone.localdate()))
|
|
|
|
date = timezone.datetime.strptime(date, '%Y-%m-%d')
|
|
|
|
date = timezone.localtime(timezone.make_aware(date))
|
|
|
|
context['timeline_objects'] = timeline.get_objects(self.object, date)
|
|
|
|
context['date'] = date
|
|
|
|
context['date_previous'] = date - timezone.timedelta(days=1)
|
|
|
|
if date.date() < timezone.localdate():
|
|
|
|
context['date_next'] = date + timezone.timedelta(days=1)
|
|
|
|
return context
|
|
|
|
|
2017-10-20 19:23:26 +00:00
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class ChildUpdate(CoreUpdateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Child
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_child',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.ChildForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:child-list')
|
2017-08-15 20:24:55 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class ChildDelete(CoreUpdateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Child
|
|
|
|
form_class = forms.ChildDeleteForm
|
2017-11-01 00:49:10 +00:00
|
|
|
template_name = 'core/child_confirm_delete.html'
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_child',)
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:child-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class DiaperChangeList(PermissionRequired403Mixin, FilterView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.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-12-06 19:40:04 +00:00
|
|
|
class DiaperChangeAdd(CoreAddView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.DiaperChange
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_diaperchange',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.DiaperChangeForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:diaperchange-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class DiaperChangeUpdate(CoreUpdateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.DiaperChange
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_diaperchange',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.DiaperChangeForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:diaperchange-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class DiaperChangeDelete(CoreDeleteView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.DiaperChange
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_diaperchange',)
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:diaperchange-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class FeedingList(PermissionRequired403Mixin, FilterView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.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-12-06 19:40:04 +00:00
|
|
|
class FeedingAdd(CoreAddView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Feeding
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_feeding',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.FeedingForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:feeding-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
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-12-06 19:40:04 +00:00
|
|
|
class FeedingUpdate(CoreUpdateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Feeding
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_feeding',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.FeedingForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:feeding-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class FeedingDelete(CoreDeleteView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Feeding
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_feeding',)
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:feeding-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class NoteList(PermissionRequired403Mixin, FilterView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.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-12-06 19:40:04 +00:00
|
|
|
class NoteAdd(CoreAddView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Note
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_note',)
|
2017-11-10 00:50:54 +00:00
|
|
|
form_class = forms.NoteForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:note-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class NoteUpdate(CoreUpdateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.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']
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:note-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class NoteDelete(CoreDeleteView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Note
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_note',)
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:note-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class SleepList(PermissionRequired403Mixin, FilterView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.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-12-06 19:40:04 +00:00
|
|
|
class SleepAdd(CoreAddView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Sleep
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_sleep',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.SleepForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:sleep-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
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-12-06 19:40:04 +00:00
|
|
|
class SleepUpdate(CoreUpdateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Sleep
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.change_sleep',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.SleepForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:sleep-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class SleepDelete(CoreDeleteView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Sleep
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.delete_sleep',)
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:sleep-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class TimerList(PermissionRequired403Mixin, FilterView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.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
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class TimerDetail(PermissionRequired403Mixin, DetailView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Timer
|
2017-08-18 03:45:56 +00:00
|
|
|
permission_required = ('core.view_timer',)
|
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class TimerAdd(PermissionRequired403Mixin, CreateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Timer
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_timer',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.TimerForm
|
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-12-06 22:16:47 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
return reverse('core:timer-detail', kwargs={'pk': self.object.pk})
|
|
|
|
|
2017-08-17 01:57:01 +00:00
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class TimerUpdate(CoreUpdateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Timer
|
2017-09-10 09:11:09 +00:00
|
|
|
permission_required = ('core.change_timer',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.TimerForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:timer-list')
|
2017-09-10 09:11:09 +00:00
|
|
|
|
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()
|
2017-12-06 22:16:47 +00:00
|
|
|
return reverse('core:timer-detail', kwargs={'pk': instance.pk})
|
2017-09-10 09:11:09 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class TimerAddQuick(PermissionRequired403Mixin, RedirectView):
|
2017-08-18 03:10:07 +00:00
|
|
|
permission_required = ('core.add_timer',)
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2017-11-07 18:15:48 +00:00
|
|
|
instance = models.Timer.objects.create(user=request.user)
|
2017-08-18 03:10:07 +00:00
|
|
|
instance.save()
|
2017-08-18 04:48:26 +00:00
|
|
|
self.url = request.GET.get(
|
2017-12-03 21:52:27 +00:00
|
|
|
'next', reverse('core:timer-detail', args={instance.id}))
|
2017-08-18 03:10:07 +00:00
|
|
|
return super(TimerAddQuick, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class TimerRestart(PermissionRequired403Mixin, RedirectView):
|
2017-09-09 16:47:41 +00:00
|
|
|
permission_required = ('core.change_timer',)
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2017-11-07 18:15:48 +00:00
|
|
|
instance = models.Timer.objects.get(id=kwargs['pk'])
|
2017-09-09 16:47:41 +00:00
|
|
|
instance.restart()
|
2017-12-06 19:40:04 +00:00
|
|
|
messages.success(request, '{} restarted.'.format(instance))
|
2017-09-09 16:47:41 +00:00
|
|
|
return super(TimerRestart, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_redirect_url(self, *args, **kwargs):
|
2017-12-06 22:16:47 +00:00
|
|
|
return reverse('core:timer-detail', kwargs={'pk': kwargs['pk']})
|
2017-09-09 16:47:41 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class TimerStop(PermissionRequired403Mixin, SuccessMessageMixin, RedirectView):
|
2017-09-08 18:36:22 +00:00
|
|
|
permission_required = ('core.change_timer',)
|
2017-12-06 19:40:04 +00:00
|
|
|
success_message = '%(timer)s stopped.'
|
2017-09-08 18:36:22 +00:00
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2017-11-07 18:15:48 +00:00
|
|
|
instance = models.Timer.objects.get(id=kwargs['pk'])
|
2017-09-09 16:47:41 +00:00
|
|
|
instance.stop()
|
2017-12-06 19:40:04 +00:00
|
|
|
messages.success(request, '{} stopped.'.format(instance))
|
2017-09-08 18:36:22 +00:00
|
|
|
return super(TimerStop, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_redirect_url(self, *args, **kwargs):
|
2017-12-06 22:16:47 +00:00
|
|
|
return reverse('core:timer-detail', kwargs={'pk': kwargs['pk']})
|
2017-09-08 18:36:22 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class TimerDelete(CoreDeleteView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.Timer
|
2017-08-18 04:55:57 +00:00
|
|
|
permission_required = ('core.delete_timer',)
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:timer-list')
|
2017-08-18 04:55:57 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class TummyTimeList(PermissionRequired403Mixin, FilterView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.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-12-06 19:40:04 +00:00
|
|
|
class TummyTimeAdd(CoreAddView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.TummyTime
|
2017-08-17 17:18:14 +00:00
|
|
|
permission_required = ('core.add_tummytime',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.TummyTimeForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:tummytime-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
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-12-06 19:40:04 +00:00
|
|
|
class TummyTimeUpdate(CoreUpdateView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.TummyTime
|
2017-08-18 04:55:57 +00:00
|
|
|
permission_required = ('core.change_tummytime',)
|
2017-11-07 18:15:48 +00:00
|
|
|
form_class = forms.TummyTimeForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:tummytime-list')
|
2017-08-16 15:16:27 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class TummyTimeDelete(CoreDeleteView):
|
2017-11-07 18:15:48 +00:00
|
|
|
model = models.TummyTime
|
2017-08-18 04:55:57 +00:00
|
|
|
permission_required = ('core.delete_tummytime',)
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:tummytime-list')
|
2017-11-10 02:15:09 +00:00
|
|
|
|
|
|
|
|
2018-05-20 21:40:09 +00:00
|
|
|
class WeightList(PermissionRequired403Mixin, FilterView):
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Weight
|
|
|
|
template_name = 'core/weight_list.html'
|
|
|
|
permission_required = ('core.view_weight',)
|
|
|
|
paginate_by = 10
|
|
|
|
filter_fields = ('child',)
|
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class WeightAdd(CoreAddView):
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Weight
|
|
|
|
permission_required = ('core.add_weight',)
|
|
|
|
form_class = forms.WeightForm
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:weight-list')
|
2017-11-10 02:15:09 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class WeightUpdate(CoreUpdateView):
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Weight
|
|
|
|
permission_required = ('core.change_weight',)
|
|
|
|
fields = ['child', 'weight', 'date']
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:weight-list')
|
2017-11-10 02:15:09 +00:00
|
|
|
|
|
|
|
|
2017-12-06 19:40:04 +00:00
|
|
|
class WeightDelete(CoreDeleteView):
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Weight
|
|
|
|
permission_required = ('core.delete_weight',)
|
2017-12-06 22:16:47 +00:00
|
|
|
success_url = reverse_lazy('core:weight-list')
|