-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
49 lines (44 loc) · 1.95 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from django.shortcuts import render, redirect
from order.models import Order
from django.http import HttpResponse
from django.contrib.auth import authenticate, logout, login
from django.contrib.auth.decorators import login_required, user_passes_test
# Create your views here.
def master_login(request):
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password = password)
if(user.get_username() == "master" or user.is_superuser):
login(request, user)
return redirect('view-orders')
return HttpResponse("You are not master")
return render(request, 'masters/login.html')
@login_required(login_url="master-login")
@user_passes_test(lambda user: user.username == 'master', login_url="login-quality")
def view_orders(request):
all_orders = Order.objects.all().order_by('order_priorty')
return render(request, 'masters/all_orders.html', context={"all_orders":all_orders})
@login_required(login_url="master-login")
@user_passes_test(lambda user: user.username == 'master', login_url="login-quality")
def view_perticular_order(request, id):
order = Order.objects.get(id = id)
if request.method == "POST":
data = request.POST["status"]
number_of_order = request.POST["number"]
if data == "cutting".lower():
order.order_status = "CUTTING STARTED"
order.save()
elif data == "stitching".lower():
order.order_status = "STITCHING STARTED"
order.save()
elif data == "finished".lower():
order.order_status = "ORDER READY"
order.save()
order.number_of_order_done = number_of_order
order.save()
return render(request, 'masters/single_order.html', context={"order":order})
@login_required(login_url="master-login")
def logout_master(request):
logout(request)
return redirect('master-login')