def dashboard_old(request, **kwargs): user = request.user user_detail = UserDetails.objects.get_or_create(user=user) user_detail = user_detail[0] if user_detail.user_type == "Tutor": return redirect("tutor-dashboard") details = Orders.objects.filter(user=user) labs = LabOrders.objects.filter(user=user) if request.method == 'POST': desc = request.POST.get('desc') reference_material = request.FILES['reference_material'] assignment = request.FILES['assignment'] deadline = request.POST.get('deadline') subject = request.POST.get('subject') order = Orders(user=user, status='Awaiting Confirmation', desc=desc, reference_material=reference_material, assignment=assignment, deadline=deadline, subject=subject) order.save() id = order.pk id += 1000 order.order_id = f'TC-HW-{id}' order.save() print("Order successful, order id : {}".format(order.order_id)) send_message(request, "Order successful, order id : {}".format(order.order_id)) c = { 'user': user.username, 'order_id': order.order_id, 'subject': order.subject, 'deadline': deadline, } email = user.email order_id = order.order_id email_msg = render_to_string('order.txt', c) mail = EmailMessage( subject=f'Order Created - {order_id}', body=email_msg, from_email='TutorChamps Student Support <*****@*****.**>', to=[email, '*****@*****.**']) mail.send() serializers = OrderSerializers(order) return JsonResponse(serializers.data) print(details) _context = { 'details': details, 'user': user, 'user_detail': user_detail, 'labs': labs, 'ordered': False } if "order" in kwargs.keys(): if kwargs["order"] == "order-successful": _context["ordered"] = True print(_context["ordered"]) return render(request, 'dash_board.html', _context)
def live_session(request): res = ''.join(random.choices(string.ascii_uppercase + string.digits, k=20)) b = request.user.is_authenticated if request.method == 'POST': deadline = request.POST.get('deadline') subject = request.POST.get('subject') file = request.FILES['files'] duration = request.POST.get('duration') desc = request.POST.get('Details') if b: user = request.user order = Orders(deadline=deadline, subject=subject, assignment=file, duration=duration, desc=desc, user=user, status="Awaiting Confirmation") order.save() id = order.pk id += 1000 order.order_id = f'TC-LS-{id}' order.save() return redirect('old-user') else: request.session['session_key'] = res new_user = User(username=res, email=res) new_user.save() print(new_user) order = Orders(deadline=deadline, subject=subject, assignment=file, duration=duration, user=new_user, desc=desc, status='Awaiting Confirmation') order.save() id = order.pk id += 1000 order.order_id = f'TC-LS-{id}' order.save() return render(request, 'live-session.html')
def onlyorders(request): res = ''.join(random.choices(string.ascii_uppercase + string.digits, k=20)) if request.method == 'POST': subject = request.POST.get('subject') desc = request.POST.get('Details') deadline = request.POST.get('deadline') if request.FILES: assignment = request.FILES['files'] else: assignment = None try: user = request.user uname = user.username user = User.objects.get(username=uname) order = Orders(subject=subject, desc=desc, deadline=deadline, assignment=assignment, user=user, status='Awaiting Confirmation') order.save() id = order.pk id += 1000 order.order_id = f'TC-HW-{id}' order.save() return redirect('old-user') except: request.session['session_key'] = res new_user = User(username=res, email=res) new_user.save() order = Orders(user=new_user, subject=subject, desc=desc, assignment=assignment, deadline=deadline, status='Awaiting Confirmation') order.save() id = order.pk id += 1000 order.order_id = f'TC-HW-{id}' order.save() return redirect('signup')
def live_session_orders(request): user = request.user user_detail = UserDetails.objects.get_or_create(user=user) user_detail = user_detail[0] if request.method == 'POST': desc = request.POST.get('desc') assignment = request.FILES['assignment'] deadline = request.POST.get('deadline') duration = request.POST.get('Duration') subject = request.POST.get('subject') reference_material = request.FILES['reference_material'] order = Orders(user=user, status='Awaiting Confirmation', desc=desc, assignment=assignment, deadline=deadline, subject=subject, duration=duration, reference_material=reference_material) order.save() id = order.pk id += 1000 order.order_id = f'TC-LS-{id}' order.save() serializers = OrderSerializers(order) c = { 'user': user.username, 'order_id': order.order_id, 'subject': order.subject, 'deadline': deadline, } email = user.email order_id = order.order_id email_msg = render_to_string('order.txt', c) mail = EmailMessage( subject=f'Order Created - {order_id}', body=email_msg, from_email='TutorChamps Students Support <*****@*****.**>', to=[email, '*****@*****.**']) mail.send() return JsonResponse(serializers.data)