-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.py
148 lines (127 loc) · 6.42 KB
/
menu.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
from database import *
import time
from pywebio.input import *
from pywebio.output import *
from allotment_mechanism import *
mydata= Data() #object of class Data
mymachine= Allotment_mechanism()
welm_img = open('images/Welcome to AllotEasy.jpg', 'rb').read()
header_img = open('images/header_new.jpg', 'rb').read()
aboutus_img = open('images/Aboutus_img.jpg', 'rb').read()
#def check_student_admin_choice(user_inp):
# if (user_inp > 7 or user_inp < 1):
# return ("Invalid choice number. Select a choice from 1 to 7")
class Menu:
def __init__(self):
self.user= None
def about_us(self):
clear('ROOT')
with use_scope("main", clear=True):
put_image(aboutus_img, width='150%', height='400px')
data = input_group("Press button to return to menu",[actions('', [ {'label': 'Back', 'value': 1},], name='action', help_text=None),])
clear('ROOT')
def login(self):
with use_scope("main",clear=True):
put_image(src=welm_img, width='150%', height='400px') #put welcome screen
login_choice = input_group('Get Started', [
actions('', [
{'label': 'Sign Up', 'value': 1},
{'label': 'Login (Student)', 'value': 2},
{'label': 'Login (Admin)', 'value': 3},
{'label': 'About Us', 'value': "Aboutus"},
{'label': 'Exit', 'value': 4},
], name='action', help_text=None),
])
user_inp= login_choice["action"]
if user_inp=="Aboutus":
self.user=None
clear("main")
self.about_us()
return
else:
# store who is the current user in class var- user.
self.user = user_inp
if user_inp==1:
# signup for students is selected
clear("main")
mydata.student_sign_up()
if user_inp==2 :
# login as student is selected
name_surname = input("Enter full name (name surname): ", type=TEXT, required=True)
name= (name_surname.split())[0]
mydata.set_userinfo(2,name) # send user info to database file
is_correct_pswd = mydata.check_pswd(name)
if(is_correct_pswd==1): # name and password match
with use_scope("main"):
put_success(f"\n Welcome, {name.capitalize()}!")
time.sleep(2)
return
else:
# Username or password or both do not match
with use_scope("main"):
put_error("Sorry! Incorrect credentials. ", closable= True)
time.sleep(2)
self.login()
if user_inp ==3:
# login as admin is selected
# (pwd for admin is secretadmin)
pwd= input("Enter password:", type=PASSWORD, required=True)
if (pwd =="secretadmin"):
with use_scope("main"):
put_success("Welcome, Admin!")
mydata.set_userinfo(3,"admin") # send user info to database file
time.sleep(2)
else:
with use_scope("main"):
put_error("Sorry! Incorrect password entered. ",closable=True)
time.sleep(2)
self.login()
def menu_for_student(self):
stud_menu_img = open('images/student_menu_img.jpg', 'rb').read()
choice= None
while(choice!=8): # breaks out of loop when 7 i.e. logout is selected
if mydata.flag==0:
# flag=0 indicates user has not withdrawn his application.
with use_scope("main", clear=True):
put_image(stud_menu_img,width='80%',height='300px')
data= input_group("Student Menu", [
radio(label="", name='menu', options=[("View Seat Matrix",1),("Fill Application details",2),("Check your application status",3),("Withdraw application",4),("View Branchwise cutoff marks",5),("View data of vacancies left",6),("Change Password",7),("Logout",8)], required=True, inline=False, value=None)
])
choice= data['menu']
#choice= input("Enter your choice: ", type=NUMBER, validate=check_student_admin_choice, help_text='Enter your choice number', required=True)
else:
# flag=1 is the case where user has withdrawn the application. So we do not show him any other option and force him to logout.
choice=8
if choice!=8:
# when any choice other than logout is selected, call the corresponding function from the functions list in database.py
clear("main")
mydata.student_options[choice-1](mydata)
return
def menu_for_admin(self):
clear('ROOT')
admin_menu_img = open('images/admin_menu_img.jpg', 'rb').read()
mymachine.flag=0
choice= None
while(choice!=7): # breaks out of loop when 7 i.e. logout is selected
if mymachine.flag==0:
with use_scope("main", clear=True):
put_image(admin_menu_img,width='80%',height='300px')
data= input_group("Admin Menu", [
radio(label="", name='menu', options=[("Run Seat allotment process",1),("View full allotment result",2),("View branch-wise allotment result",3),("Search a student",4),("Get list of students without allotment",5),("View data of vacancies left",6),("Logout",7)], required=True, inline=False, value=None)
])
choice= data['menu']
#choice= input("Enter your choice: ", type=NUMBER, validate=check_student_admin_choice, help_text='Enter your choice number', required=True)
else:
choice=7
if choice!=7:
# when any choice other than logout is selected, call the corresponding function from the functions list in database.py
clear()
if choice!=1:
# all functions other than 'run allotment' are present in class Data. They require an object of this class to be passed as parameter.
clear("main")
mydata.admin_options[choice-1](mydata)
else:
# if choice 1 is selected, this run allotment function is present in a diff class than other functions and hence does not require the object of class Data to be passed as paramenter.
clear("main")
mydata.admin_options[0]()
return