def get(self, request): context = {} login_id = None if LOGIN_ID in request.session: login_id = request.session[LOGIN_ID] login_type = None if LOGIN_TYPE in request.session: login_type = request.session[LOGIN_TYPE] if login_id and login_type: if login_type == LoginType.ORG: org = OrganizationDB.organization(uno=login_id) if org.valid(): context['org'] = org context['login'] = True elif login_type == LoginType.EMP: user = UserDB.user(uno=login_id) if user.valid(): user_name_arr = user['name'].split() user_init = "" for i in user_name_arr: user_init += i[0] user['initial'] = user_init context['user'] = user context['login'] = True return render(request, "test/browse.html", context)
def get(self, request): context = {} if LOGIN_ID not in request.session or LOGIN_TYPE not in request.session: return HttpResponseRedirect("/profile") if request.session[LOGIN_TYPE] == LoginType.ORG: return HttpResponseRedirect("/profile") user_id = request.session[LOGIN_ID] user_type = request.session[LOGIN_TYPE] user = UserDB.user(uno=user_id) if not user.valid(): return HttpResponseRedirect("/profile") if user['role'] != PROBLEM_SETTER: return HttpResponseRedirect("/profile") user_name_arr = user['name'].split() user_init = "" for i in user_name_arr: user_init += i[0] user['initial'] = user_init context['user'] = user if ADD_PROBLEM_SET_RESULT in request.session: pscode = request.session[ADD_PROBLEM_SET_RESULT] context['alert'] = pscode del request.session[ADD_PROBLEM_SET_RESULT] return render(request, "employee/problem_set.html", context)
def save_review(request): response = {} found_sub = None data = request.GET session = request.session test_id = data.get('id') review = data.get('review') if not test_id: response['result'] = "error" response['message'] = "No Test Provided" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) test = TestModuleDB.test_module(uno=test_id) if not test.valid(): response['result'] = "error" response['message'] = "Test Doesn't Exist" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) login_id = request.session.get(LOGIN_ID) login_type = request.session.get(LOGIN_TYPE) if not login_id or not login_type: response['result'] = "error" response['message'] = "Login Required" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if login_type == LoginType.ORG: response['result'] = "error" response['message'] = "Only a Participant can Review" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) elif login_type == LoginType.EMP: user = UserDB.user(uno=login_id) if not user.valid(): response['result'] = "error" response['message'] = "Something Looks Wrong with the Login" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if user['role'] or user['organization']: response['result'] = "error" response['message'] = "Only a Participant can Review" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) test['review'][user['_id']] = review TestModuleDB.update(test) response['result'] = "sucess" response['message'] = "Review Saved" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False)
def employees(self, etype=None): from db.user_database import UserDB from .user import User if etype == self.EmpType.GN: userdb = UserDB.all() role = self.EmpType.GN gn_arr = self.get('employees')[role.name] return [ User(doc) for doc in userdb if doc['_id'] in gn_arr and doc['role'] == role.name ] elif etype == self.EmpType.HR: return UserDB.user(uno=self.get('employees')[self.EmpType.HR.name]) elif etype == self.EmpType.SU: return UserDB.user(uno=self.get('employees')[self.EmpType.SU.name]) elif etype == self.EmpType.PS: return UserDB.user(uno=self.get('employees')[self.EmpType.PS.name]) return User()
def get(self, request): context = {} if LOGIN_ID not in request.session or LOGIN_TYPE not in request.session: return HttpResponseRedirect("/profile") if request.session[LOGIN_TYPE] == LoginType.ORG: return HttpResponseRedirect("/profile") user_id = request.session[LOGIN_ID] user_type = request.session[LOGIN_TYPE] user = UserDB.user(uno=user_id) if not user.valid(): return HttpResponseRedirect("/profile") if user['role'] != TEST_SUPERVISOR: return HttpResponseRedirect("/profile") user_name_arr = user['name'].split() user_init = "" for i in user_name_arr: user_init += i[0] user['initial'] = user_init context['user'] = user now = datetime.now() first_date = now - timedelta(days=now.isoweekday() - 1) dates = [] for count in range(0, 21): date_entry = { "day": first_date.day, "date_val": first_date.strftime("%d-%m-%Y"), "date_str": first_date.strftime("%d %B %Y") } if first_date > now and first_date <= now + timedelta(days=10): date_entry['available'] = True else: date_entry['available'] = False dates.append(date_entry) first_date += timedelta(days=1) context['dates'] = dates if ADD_TEST_MODULE_RESULT in request.session: tmcode = request.session[ADD_TEST_MODULE_RESULT] context['alert'] = tmcode del request.session[ADD_TEST_MODULE_RESULT] return render(request, "employee/test-module.html", context)
def post(self, request): data = request.POST redirect = data.get('r', '/profile') email = data.get('email') pwd = data.get('pwd') if not email or not pwd: request.session[AUTH_RESULT] = LoginResult.SOMETHING_ELSE return HttpResponseRedirect("/login?r=" + redirect) if data.get('org'): org = OrganizationDB.organization(email=email, password=pwd) if not org.valid(): request.session[ AUTH_RESULT] = LoginResult.WRONG_USERNAME_OR_PASSWORD.value return HttpResponseRedirect("/login?r=" + redirect) if not org.verified(): request.session[ AUTH_RESULT] = LoginResult.ORGANIZATION_NOT_VERIFIED.value return HttpResponseRedirect("/login?r=" + redirect) request.session[LOGIN_ID] = org['_id'] request.session[LOGIN_TYPE] = LoginType.ORG return HttpResponseRedirect(redirect) else: user = UserDB.user(email=email, password=pwd) if not user.valid(): request.session[ AUTH_RESULT] = LoginResult.WRONG_USERNAME_OR_PASSWORD.value return HttpResponseRedirect("/login?r=" + redirect) request.session[LOGIN_ID] = user['_id'] request.session[LOGIN_TYPE] = LoginType.EMP return HttpResponseRedirect(redirect)
def profile(request): context = {} session = request.session if not session.get(LOGIN_ID) or not session.get(LOGIN_TYPE): return HttpResponseRedirect("/login?r=/profile") user_id = session[LOGIN_ID] user_type = session[LOGIN_TYPE] if user_type == LoginType.ORG: org = OrganizationDB.organization(uno=user_id) if not org.valid(): session[AUTH_RESULT] = LoginResult.SOMETHING_ELSE.value return HttpResponseRedirect("/login?r=/profile") add_result = session.get(ADD_EMP_RESULT) remove_result = session.get(REMOVE_EMP_RESULT) if add_result: context['alert'] = add_result del request.session[ADD_EMP_RESULT] elif remove_result: context['alert'] = remove_result del request.session[REMOVE_EMP_RESULT] employees = {} user = org.employees(OrganizationData.EmpType.HR) if user.valid(): user['id'] = user['_id'] employees[OrganizationData.EmpType.HR.name] = user user = org.employees(OrganizationData.EmpType.SU) if user.valid(): user['id'] = user['_id'] employees[OrganizationData.EmpType.SU.name] = user user = org.employees(OrganizationData.EmpType.PS) if user.valid(): user['id'] = user['_id'] employees[OrganizationData.EmpType.PS.name] = user user = org.employees(OrganizationData.EmpType.GN) for u in user: if u.valid(): u['id'] = u['_id'] employees[OrganizationData.EmpType.GN.name] = user org['employees'] = employees context['org'] = org return render(request, "home/orgprofile.html", context) else: user = UserDB.user(uno=user_id) if not user.valid(): session[AUTH_RESULT] = LoginResult.SOMETHING_ELSE.value return HttpResponseRedirect("/login?r=/profile") org = user.organization() if org.valid(): org['id'] = org['_id'] user['organization'] = org user_name_arr = user['name'].split() user_init = "" for i in user_name_arr: user_init += i[0] user['initial'] = user_init context['user'] = user return render(request, "home/userprofile.html", context)
def find_problem_sets(request): response = {} data = request.GET session = request.session if not session.get(LOGIN_ID) or not session.get(LOGIN_TYPE): response['result'] = "error" response['message'] = "Login Required" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if session[LOGIN_TYPE] == LoginType.EMP: user_id = session[LOGIN_ID] user = UserDB.user(uno=user_id) if not user.valid(): response['result'] = "error" response['message'] = "Login Required" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if user['role'] == GENERAL_MEMBER: response['result'] = "error" response['message'] = "Permission Not Granted" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) org = user.organization() else: org_id = session[LOGIN_ID] org = OrganizationDB.organization(uno=org_id) s_id = data.get('id') s_name = data.get('name') s_category = data.get('category') s_public = data.get('public') s_sort_with = data.get('sort_with') s_group_with = data.get('group_with') if s_public == "true": s_public = True else: s_public = False if s_sort_with != "name" and s_sort_with != "category" and s_sort_with: response['result'] = "error" response['message'] = "Unknown Sort Type" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if s_group_with != "category" and s_group_with: response['result'] = "error" response['message'] = "Unknown Group Type" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) try: s_from = int(data.get('from', 1)) except Exception as e: response['result'] = "error" response['message'] = "value of parameter 'from' is not an integer" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) try: s_max = int(data.get('max', 6)) except Exception as e: response['result'] = "error" response['message'] = "value of parameter 'max' is not an integer" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if s_from <= 0: response['result'] = "error" response['message'] = "value of parameter 'from' is less than 1" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if s_max <= 0: response['result'] = "error" response['message'] = "value of parameter 'max' is less than 1" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) # print("id = "+str(s_id)) # print("from = "+str(s_from)) # print("max = "+str(s_max)) # print("name = "+str(s_name)) # print("category = "+str(s_category)) # print("sort_with = "+str(s_sort_with)) # print("group_with = "+str(s_group_with)) if s_id: pset = ProblemSetDB.problem_set(uno=s_id) if not pset.valid(): response['result'] = "error" response['message'] = "Problem Set Does not exist" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) response['result'] = "success" response['length'] = 1 response['organization'] = org['_id'] response['problem_sets'] = [pset] return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if s_public: psets = ProblemSetDB.all() pset_list = [ pset for pset in psets if pset['public'] or pset['organization'] == org['_id'] ] else: pset_list = org.problem_sets() count, pset_list = problem_sets(pset_list, s_name, s_category, s_from, s_max) if s_sort_with: pset_list = sort(pset_list, s_sort_with) if s_group_with: pset_list = group(pset_list, s_group_with) if not pset_list or count == 0: response['result'] = "success" response['length'] = 0 return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) for ps in pset_list: ps['id'] = ps['_id'] del ps['_id'] ps['organization'] = ps.organization() ps['organization']['id'] = ps['organization'].get('_id') response['result'] = "success" response['length'] = count response['organization'] = org['_id'] response['problem_sets'] = pset_list return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False)
def change(request): response = {} data = request.GET session = request.session if not session.get(LOGIN_ID) or not session.get(LOGIN_TYPE): response['result'] = "error" response['message'] = "Login Required" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if session[LOGIN_TYPE] != LoginType.EMP: response['result'] = "error" response['message'] = "Not a User" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) user_id = session[LOGIN_ID] user = UserDB.user(uno=user_id) if not user.valid(): response['result'] = "error" response['message'] = "Login Required" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) u_name = data.get('name') u_email = data.get('email') u_website = data.get('website') u_description = data.get('description') if ('name' in data and not u_name) or ('email' in data and not u_email): response['result'] = "error" response['message'] = "No Input" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if u_name: user['name'] = u_name if u_email: user['email'] = u_email if 'website' in data: user['website'] = u_website if 'description' in data: user['description'] = u_description if not user.valid(): response['result'] = "error" response['message'] = user.error.value return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) result = UserDB.update(user) if not result: response['result'] = "error" response['message'] = "Something Wrong Happened" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if u_name: name = user['name'] name_arr = name.split() name = "" for i in name_arr: name += i[0] response['user_initials'] = name response['result'] = "success" response['message'] = "Changed Successfully" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False)
def save_response(request): response = {} found_sub = None data = request.GET session = request.session test_id = data.get('id') pset_id = data.get('category') ques_no = data.get('question') answer = data.get('response') if not test_id or not pset_id or not ques_no: response['result'] = "error" response['message'] = "Wrong Data Provided" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if not answer or answer == "": answer = None test = TestModuleDB.test_module(uno=test_id) if not test.valid(): response['result'] = "error" response['message'] = "Test Doesn't Exist" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) login_id = request.session.get(LOGIN_ID) login_type = request.session.get(LOGIN_TYPE) if not login_id or not login_type: response['result'] = "error" response['message'] = "Login Required" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if login_type == LoginType.ORG: org = OrganizationDB.organization(uno=login_id) if not org.valid(): response['result'] = "error" response['message'] = "Something Looks Wrong with the Login" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) elif login_type == LoginType.EMP: user = UserDB.user(uno=login_id) if not user.valid(): response['result'] = "error" response['message'] = "Something Looks Wrong with the Login" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if not user['role'] or not user['organization']: if not test.is_live(): response['result'] = "error" response['message'] = "Test is Not Live" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) submission = user.submission(test=test_id) if submission.valid(): found_sub = submission psets = test.problem_sets() if pset_id not in [p['_id'] for p in psets]: response['result'] = "error" response['message'] = "Category Doesn't Exist" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) pset = {} for p in psets: if p['_id'] == pset_id: pset = p questions = pset['questions'] if len(questions) < int(ques_no) or int(ques_no) < 0: response['result'] = "error" response['message'] = "Question Doesn't Exist" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False) if found_sub: found_sub.save_response(pset_id, ques_no, answer) SubmissionDB.update(found_sub) response['result'] = "success" return JsonResponse(json.dumps(response, indent=4, sort_keys=True), safe=False)
def post(self, request): # validating client if LOGIN_ID not in request.session or LOGIN_TYPE not in request.session: return HttpResponseRedirect("/profile") if request.session[LOGIN_TYPE] == LoginType.ORG: return HttpResponseRedirect("/profile") user_id = request.session[LOGIN_ID] user_type = request.session[LOGIN_TYPE] user = UserDB.user(uno=user_id) if not user.valid(): return HttpResponseRedirect("/profile") if user['role'] != PROBLEM_SETTER: return HttpResponseRedirect("/profile") # validating request data = request.POST noq = data.get('noq') if not noq: request.session[ ADD_PROBLEM_SET_RESULT] = CreatePSetResult.SOMETHING_ELSE.value return HttpResponseRedirect("/create/problem-set") if int(noq) <= 0: request.session[ ADD_PROBLEM_SET_RESULT] = CreatePSetResult.NO_QUESTIONS.value return HttpResponseRedirect("/create/problem-set") ps_name = data.get('ps_name') if not ps_name: request.session[ ADD_PROBLEM_SET_RESULT] = CreatePSetResult.NO_NAME.value return HttpResponseRedirect("/create/problem-set") ps_category = data.get('ps_category') pset = { "name": ps_name, "category": ps_category, "public": False, "organization": user['organization'], "questions": [] } problem_sets = ProblemSetDB.all() for pset in problem_sets: if ps_name == pset['name'] and user['organization'] == pset[ 'organization']: request.session[ ADD_PROBLEM_SET_RESULT] = CreatePSetResult.SAME_NAME_EXISTS.value return HttpResponseRedirect("/create/problem-set") allques = [] for q in range(1, int(noq) + 1): i = str(q) qtype = data['q' + i + 't'] if qtype == "OBJ": qop = [] qnoo = data.get('q' + i + 'noo') for o in range(1, int(qnoo) + 1): j = str(o) qop.append(data['q' + i + 'o' + j]) ques = { "no": i, "type": "OBJ", "question": data.get('q' + i + 'q'), "no_of_options": data.get('q' + i + 'noo'), "options": qop, "correct": data.get('q' + i + 'co'), "marks": data.get('q' + i + 'marks'), "tag": data.get('q' + i + 'tag') } allques.append(ques) continue if qtype == "SUB": ques = { "no": i, "type": "SUB", "question": data.get('q' + i + 'q'), "limit": data.get('limit'), "tag": data.get('q' + i + 'tag') } allques.append(ques) continue if qtype == "COD": ques = { "no": i, "type": "COD", "question": data.get('q' + i + 'q'), "input": data.get('q' + i + 'si'), "output": data.get('q' + i + 'so'), "time_limit": data.get('q' + i + 'tl'), "marks": data.get('q' + i + 'marks'), "tag": data.get('q' + i + 'tag') } allques.append(ques) continue # saving problem set pset['questions'] = allques org = OrganizationDB.organization(uno=user['organization']) if not org.valid(): request.session[ ADD_PROBLEM_SET_RESULT] = CreatePSetResult.SOMETHING_ELSE.value return HttpResponseRedirect("/create/problem-set") result, pset = ProblemSetDB.create(pset) if not result: print("error in creating document in ProblemSets") request.session[ ADD_PROBLEM_SET_RESULT] = CreatePSetResult.SOMETHING_ELSE.value return HttpResponseRedirect("/create/problem-set") org['problem_sets'].append(pset['_id']) OrganizationDB.update(org) request.session[ADD_PROBLEM_SET_RESULT] = CreatePSetResult.ADDED.value return HttpResponseRedirect("/create/problem-set")
def post(self, request): # validating client session = request.session if not session.get(LOGIN_ID) or not session.get(LOGIN_TYPE): return HttpResponseRedirect("/profile") if session[LOGIN_TYPE] == LoginType.ORG: return HttpResponseRedirect("/profile") user_id = session[LOGIN_ID] user_type = session[LOGIN_TYPE] user = UserDB.user(uno=user_id) if not user.valid(): return HttpResponseRedirect("/profile") if user['role'] != TEST_SUPERVISOR: return HttpResponseRedirect("/profile") data = request.POST test_name = data.get('test_name') if not test_name: request.session[ ADD_TEST_MODULE_RESULT] = CreateTMResult.NO_NAME.value return HttpResponseRedirect("/create/test-module") org = OrganizationDB.organization(uno=user['organization']) if not org.valid(): request.session[ ADD_TEST_MODULE_RESULT] = CreateTMResult.SOMETHING_ELSE.value return HttpResponseRedirect("/create/test-module") test_modules = TestModuleDB.all() for doc in test_modules: if test_name == doc['name'] and user['organization'] == doc[ 'organization']: request.session[ ADD_TEST_MODULE_RESULT] = CreateTMResult.SAME_NAME_EXISTS.value return HttpResponseRedirect("/create/test-module") if 'no-of-psets' not in data: request.session[ ADD_TEST_MODULE_RESULT] = CreateTMResult.SOMETHING_ELSE.value return HttpResponseRedirect("/create/test-module") nopset = int(data['no-of-psets']) if int(nopset) <= 0: request.session[ ADD_TEST_MODULE_RESULT] = CreateTMResult.NO_PSET.value return HttpResponseRedirect("/create/test-module") test_category = data.get('test_category') test_description = data.get('test_description') test = { "name": test_name, "category": test_category, "description": test_description, "organization": org['_id'], "problem_sets": [], "submissions": None, "schedule": None, "job_offer": None, } try: time_hour = int(str(data.get('time-hour'))) time_min = int(str(data.get('time-min'))) except Exception as e: print("hello") request.session[ ADD_TEST_MODULE_RESULT] = CreateTMResult.SOMETHING_ELSE.value return HttpResponseRedirect("/create/test-module") time_am_pm = data.get('time-am-pm') if time_am_pm != "PM" and time_am_pm != "AM": request.session[ ADD_TEST_MODULE_RESULT] = CreateTMResult.SOMETHING_ELSE.value return HttpResponseRedirect("/create/test-module") time_hour -= 1 if time_am_pm == "PM": time_hour += 12 time = str(time_hour) + ":" + str(time_min) schedule = { "date": data.get('date'), "time": time, "duration": data.get('duration') } job_offer = { "position": data.get('position'), "type": data.get('type'), "duration": data.get('job-duration'), "salary": data.get('salary'), "currency": data.get('currency'), "description": data.get('job-description') } test['schedule'] = schedule test['job_offer'] = job_offer all_psets = {doc['_id']: doc for doc in ProblemSetDB.all()} for i in range(0, nopset): pset_id = data.get('ps' + str(i)) if pset_id: test['problem_sets'].append(pset_id) result, test = TestModuleDB.create(test) if not result: print("error in creating document in Test Modules") request.session[ ADD_TEST_MODULE_RESULT] = CreateTMResult.SOMETHING_ELSE.value return HttpResponseRedirect("/create/test-module") result, subset = SubmissionSetDB.create({"test": test['_id']}) if result: test['submissions'] = subset['_id'] TestModuleDB.update(test) org['test_modules'].append(test['_id']) OrganizationDB.update(org) request.session[ADD_TEST_MODULE_RESULT] = CreateTMResult.ADDED.value return HttpResponseRedirect("/create/test-module")
def get(self, request, user=None): if LOGIN_ID not in request.session \ or LOGIN_TYPE not in request.session: request.session[ADD_EMP_RESULT] = RemoveResult.SOMETHING_ELSE.value return HttpResponseRedirect("/profile") if request.session[LOGIN_TYPE] != LoginType.ORG \ or not user: request.session[ADD_EMP_RESULT] = RemoveResult.SOMETHING_ELSE.value return HttpResponseRedirect("/profile") org_id = request.session[LOGIN_ID] org = OrganizationDB.organization(uno=org_id) if not org.valid(): request.session[AUTH_RESULT] = LoginResult.SOMETHING_ELSE.value del request.session[LOGIN_ID] del request.session[LOGIN_TYPE] return HttpResponseRedirect("/profile") user = UserDB.user(uno=user) print("1") if not user.valid(): print("1") request.session[ADD_EMP_RESULT] = RemoveResult.EMP_NOT_VALID.value return HttpResponseRedirect("/profile") if user['organization'] != org['_id']: print("1") request.session[AUTH_RESULT] = RemoveResult.SOMETHING_ELSE.value del request.session[LOGIN_ID] del request.session[LOGIN_TYPE] return HttpResponseRedirect("/profile") if user['role'] == "GN": org.remove(user['_id']) user['role'] = None user['organization'] = None else: if user['role'] == "HR": org.remove_emp(Organization.EmpType.HR) org.add(user['_id']) user['role'] = "GN" elif user['role'] == "SU": org.remove_emp(Organization.EmpType.SU) org.add(user['_id']) user['role'] = "GN" elif user['role'] == "PS": org.remove_emp(Organization.EmpType.PS) org.add(user['_id']) user['role'] = "GN" else: print("1") request.session[ ADD_EMP_RESULT] = RemoveResult.SOMETHING_ELSE.value return HttpResponseRedirect("/profile") UserDB.update(user) OrganizationDB.update(org) request.session[ADD_EMP_RESULT] = RemoveResult.REMOVED.value return HttpResponseRedirect("/profile")
def get(self, request, user=None): session = request.session if not session.get(LOGIN_ID) or not session.get(LOGIN_TYPE): request.session[ADD_EMP_RESULT] = AddResult.SOMETHING_ELSE.value return HttpResponseRedirect("/profile") if session.get(LOGIN_TYPE) != LoginType.ORG or not user: request.session[ADD_EMP_RESULT] = AddResult.SOMETHING_ELSE.value return HttpResponseRedirect("/profile") org_id = request.session[LOGIN_ID] org = OrganizationDB.organization(uno=org_id) if not org.valid(): request.session[AUTH_RESULT] = LoginResult.SOMETHING_ELSE.value del request.session[LOGIN_ID] del request.session[LOGIN_TYPE] return HttpResponseRedirect("/profile") if 'mod' not in request.GET: request.session[ADD_EMP_RESULT] = AddResult.SOMETHING_ELSE.value return HttpResponseRedirect("/profile") mod = request.GET['mod'] user = UserDB.user(uno=user) if not user.valid(): request.session[ADD_EMP_RESULT] = AddResult.EMP_NOT_VALID.value return HttpResponseRedirect("/profile") if mod == "GN": if user.get('organization'): request.session[ADD_EMP_RESULT] = AddResult.EMP_NOT_FREE.value return HttpResponseRedirect("/profile") user['organization'] = org_id user['role'] = 'GN' org.add(user['_id']) else: if user['organization'] != org['_id'] \ or user['role'] != "GN": request.session[ADD_EMP_RESULT] = AddResult.EMP_NOT_FREE.value return HttpResponseRedirect("/profile") if mod == "HR": org.set_emp(Organization.EmpType.HR, user['_id']) user['role'] = "HR" elif mod == "SU": org.set_emp(Organization.EmpType.SU, user['_id']) user['role'] = "SU" elif mod == "PS": org.set_emp(Organization.EmpType.PS, user['_id']) user['role'] = "PS" else: request.session[ ADD_EMP_RESULT] = AddResult.SOMETHING_ELSE.value return HttpResponseRedirect("/profile") UserDB.update(user) OrganizationDB.update(org) request.session[ADD_EMP_RESULT] = AddResult.ADDED.value return HttpResponseRedirect("/profile")
def get(self, request, test_id): context = {} login_id = None if LOGIN_ID in request.session: login_id = request.session[LOGIN_ID] login_type = None if LOGIN_TYPE in request.session: login_type = request.session[LOGIN_TYPE] if login_id and login_type: if login_type == LoginType.ORG: org = OrganizationDB.organization(uno=login_id) if org.valid(): context['org'] = org context['login'] = True elif login_type == LoginType.EMP: user = UserDB.user(uno=login_id) if user.valid(): user_name_arr = user['name'].split() user_init = "" for i in user_name_arr: user_init += i[0] user['initial'] = user_init user['organization'] = user.organization() context['user'] = user context['login'] = True test = TestModuleDB.test_module(uno=test_id) if not test.valid(): raise Http404 test['id'] = test['_id'] test['organization'] = test.organization() job_type = test['job_offer']['type'] for jt in JobType: if job_type == jt.name: test['job_offer']['type'] = jt.value break job_duration = test['job_offer']['duration'] for jd in JobDuration: if job_duration == jd.name: test['job_offer']['duration'] = jd.value break if test.is_completed(): test['status'] = "completed" elif test.is_live(): test['status'] = "live" test['remaining_time'] = test.pretty_remaining_time(True) else: test['status'] = "coming" test['remaining_time'] = test.pretty_remaining_time() test_duration = int(test['schedule']['duration']) if test_duration / 60 <= 1: test['schedule']['duration'] = str(test_duration) + "min" else: test['schedule']['duration'] = str(test_duration / 60) + "h" test['schedule']['open_date'] = test.pretty_date() context['test'] = test return render(request, "test/view.html", context)
def get(self, request, test_id): context = {} found_sub = None login_id = request.session.get(LOGIN_ID) login_type = request.session.get(LOGIN_TYPE) test = TestModuleDB.test_module(uno=test_id) if not test.valid(): return Http404 if not test.is_live(): return HttpResponseRedirect("/test/" + test_id) if not login_id or not login_type: return HttpResponseRedirect("/login?r=/test/start/" + test_id) if login_type == LoginType.ORG: org = OrganizationDB.organization(uno=login_id) if org.valid(): context['org'] = org context['login'] = True else: del request.session[LOGIN_ID] request.session[AUTH_RESULT] = LoginResult.SOMETHING_ELSE return HttpResponseRedirect("/login?r=/test/start/" + test_id) elif login_type == LoginType.EMP: user = UserDB.user(uno=login_id) if user.valid(): user_name_arr = user['name'].split() user_init = "" for i in user_name_arr: user_init += i[0] user['initial'] = user_init context['user'] = user context['login'] = True else: del request.session[LOGIN_ID] request.session[AUTH_RESULT] = LoginResult.SOMETHING_ELSE return HttpResponseRedirect("/login?r=/test/start/" + test_id) if not user['role'] or not user['organization']: context['pe'] = True submission = user.submission(test=test_id) if submission.valid(): found_sub = submission elif user.register_for_test(test=test): TestModuleDB.update(test) UserDB.update(user) test['id'] = test['_id'] count = 1 problem_sets = test.problem_sets() for pset in problem_sets: pset['no'] = count pset['id'] = pset['_id'] count = count + 1 if found_sub: for q in pset['questions']: q['submitted_data'] = submission.response( pset['_id'], q['no']) test['problem_sets'] = problem_sets test['remaining_time'] = test.pretty_remaining_time(True) context['test'] = test return render(request, "test/start.html", context)