def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) if get_abstract_user(self.request) is not None: curUser = get_abstract_user(self.request) context['curUser'] = curUser.email_address return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['form'] = self.get_form() if get_abstract_user(self.request) is not None: curUser = get_abstract_user(self.request) context['curUser'] = curUser.email_address if curUser is not None: other_username = self.kwargs.get("username") if type(curUser) is UserModel: other_user = DoctorModel.objects.filter( email_address=other_username).first() consultations = Consultation.objects.filter(doctor=other_user, user=curUser) else: other_user = UserModel.objects.filter( email_address=other_username).first() consultations = Consultation.objects.filter(user=other_user, doctor=curUser) valid = False for cur_consult in consultations: if cur_consult.ongoing: valid = True break context['valid'] = valid return context
def get_queryset(self): if get_abstract_user(self.request) is not None: user = get_abstract_user(self.request) else: messages.info(self.request, 'Please Log in first to access the page') return HttpResponseRedirect('/login') return Thread.objects.by_user(user)
def form_valid(self, form): thread = self.get_object() user = None if get_abstract_user(self.request) is not None: user = get_abstract_user(self.request) message = form.cleaned_data.get("message") ChatMessage.objects.create(user=user, thread=thread, message=message) return super().form_valid(form)
def get_object(self): other_username = self.kwargs.get("username") user = None if get_abstract_user(self.request) is not None: user = get_abstract_user(self.request) obj, created = Thread.objects.get_or_new(user, other_username) if obj is None: raise Http404 return obj
def past_consultations(request): user = get_abstract_user(request) consultations = None if user: if type(user) == UserModel: consultations = Consultation.objects.filter(user_id=user.id) else: consultations = Consultation.objects.filter(doctor_id=user.id) past_consultations_list = [ consultation for consultation in consultations if not consultation.ongoing ] paginator = Paginator(past_consultations_list, 5) page = request.GET.get('page') past_consultations = paginator.get_page(page) return render(request, "past_consultations.html", {'consultations': past_consultations})
def ongoing_consultations(request): user = get_abstract_user(request) consultations = None isUser = None if user: if type(user) == UserModel: consultations = Consultation.objects.filter(user_id=user.id) isUser = True else: consultations = Consultation.objects.filter(doctor_id=user.id) ongoing_consultations = [ consultation for consultation in consultations if consultation.ongoing ] return render(request, "current_consultations.html", { 'consultations': ongoing_consultations, 'is_user': isUser })
def get_queryset(self): user = None if get_abstract_user(self.request) is not None: user = get_abstract_user(self.request) return Thread.objects.by_user(user)
def dispatch(self, request, *args, **kwargs): if get_abstract_user(request) is None: messages.error(request, 'Please log in first to access Inbox.') return HttpResponseRedirect('/login') else: return super(InboxView, self).dispatch(request, *args, **kwargs)