def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) if get_user(self.request) is not None: curUser = get_user(self.request) context['curUser'] = curUser.email_address return context
def get_object(self): other_username = self.kwargs.get("username") if get_user(self.request) is not None: user = get_user(self.request) obj, created = Thread.objects.get_or_new(user, other_username) if obj is None: raise Http404 return obj
def form_valid(self, form): thread = self.get_object() user = None if get_user(self.request) is not None: user = get_user(self.request) message = form.cleaned_data.get("message") ChatMessage.objects.create(user=user, thread=thread, message=message) return super().form_valid(form)
def signed_in(request): logged_in = check_user_token_validation(request) if logged_in: try: user = get_user(request) except: return logged_in return render(request, "patientDashboard.html")
def go_to_chat(request): print(request.GET.get("doctor_id")) doctor_id = request.GET.get("doctor_id") doctor = DoctorModel.objects.filter(id=doctor_id).first() print(doctor) logged_in = check_user_token_validation(request) user = None if logged_in: try: user = get_user(request) except: return logged_in new_consultation = Consultation(doctor=doctor, user=user, no_days=1) new_consultation.save() return HttpResponseRedirect("consultations/" + doctor.email_address + "/")
def dispatch(self, request, *args, **kwargs): if get_user(request) is None: messages.error(request, 'Please log in first to access Inbox.') return HttpResponseRedirect('/login') else: return super(ThreadView, self).dispatch(request, *args, **kwargs)
def get_queryset(self): user = None if get_user(self.request) is not None: user = get_user(self.request) return Thread.objects.by_user(user)