def badge_award_submit(): if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') badge_list = m3.get_badges(pcrDB) # list of all badges user_list = m3.get_users(pcrDB) # list of all users current_user = request.params.user current_user_badges = m3.get_users_badges(pcrDB, current_user) current_badge = request.params.badge ## check that the user doesn't already have the badge # if so, send back to the menu if(current_badge in current_user_badges): return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:red;">That user already has that badge!</h2> '''.format(useremail) + template('admin-award.tpl', badges=badge_list, users=user_list) + "</body>" # if not, award the badge ## awarding badge magic else: m3.award_badge_to_user(pcrDB, current_badge, current_user) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue;">Badge successfully awarded!<h2> '''.format(useremail) + template('admin-award.tpl', badges=badge_list, users=user_list) + "</body>" else: redirect("/login")
def badge_award_submit(): if (request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') badge_list = m3.get_badges(pcrDB) # list of all badges user_list = m3.get_users(pcrDB) # list of all users current_user = request.params.user current_user_badges = m3.get_users_badges(pcrDB, current_user) current_badge = request.params.badge ## check that the user doesn't already have the badge # if so, send back to the menu if (current_badge in current_user_badges): return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:red;">That user already has that badge!</h2> '''.format(useremail) + template('admin-award.tpl', badges=badge_list, users=user_list) + "</body>" # if not, award the badge ## awarding badge magic else: m3.award_badge_to_user(pcrDB, current_badge, current_user) return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue;">Badge successfully awarded!<h2> '''.format(useremail) + template( 'admin-award.tpl', badges=badge_list, users=user_list) + "</body>" else: redirect("/login")
def tasks_menu(): if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') badge_list = m3.get_badges(pcrDB) user_list = m3.get_users(pcrDB) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> '''.format(useremail) + template('admin-tasks.tpl', badges=badge_list, users=user_list, typeselection = 0) + "</body>" else: redirect("/login")
def tasks_menu_post(): if(request.get_cookie('loggedin')): submitted = request.params.flag typeselection = request.params.typeselection badge_list = m3.get_badges(pcrDB) user_list = m3.get_users(pcrDB) app_list = m3.get_all_apps(pcrDB) useremail = request.get_cookie('loggedin', secret='applesauce') if(submitted == "False"): if(typeselection != 0): app = request.params.app return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> '''.format(useremail) + template('admin-tasks.tpl', badges=badge_list, users=user_list, app_list=app_list, typeselection = typeselection, app = app) + "</body>" else: user = request.params.user badge = request.params.badge app = request.params.app print("typeselection = %s " % typeselection) ### type handling for task assignment: if(typeselection == "percent"): circuit = request.params.circuit score = float(request.params.score) percent = int(request.params.percent) NewTask = m3.PercentTask(user, badge, app, circuit, score, percent) elif(typeselection == "repeat"): circuit = request.params.circuit repeat = int(request.params.repeat) NewTask = m3.RepeatTask(user, badge, app, circuit, repeat) elif(typeselection == "unique"): unique = request.params.unique NewTask = m3.UniqueTask(user, badge, app, unique) elif(typeselection == "timetrial"): days = int(request.params.days) hours = int(request.params.hours) minutes = int(request.params.minutes) circuit = request.params.circuit tasknum = int(request.params.tasknum) NewTask = m3.TimeTrialTask(user, badge, app, days, hours, minutes, circuit, tasknum) else: #performance circuit = request.params.circuit targetyield = int(request.params.targetyield) cost = int(request.params.cost) NewTask = m3.PerformanceTask(user, badge, app, circuit, targetyield, cost) ### task is assigned, now time to see if it's unique... print(NewTask.output()) result = NewTask.assign(pcrDB) if(result): return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue;">Task successfully started...</h2> '''.format(useremail) + template('admin-tasks.tpl', badges=badge_list, users=user_list, typeselection = 0) + "</body>" else: return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:red;">Task already assigned to user...</h2> '''.format(useremail) + template('admin-tasks.tpl', badges=badge_list, users=user_list, typeselection = 0) + "</body>" else: redirect("/login")
def tasks_menu_post(): if (request.get_cookie('loggedin')): submitted = request.params.flag typeselection = request.params.typeselection badge_list = m3.get_badges(pcrDB) user_list = m3.get_users(pcrDB) app_list = m3.get_all_apps(pcrDB) useremail = request.get_cookie('loggedin', secret='applesauce') if (submitted == "False"): if (typeselection != 0): app = request.params.app return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> '''.format(useremail) + template('admin-tasks.tpl', badges=badge_list, users=user_list, app_list=app_list, typeselection=typeselection, app=app) + "</body>" else: user = request.params.user badge = request.params.badge app = request.params.app print("typeselection = %s " % typeselection) ### type handling for task assignment: if (typeselection == "percent"): circuit = request.params.circuit score = float(request.params.score) percent = int(request.params.percent) NewTask = m3.PercentTask(user, badge, app, circuit, score, percent) elif (typeselection == "repeat"): circuit = request.params.circuit repeat = int(request.params.repeat) NewTask = m3.RepeatTask(user, badge, app, circuit, repeat) elif (typeselection == "unique"): unique = request.params.unique NewTask = m3.UniqueTask(user, badge, app, unique) elif (typeselection == "timetrial"): days = int(request.params.days) hours = int(request.params.hours) minutes = int(request.params.minutes) circuit = request.params.circuit tasknum = int(request.params.tasknum) NewTask = m3.TimeTrialTask(user, badge, app, days, hours, minutes, circuit, tasknum) else: #performance circuit = request.params.circuit targetyield = int(request.params.targetyield) cost = int(request.params.cost) NewTask = m3.PerformanceTask(user, badge, app, circuit, targetyield, cost) ### task is assigned, now time to see if it's unique... print(NewTask.output()) result = NewTask.assign(pcrDB) if (result): return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue;">Task successfully started...</h2> '''.format(useremail) + template('admin-tasks.tpl', badges=badge_list, users=user_list, typeselection=0) + "</body>" else: return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:red;">Task already assigned to user...</h2> '''.format(useremail) + template('admin-tasks.tpl', badges=badge_list, users=user_list, typeselection=0) + "</body>" else: redirect("/login")