-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
65 lines (54 loc) · 2.29 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from pyexpat.errors import messages
from django.shortcuts import render, HttpResponse,redirect
from .models import *
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
from django.contrib.auth import login,logout
from django.contrib import messages
# Create your views here.
def setplan(request):
if request.user.is_superuser:
logout(request)
messages.error(request, 'Error - Super user Dont have Access.')
return redirect('home')
if request.user.is_staff:
plans = Plan.objects.all()
return render(request,"staff/setplan.html", context={"data" : plans})
# plans = Plan.objects.all()
# return render(request,'staff/setplan.html',context={"all_plans": plans})
messages.error(request, 'Error - You dont have staff permission Signin with staff account.')
return redirect('home')
def addplan(request):
if request.method == 'POST':
name=request.POST.get('planname')
description=request.POST.get('plandesc')
price=request.POST.get('planprice')
Plan.objects.create(name=name,description=description, price=price)
messages.error(request, 'Success - Plan Added Successfully.')
return redirect('setplan')
# plans = Plan.objects.all()
else:
if request.user.is_superuser:
logout(request)
messages.error(request, 'Error - Super user Dont have Access.')
return redirect('home')
if request.user.is_staff:
return render(request,"staff/addplan.html")
else:
messages.error(request, 'Error - You dont have staff permission Signin with staff account.')
return redirect('home')
def delplan(request,plan_id):
try :
thisplan=Plan.objects.get(id=int(plan_id))
thisplan.delete()
messages.error(request, 'Success - Plan Deleted Successfully.')
return redirect('setplan')
except:
messages.error(request, 'Error - Enter Valid plan listed Below.')
return redirect('setplan')
def staffdashboard(request):
if request.user.is_superuser:
logout(request)
messages.error(request, 'Error - Super user Dont have Access.')
return redirect('home')
return render(request,"staff/staffdashboard.html")