Add cbv to manage Room model.
This commit is contained in:
parent
ad953a48d1
commit
c9641978d7
|
@ -20,6 +20,8 @@
|
|||
'''
|
||||
|
||||
|
||||
import requests
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from django.views.generic import (TemplateView, FormView, View, ListView,
|
||||
|
@ -220,3 +222,60 @@ class AllAlertsCheckView(View):
|
|||
def post(self, request, *args, **kwargs):
|
||||
medibot_models.Episode.objects.all().update(checked=True, checker=request.user)
|
||||
return JsonResponse({'message': 'ok',})
|
||||
|
||||
|
||||
class RoomList(ListView):
|
||||
model = models.Room
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(RoomList, self).get_context_data(**kwargs)
|
||||
try:
|
||||
context['lastpatient'] = models.Patient.objects.get(
|
||||
pk=int(self.request.COOKIES.get(LAST_PATIENT_COOKIE)))
|
||||
except:
|
||||
pass
|
||||
return context
|
||||
|
||||
|
||||
class RoomCreate(CreateView):
|
||||
model = models.Room
|
||||
success_url = reverse_lazy('room_list')
|
||||
fields = ['number']
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(RoomCreate, self).get_context_data(**kwargs)
|
||||
try:
|
||||
context['lastpatient'] = models.Patient.objects.get(
|
||||
pk=int(self.request.COOKIES.get(LAST_PATIENT_COOKIE)))
|
||||
except:
|
||||
pass
|
||||
return context
|
||||
|
||||
|
||||
class RoomUpdate(UpdateView):
|
||||
model = models.Room
|
||||
success_url = reverse_lazy('room_list')
|
||||
fields = ['number']
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(RoomUpdate, self).get_context_data(**kwargs)
|
||||
try:
|
||||
context['lastpatient'] = models.Patient.objects.get(
|
||||
pk=int(self.request.COOKIES.get(LAST_PATIENT_COOKIE)))
|
||||
except:
|
||||
pass
|
||||
return context
|
||||
|
||||
|
||||
class RoomDelete(DeleteView):
|
||||
model = models.Room
|
||||
success_url = reverse_lazy('room_list')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(RoomDelete, self).get_context_data(**kwargs)
|
||||
try:
|
||||
context['lastpatient'] = models.Patient.objects.get(
|
||||
pk=int(self.request.COOKIES.get(LAST_PATIENT_COOKIE)))
|
||||
except:
|
||||
pass
|
||||
return context
|
||||
|
|
Reference in New Issue