mybuddy/core/views.py

184 lines
4.9 KiB
Python
Raw Normal View History

2017-08-15 19:14:03 +00:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2017-08-17 01:57:01 +00:00
from django.core.urlresolvers import resolve
from django.contrib.auth.mixins import (LoginRequiredMixin,
PermissionRequiredMixin)
2017-08-15 19:14:03 +00:00
from django.views.generic.base import TemplateView
2017-08-15 20:24:55 +00:00
from django.views.generic.edit import CreateView, UpdateView, DeleteView
2017-08-16 13:12:49 +00:00
from django.views.generic.list import ListView
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
from .forms import (ChildForm, DiaperChangeForm, FeedingForm, SleepForm,
2017-08-17 01:57:01 +00:00
TimerForm, TummyTimeForm)
2017-08-15 19:14:03 +00:00
2017-08-15 20:24:55 +00:00
class Dashboard(LoginRequiredMixin, TemplateView):
2017-08-15 19:14:03 +00:00
template_name = 'core/index.html'
2017-08-15 20:24:55 +00:00
class ChildList(PermissionRequiredMixin, ListView):
2017-08-16 13:12:49 +00:00
model = Child
permission_required = ('core.view_child',)
2017-08-16 13:12:49 +00:00
class ChildAdd(PermissionRequiredMixin, CreateView):
2017-08-16 12:49:58 +00:00
model = Child
permission_required = ('core.add_child',)
form_class = ChildForm
2017-08-16 13:12:49 +00:00
success_url = '/children'
2017-08-15 20:24:55 +00:00
class ChildUpdate(PermissionRequiredMixin, UpdateView):
2017-08-16 12:49:58 +00:00
model = Child
permission_required = ('core.change_child',)
form_class = ChildForm
2017-08-16 13:12:49 +00:00
success_url = '/children'
2017-08-15 20:24:55 +00:00
class ChildDelete(PermissionRequiredMixin, DeleteView):
2017-08-16 12:49:58 +00:00
model = Child
permission_required = ('core.delete_child',)
2017-08-16 13:43:34 +00:00
success_url = '/children'
2017-08-16 15:16:27 +00:00
class DiaperChangeList(PermissionRequiredMixin, ListView):
2017-08-16 15:16:27 +00:00
model = DiaperChange
permission_required = ('core.view_diaperchange',)
2017-08-16 15:16:27 +00:00
class DiaperChangeAdd(PermissionRequiredMixin, CreateView):
2017-08-16 15:16:27 +00:00
model = DiaperChange
permission_required = ('core.add_diaperchange',)
form_class = DiaperChangeForm
2017-08-16 15:16:27 +00:00
success_url = '/changes'
class DiaperChangeUpdate(PermissionRequiredMixin, UpdateView):
2017-08-16 15:16:27 +00:00
model = DiaperChange
permission_required = ('core.change_diaperchange',)
form_class = DiaperChangeForm
2017-08-16 15:16:27 +00:00
success_url = '/changes'
class DiaperChangeDelete(PermissionRequiredMixin, DeleteView):
2017-08-16 15:16:27 +00:00
model = DiaperChange
permission_required = ('core.delete_diaperchange',)
2017-08-16 15:16:27 +00:00
success_url = '/changes'
class FeedingList(PermissionRequiredMixin, ListView):
2017-08-16 15:16:27 +00:00
model = Feeding
permission_required = ('core.view_feeding',)
2017-08-16 15:16:27 +00:00
class FeedingAdd(PermissionRequiredMixin, CreateView):
2017-08-16 15:16:27 +00:00
model = Feeding
permission_required = ('core.add_feeding',)
form_class = FeedingForm
2017-08-16 15:16:27 +00:00
success_url = '/feedings'
class FeedingUpdate(PermissionRequiredMixin, UpdateView):
2017-08-16 15:16:27 +00:00
model = Feeding
permission_required = ('core.change_feeding',)
form_class = FeedingForm
2017-08-16 15:16:27 +00:00
success_url = '/feedings'
class FeedingDelete(PermissionRequiredMixin, DeleteView):
2017-08-16 15:16:27 +00:00
model = Feeding
permission_required = ('core.delete_feeding',)
2017-08-16 15:16:27 +00:00
success_url = '/feedings'
class NoteList(PermissionRequiredMixin, ListView):
2017-08-16 15:16:27 +00:00
model = Note
permission_required = ('core.view_note',)
2017-08-16 15:16:27 +00:00
class NoteAdd(PermissionRequiredMixin, CreateView):
2017-08-16 15:16:27 +00:00
model = Note
permission_required = ('core.add_note',)
2017-08-16 15:16:27 +00:00
fields = ['child', 'note']
success_url = '/notes'
class NoteUpdate(PermissionRequiredMixin, UpdateView):
2017-08-16 15:16:27 +00:00
model = Note
permission_required = ('core.change_note',)
2017-08-16 15:16:27 +00:00
fields = ['child', 'note']
success_url = '/notes'
class NoteDelete(PermissionRequiredMixin, DeleteView):
2017-08-16 15:16:27 +00:00
model = Note
permission_required = ('core.delete_note',)
2017-08-16 15:16:27 +00:00
success_url = '/notes'
class SleepList(PermissionRequiredMixin, ListView):
2017-08-16 15:16:27 +00:00
model = Sleep
permission_required = ('core.view_sleep',)
2017-08-16 15:16:27 +00:00
class SleepAdd(PermissionRequiredMixin, CreateView):
2017-08-16 15:16:27 +00:00
model = Sleep
permission_required = ('core.add_sleep',)
form_class = SleepForm
2017-08-16 15:16:27 +00:00
success_url = '/sleep'
class SleepUpdate(PermissionRequiredMixin, UpdateView):
2017-08-16 15:16:27 +00:00
model = Sleep
permission_required = ('core.change_sleep',)
form_class = SleepForm
2017-08-16 15:16:27 +00:00
success_url = '/sleep'
class SleepDelete(PermissionRequiredMixin, DeleteView):
2017-08-16 15:16:27 +00:00
model = Sleep
permission_required = ('core.delete_sleep',)
2017-08-16 15:16:27 +00:00
success_url = '/sleep'
class TimerAdd(PermissionRequiredMixin, CreateView):
2017-08-17 01:57:01 +00:00
model = Timer
permission_required = ('core.add_timer',)
2017-08-17 01:57:01 +00:00
form_class = TimerForm
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
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(PermissionRequiredMixin, ListView):
2017-08-16 15:16:27 +00:00
model = TummyTime
permission_required = ('core.view_tummytime',)
2017-08-16 15:16:27 +00:00
class TummyTimeAdd(PermissionRequiredMixin, CreateView):
2017-08-16 15:16:27 +00:00
model = TummyTime
permission_required = ('core.add_tummytime',)
form_class = TummyTimeForm
2017-08-16 15:16:27 +00:00
success_url = '/tummy-time'
class TummyTimeUpdate(PermissionRequiredMixin, UpdateView):
2017-08-16 15:16:27 +00:00
model = TummyTime
form_class = TummyTimeForm
2017-08-16 15:16:27 +00:00
success_url = '/tummy-time'
class TummyTimeDelete(PermissionRequiredMixin, DeleteView):
2017-08-16 15:16:27 +00:00
model = TummyTime
success_url = '/tummy-time'