def caregiver(self, request): posting = None # Posting.get_latest_post() if request.session['active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) caregiver = CareGiver.objects.get(user=request.user) today = datetime.combine(date.today(), time.min) lastweek = today - timedelta(days=7) tracker = elder.tracker_set.filter(created__gte=lastweek) blood = tracker.filter(type="bg") heartrate = tracker.filter(type="hr") daily_condition = tracker.filter(type="cd") elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) return render( request, 'index.html', { 'active_elder': elder, 'elders': elders, 'info': posting, 'caregiver': caregiver, 'blood': blood, 'heartrate': heartrate, 'daily_condition': daily_condition }) else: caregiver = CareGiver.objects.get(user=request.user) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) return render(request, 'index.html', { 'caregiver': caregiver, 'elders': elders })
def post(self, request): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) form = MedicalTreatmentForm(request.POST) medis = MedicalTreatmentHist.objects.filter( elder=elder).order_by('-id') if form.is_valid(): new = form.save(commit=False) new.elder = elder new.save() medis = MedicalTreatmentHist.objects.filter( elder=elder).order_by('-id') return render( request, 'medis.html', { 'elders': elders, 'success': "Data berhasil ditambahkan", 'active_elder': elder, 'medis': medis }) else: return render( request, 'medis.html', { 'elders': elders, 'error': form.errors, 'active_elder': elder, 'medis': medis }) else: return HttpResponseRedirect(reverse('index'))
def post(self, request, type, id): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) info = Posting.objects.filter(category=type, id=id) if info: form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.owner = request.user comment.posting = info[0] comment.save() return render( request, 'post_view.html', { 'elders': elders, 'tag': type, 'active_elder': elder, 'success': 'Komentar berhasil ditambahkan', 'info': info[0] }) return render( request, 'post_view.html', { 'elders': elders, 'tag': type, 'active_elder': elder, 'error': form.errors, 'info': info[0] }) return HttpResponseRedirect(reverse(type))
def post(self, request): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) feedback = Feedback.objects.filter(owner=request.user) form = FeedbackForm(request.POST) if form.is_valid(): new = form.save(commit=False) new.status = 's' new.owner = request.user new.save() feedback = Feedback.objects.filter(owner=request.user) return render( request, 'feedback.html', { 'elders': elders, 'success': 'Feedback berhasil ditambahkan', 'active_elder': elder, 'feedback': feedback }) else: return render( request, 'feedback.html', { 'elders': elders, 'error': form.errors, 'active_elder': elder, 'feedback': feedback })
def post(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) contact = Contact.objects.filter( elder=elder, id=id, added_by=CareGiver.objects.get(user=request.user)) if contact: form = ContactForm(request.POST, instance=contact[0]) if form.is_valid(): contact = form.save() return render( request, 'contact_edit.html', { 'elders': elders, 'success': "Data berhasil dirubah", 'active_elder': elder, 'contact': contact }) return render( request, 'contact_edit.html', { 'elders': elders, 'active_elder': elder, 'error': form.errors, 'contact': contact[0] }) return HttpResponseRedirect(reverse('contact')) return HttpResponseRedirect(reverse('index'))
def post(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) disease = DiseaseHist.objects.filter(elder=elder, id=id) if disease: form = DiseaseHistForm(request.POST, instance=disease[0]) if form.is_valid(): disease = form.save() return render( request, 'disease_edit.html', { 'elders': elders, 'success': "Data berhasil dirubah", 'active_elder': elder, 'disease': disease }) return render( request, 'disease_edit.html', { 'elders': elders, 'active_elder': elder, 'error': form.errors, 'disease': disease[0] }) return HttpResponseRedirect(reverse('treatment')) return HttpResponseRedirect(reverse('index'))
def post(self, request, id): if is_caregiver(request.user): cek_session(request) active = None if request.session.get('active_elder') is not None and \ request.session['active_elder'] != 0: active = Elder.objects.get( pk=request.session.get('active_elder')) elders = Elder.get_cared_elder( user=CareGiver.objects.get(user=request.user)) elder = elders.filter(id=id) if elder: userform = ElderUserForm(request.POST, instance=elder[0].user) elderform = ElderForm( request.POST, request.FILES, instance=elder[0]) if userform.is_valid() and elderform.is_valid(): userform.save() elder = elderform.save() return render(request, 'parents_edit.html', {'elders': elders, 'success': "Data tersimpan", 'active_elder': active, 'edit': elder}) else: userform.errors.update(elderform.errors) return render(request, 'parents_edit.html', {'elders': elders, 'error': userform.errors, 'active_elder': active, 'edit': elder[0]}) return HttpResponseRedirect(reverse('parents')) else: return HttpResponseRedirect(reverse('index'))
def post(self, request, id): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) feedback = Feedback.objects.filter(owner=request.user, id=id) if feedback: form = ResponseForm(request.POST) if form.is_valid(): new = form.save(commit=False) new.owner = request.user new.feedback = feedback[0] new.save() return render( request, 'feedback_view.html', { 'elders': elders, 'success': 'Respon berhasil ditambahkan', 'active_elder': elder, 'feedback': feedback[0] }) return render( request, 'feedback_view.html', { 'elders': elders, 'error': form.errors, 'active_elder': elder, 'feedback': feedback[0] }) return HttpResponseRedirect(reverse('notif_elder'))
def post(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) note = Note.objects.filter( elder=elder, id=id, user=CareGiver.objects.get(user=request.user)) if note: form = NoteForm(request.POST, instance=note[0]) if form.is_valid(): note = form.save() return render( request, 'note_edit.html', { 'elders': elders, 'success': "Note berhasil dirubah", 'active_elder': elder, 'note': note }) return render( request, 'note_edit.html', { 'elders': elders, 'active_elder': elder, 'error': form.errors, 'note': note[0] }) return HttpResponseRedirect(reverse('note')) return HttpResponseRedirect(reverse('index'))
def cek_session(request): if 'active_elder' not in request.session: elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) if elders: request.session['active_elder'] = elders[0].id else: request.session['active_elder'] = 0
def get_queryset(self): if self.request.user.is_authenticated(): if CareGiver.objects.filter(user=self.request.user): caregiver = CareGiver.objects.get(user=self.request.user) return MedicalTreatmentHist.objects.filter( elder__in=Elder.get_cared_elder(caregiver)) elif Elder.objects.filter(user=self.request.user): elder = Elder.objects.get(user=self.request.user) return MedicalTreatmentHist.objects.filter(elder=elder) return MedicalTreatmentHist.objects.all()
def get(self, request): cek_session(request) elder = None if (request.session.get('active_elder') is not None and request.session['active_elder'] != 0): elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder( user=CareGiver.objects.get(user=request.user)) return render(request, 'parents.html', {'elders': elders, 'active_elder': elder})
def get(self, request): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) feedback = Feedback.objects.filter(owner=request.user) return render(request, 'feedback.html', { 'elders': elders, 'active_elder': elder, 'feedback': feedback })
def get(self, request): if is_caregiver(request.user): cek_session(request) active = None if request.session.get('active_elder') is not None and \ request.session['active_elder'] != 0: active = Elder.objects.get( pk=request.session.get('active_elder')) elders = Elder.get_cared_elder( user=CareGiver.objects.get(user=request.user)) return render(request, 'profile_edit.html', {'elders': elders, 'active_elder': active}) else: return render(request, 'partner/profile_edit.html')
def post(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) disease = DiseaseHist.objects.filter(elder=elder, id=id) if disease: name = disease[0].name disease.delete() messages.success(request, 'Data "' + name + '" telah berhasil dihapus.') return HttpResponseRedirect(reverse('treatment'))
def get(self, request, id): cek_session(request) active = None if request.session.get('active_elder') is not None and \ request.session['active_elder'] != 0: active = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder( user=CareGiver.objects.get(user=request.user)) elder = elders.filter(id=id) if elder: return render(request, 'parents_delete.html', {'elders': elders, 'active_elder': active, 'delete': elder[0]}) return HttpResponseRedirect(reverse('parents'))
def get(self, request): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) location = PointOfInterest.objects.order_by('category') return render(request, 'location.html', { 'elders': elders, 'active_elder': elder, 'location': location })
def post(self, request, id): cek_session(request) elders = Elder.get_cared_elder( user=CareGiver.objects.get(user=request.user)) elder = elders.filter(id=id) if elder: elder = elder[0] name = elder.user.first_name + " " + elder.user.last_name if elder.cared_by.count() == 1: elder.delete() else: cg = CareGiver.objects.get(user=request.user) CareGiving.objects.filter( elder=elder, caregiver=cg).delete() if int(id) == request.session.get('active_elder'): elders = Elder.get_cared_elder( user=CareGiver.objects.get(user=request.user)) if elders: request.session['active_elder'] = elders[0].id else: request.session['active_elder'] = 0 messages.success( request, name + ' berhasil dihapus dari daftar anda.') return HttpResponseRedirect(reverse('parents'))
def post(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) notif = Notification.objects.filter(receiver=elder.user, id=id) if notif: name = notif[0].title notif.delete() messages.success( request, 'Notifikasi "' + name + '" telah berhasil dihapus.') return HttpResponseRedirect(reverse('notif_elder'))
def get(self, request, id): cek_session(request) elder = None elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) notif = Notification.objects.filter(receiver=request.user, id=id) if notif: return render(request, 'notif_response.html', { 'elders': elders, 'active_elder': elder, 'notif': notif[0] }) return HttpResponseRedirect(reverse('notif_cg'))
def get(self, request): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) disease = DiseaseHist.objects.filter(elder=elder).order_by('-id') return render(request, 'disease.html', { 'elders': elders, 'active_elder': elder, 'disease': disease }) else: return HttpResponseRedirect(reverse('index'))
def get(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) medis = MedicalTreatmentHist.objects.filter(elder=elder, id=id) if medis: return render(request, 'medis_edit.html', { 'elders': elders, 'active_elder': elder, 'medis': medis[0] }) return HttpResponseRedirect(reverse('treatment')) return HttpResponseRedirect(reverse('index'))
def get(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) contact = Contact.objects.filter(elder=elder, id=id) if contact: return render(request, 'contact_read.html', { 'elders': elders, 'active_elder': elder, 'contact': contact[0] }) return HttpResponseRedirect(reverse('contact')) return HttpResponseRedirect(reverse('index'))
def get(self, request, id): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) feedback = Feedback.objects.filter(owner=request.user, id=id) if feedback: return render(request, 'feedback_view.html', { 'elders': elders, 'active_elder': elder, 'feedback': feedback[0] }) return HttpResponseRedirect(reverse('notif_elder'))
def get(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) disease = DiseaseHist.objects.filter(elder=elder, id=id) if disease: return render(request, 'disease_delete.html', { 'elders': elders, 'active_elder': elder, 'disease': disease[0] }) return HttpResponseRedirect(reverse('treatment')) return HttpResponseRedirect(reverse('index'))
def post(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) contact = Contact.objects.filter( elder=elder, id=id, added_by=CareGiver.objects.get(user=request.user)) if contact: name = contact[0].name contact.delete() messages.success(request, 'Data "' + name + '" telah berhasil dihapus.') return HttpResponseRedirect(reverse('contact'))
def post(self, request): if ('login' in request.POST): form = LoginForm(request.POST) if form.is_valid(): user = form.login(request) if user: login(request, user) if is_caregiver(user): caregiver = CareGiver.objects.get(user=user) elders = Elder.get_cared_elder(caregiver) if elders: request.session['active_elder'] = elders[0].id else: request.session['active_elder'] = 0 return self.caregiver(request) else: return self.partner(request) else: return render(request, 'login.html', {'error_login': form.errors}) elif ('signup' in request.POST): userform = UserForm(request.POST) caregiverform = CareGiverForm(request.POST) # return reverse(request.POST['gender']) if userform.is_valid() and caregiverform.is_valid(): user = userform.save(commit=False) user.set_password(userform.cleaned_data.get('password')) user.save() caregiver = caregiverform.save(commit=False) caregiver.user = user caregiver.save() g = Group.objects.get(name='CareGiver') g.user_set.add(user) return render( request, 'login.html', {'success': "Pendaftaran Berhasil, silahkan login"}) else: userform.errors.update(caregiverform.errors) return render(request, 'login.html', { 'error_signup': userform.errors, 'values': request.POST }) else: return render(request, 'login.html')
def get(self, request, type, id): cek_session(request) elder = None if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) info = Posting.objects.filter(category=type, id=id) if info: return render( request, 'post_view.html', { 'elders': elders, 'tag': type, 'active_elder': elder, 'info': info[0] }) return HttpResponseRedirect(reverse(type))
def get_queryset(self): user = self.request.user if user.is_authenticated(): if CareGiver.objects.filter(user=user): caregiver = CareGiver.objects.get(user=user) elder = Elder.get_cared_elder(caregiver).values_list( 'user', flat=True).order_by('id') return Notification.objects.filter( Q(sender=user) | Q(receiver=user) | Q(receiver__in=elder)) elif Elder.objects.filter(user=user): elder = Elder.objects.get(user=user) caregiver = CareGiver.objects.filter( elder__in=[elder]).values_list('user', flat=True).order_by('id') return Notification.objects.filter( Q(sender=user) | Q(receiver=user) | Q(receiver__in=caregiver)) return Notification.objects.all()
def get(self, request, id): cek_session(request) if request.session.get('active_elder') is not None and request.session[ 'active_elder'] != 0: elder = Elder.objects.get(pk=request.session.get('active_elder')) elders = Elder.get_cared_elder(user=CareGiver.objects.get( user=request.user)) note = Note.objects.filter( elder=elder, id=id, user=CareGiver.objects.get(user=request.user)) if note: return render(request, 'note_delete.html', { 'elders': elders, 'active_elder': elder, 'note': note[0] }) return HttpResponseRedirect(reverse('note')) return HttpResponseRedirect(reverse('index'))