def changePassword(request): if request.is_ajax(): password = request.POST['password'] user = EN_Users.objects.get( id=request.session[SessionProperties.USER_ID_KEY]) existingPass = user.en_logincredentials.password if (existingPass == password): retDict = { "status": False, "message": DisplayKey.get("same_password") } return HttpResponse(json.dumps(retDict)) else: credentials = user.en_logincredentials if credentials.password_history is None or credentials.password_history != password: credentials.password_history = existingPass credentials.password = password credentials.last_logged_in_time = datetime.datetime.now() credentials.save() retDict = { "status": True, "message": DisplayKey.get("successful_pass_reset") } return HttpResponse(json.dumps(retDict)) else: retDict = { "status": False, "message": DisplayKey.get("last_two_pass_error") } return HttpResponse(json.dumps(retDict)) else: return HttpResponseRedirect("../Page404/")
def changeUsername(request): if request.is_ajax(): username = request.POST['username'] user = EN_Users.objects.get( id=request.session[SessionProperties.USER_ID_KEY]) if (user.en_logincredentials.username == username): retDict = { "status": False, "message": DisplayKey.get("same_username") } return HttpResponse(json.dumps(retDict)) else: usernameExists = EN_LoginCredentials.objects.exclude( user=user).filter(username=username) if (not usernameExists.exists()): loginData = EN_LoginCredentials.objects.get(user=user) loginData.username = username loginData.last_logged_in_time = datetime.datetime.now() loginData.save() retDict = { "status": True, "message": DisplayKey.get("successful_username_reset") } return HttpResponse(json.dumps(retDict)) else: retDict = { "status": True, "message": DisplayKey.get("username_exists_otheruser") } return HttpResponse(json.dumps(retDict)) else: return HttpResponseRedirect("../Page404/")
def saveBookDetails(request): if request.method == 'POST': form_data = FORM_BookDetails(request.POST) if (form_data.is_valid()): try: bookObj = EN_Books() bookObj.name = form_data.cleaned_data.get("book_name") bookObj.book_code = form_data.cleaned_data.get("book_code") bookObj.published_year = form_data.cleaned_data.get( "book_year") vol = form_data.cleaned_data.get("book_volume") bookObj.volume = 1 if (vol == None or vol == "") else int(vol) bookObj.author = form_data.cleaned_data.get("book_author") bookObj.publisher = form_data.cleaned_data.get( "book_publisher") bookObj.category = TL_BooksCategory.objects.get( code=form_data.cleaned_data.get("book_category")) if request.POST.get( "book_sub_category") != "" and request.POST.get( "book_sub_category") != None: bookObj.sub_category = TL_BooksSubCategory.objects.get( code=request.POST.get("book_sub_category")) bookObj.save() messages.success(request, DisplayKey.get("book_added_successfully")) return HttpResponseRedirect("../Books") except Exception as e: messages.error(request, e.__str__()) return addBook(request) else: return addBook(request) else: messages.warning(request, DisplayKey.get("error_not_a_post_request")) return HttpResponseRedirect("../Home")
def __call__(self, request): try: fullPath = request.get_full_path() if list(fullPath).__contains__("?"): fullPathList = list((fullPath.split("?")[0]).split("/")) else: fullPathList = list(fullPath.split("/")) for uri in fullPathList: if uri.strip() == "": fullPathList.remove(uri) app = fullPathList[0] method = "Index" if fullPathList.__len__( ) == 1 else fullPathList[1] allow = False isURLInvalid = False if not AppAccessibilityDictionary.APPS_WITH_FULL_ACCESS_TO_ALL_USERS.__contains__( app): if AppAccessibilityDictionary.APPS_WITH_LIMITED_ACCESS_TO_USERS.keys( ).__contains__(app): limitedAccessApp = AppAccessibilityDictionary.APPS_WITH_LIMITED_ACCESS_TO_USERS.get( app) if limitedAccessApp.keys().__contains__(method): currentRole = request.session[ SessionProperties.USER_ACTIVE_ROLE_KEY] allow = True if ( limitedAccessApp.get(method).__contains__( currentRole) or limitedAccessApp.get(method).__contains__("all") ) else False else: isURLInvalid = True else: isURLInvalid = True else: allow = True if allow: return self.get_response(request) elif isURLInvalid: messages.error(request, DisplayKey.get("unregistered_url")) return HttpResponseRedirect('../Home') else: messages.error(request, DisplayKey.get("no_privelege_to_access_app")) return HttpResponseRedirect('../Home') except Exception as e: Logger.error( "Error occured on middleware MW_RoleAccessiblityOnAppAuthentication \n : {}" .format(e)) messages.error(request, DisplayKey.get("unregistered_url")) return HttpResponseRedirect('../Home')
def getOrganizationGroup(request): if "pid" in request.GET: user_product_id = request.GET["pid"].strip() try: organization_group = EN_OrganizationGroup.objects.get(product_id=user_product_id) except: messages.error(request, DisplayKey.get("invalid_product_id")) return index(request) else: messages.error(request, DisplayKey.get("no_get_atribute_specified")) return index(request) return HttpResponse("Show Individual Org Group Details")
def searchBooks(request): if request.is_ajax(): if request.method == "POST": status = True message = "" search_key = request.POST.get("search_key") books = [] if search_key == None or search_key == "": status = False message = "Search key should not be empty" else: books = EN_Books.objects.filter( Q(name__contains=search_key) | Q(book_code__contains=search_key)) totalCount = books.count() if totalCount > 30: status = False message = "Filter using bookid. Result exceeds threshold {}" jsonRetData = { "status": status, "message": message, "booksData": [{ "id": book.id, "name": book.name, "volume": book.volume, "book_code": book.book_code, "author": book.author, "publisher": book.publisher, "category": book.category.name, "sub_category": None if book.sub_category == None else book.sub_category.name, } for book in books] } return HttpResponse(json.dumps(jsonRetData)) else: messages.warning(request, DisplayKey.get("error_not_a_post_request")) else: messages.warning(request, DisplayKey.get("error_not_ajax_request")) return HttpResponseRedirect("../Home")
def clean(self): data = self.cleaned_data classStart = data["class_start_date"] classEnd = data["class_end_date"] if (classStart > classEnd): self.add_error( "class_end_date", DisplayKey.get("class_end_date_prior_to_start_date_error")) if (data["class_division"] != None): division = data["class_division"] if re.match("^[a-z,A-Z]*$", division) is not None: divArray = division.split(",") divList = [d.upper() for d in divArray] for div in division.split(","): if not (div.strip() == "" or div.strip() == None): div = div.upper() if len(div) > 1: self.add_error( "class_division", "Division '{}' should be single characters". format(div)) elif divList.count(div) > 1: divList.remove(div) self.add_error( "class_division", "Division '{}' occurs multiple times".format( div)) elif EN_Classes.objects.filter( class_division=div, class_name=data["class_name"]): user_id = self.request.session[ SessionProperties.USER_ID_KEY] try: role = EN_UserRoles.objects.get( approved=True, is_selected_role=True, user_id=user_id, role__code=Roles.SCHOOL_ADMIN) existing_divs = [ clas.class_division for clas in EN_Classes.objects.filter( class_name=data["class_name"], organization=role.related_organization) ] if div in existing_divs: self.add_error( "class_division", "Division '{}' already exists for class {} " .format(div, data["class_name"])) except Exception as e: self.add_error( "class_division", "No permmission for current role") else: self.add_error( "class_division", "Invalid chars found. Single alphabets seperated by comma are only allowed" ) return data
def saveCredentialPageDetails(request): if(request.method == "POST"): form_data = FORM_CredentialDetails(request.POST) if(request.POST["credential_submit_button"] == "next"): if (form_data.is_valid()): try: ur = UserRegistrationSessions(request).getCorrespondingDBRecord() ur.username = form_data.cleaned_data.get("username") ur.password = form_data.cleaned_data.get("password") ur.subscribe_for_news_letter= form_data.cleaned_data.get("subscribe_for_news_letter") ur.save() try: user = SaveRecord().save(ur) del request.session[Constants.SESSION_TOKEN] ur.delete() messages.success(request, DisplayKey.get("user_successfully_registered")) except Exception as e: messages.error(request,e.__str__()) return loadCredentialsPage(request) template_data = { "url": "{}/SignUp/ActivateAccount".format(request.get_host()), "name": user.name, "token": user.activation_token, "product_id": user.product_id, } try: Email().sendEmail( template=EmailTemplates.ACCOUNT_ACTIVATION_EMAIL, subject="Activate Wokidz Account", recipient_list=[user.contact.email_id], template_data=template_data ) except Exception as e: messages.error(request,"Registered Successfully but failed to send activation Email. Please contact site admin") NotificationHelper(request).notify(recipient_id=user.id, type=NotificationTypes.WELCOME_MESSAGE) return HttpResponseRedirect("../Login") except Exception as e: messages.error(request,e.__str__()) return loadCredentialsPage(request) else: return loadCredentialsPage(request) else: # Note: Converting method to GET from POST # If not changed, in session_helper class, form validation will be trigerred ur = UserRegistrationSessions(request).getCorrespondingDBRecord() if (form_data.is_valid()): ur.username = form_data.cleaned_data.get("username") ur.password = form_data.cleaned_data.get("password") ur.subscribe_for_news_letter = form_data.cleaned_data.get("subscribe_for_news_letter") ur.save() request.method = "GET" return loadPermanentAddressPage(request) if ur.is_current_address else loadCurrentAddressPage(request) else: return loadCredentialsPage(request) else: return HttpResponseRedirect("LoadCredentialsPage")
def getUserDetails(request): if request.is_ajax(): product_ids = request.POST["product_ids"] student_id = request.POST["student_id"] retDict = {"status": False, "message": None, "data": []} prdIdListString = (product_ids.replace(" ", "")).strip() if (re.match('^[MY0-9,]+$', prdIdListString) == None): retDict["message"] = DisplayKey.get( "invalid_characters_in_product_id_list") else: prdId_list = list(prdIdListString.split(",")) student = EN_Users.objects.get(id=int(student_id)) if student.product_id in prdId_list: retDict["message"] = DisplayKey.get( "parent_id_and_student_id_cannot_be_same") else: users = EN_Users.objects.filter(product_id__in=prdId_list) retList = [] prodComparisonList = [] for user in users: addr = EN_AddressBook.objects.get( user=user, is_permanent_address=True) permanent_adr = addr.house_name + ", " + addr.street retUserDict = { "id": user.id, "name": user.name, "gender": user.gender.code, "contact_no": user.contact.mobile_number, "address": permanent_adr, "dp": user.display_picture, "product_id": user.product_id } prodComparisonList.append(user.product_id) retList.append(retUserDict) diff = set(prdId_list) - set(prodComparisonList) if diff.__len__() > 0: retDict[ "message"] = "Could not find Wokidz ID(s) : {}".format( diff.__str__()) else: retDict["status"] = True retDict["data"] = retList return HttpResponse(json.dumps(retDict)) else: messages.warning(request, DisplayKey.get("direct_access_denied")) return HttpResponse("../Page404/")
def __call__(self, request): appName = AppUtil.getAppName(request) if appName not in self.excluded_apps: user_id = request.session[SessionProperties.USER_ID_KEY] if SessionProperties.USER_ID_KEY in request.session else None if user_id == None: Logger.error("Middleware Authentication Denied User ID {} To Access App {} ".format(user_id,appName)) messages.warning(request,DisplayKey.get("error_session_time_out")) return HttpResponseRedirect('../Login') return self.get_response(request)
def loadRoleSettingPage(request): data = UIDataHelper(request).getData(page="is_raise_role_request") user_id = request.session[SessionProperties.USER_ID_KEY] accepted_user_list = [ Roles.INSTITUTION_SUPER_USER, Roles.SCHOOL_ADMIN, Roles.TEACHER ] ur = EN_UserRoles.objects.filter(approved=True, user_id=user_id, role__code__in=accepted_user_list, is_selected_role=True) if ur.exists(): ur = ur[0] if ur.role.code == Roles.INSTITUTION_SUPER_USER: approvalList = RoleApprovalHierarchy.INSTITUTION_SU_APPROVAL_LIST elif ur.role.code == Roles.SCHOOL_ADMIN: approvalList = RoleApprovalHierarchy.SCHOOL_ADMIN_APPROVAL_LIST elif ur.role.code == Roles.TEACHER: approvalList = RoleApprovalHierarchy.TEACHER_APPROVAL_LIST else: approvalList = [] roles = [{ "code": role.code, "name": role.name } for role in TL_Roles.objects.filter(code__in=approvalList)] schools_list = [] if ur.related_organization_group != None: schools_list = [{ "org_id": org.id, "org_name": org.school_name + ", " + org.street } for org in EN_Organization.objects.filter( organization_group=ur.related_organization_group)] elif ur.related_organization != None: schools_list = [{ "org_id": ur.related_organization.id, "org_name": ur.related_organization.school_name + ", " + ur.related_organization.street }] data.__setitem__("roles", roles) data.__setitem__("schools_list", schools_list) data.__setitem__( "form", FORM_UserRoleAssignment(request.POST) if request.method == "POST" else FORM_UserRoleAssignment()) template = loader.get_template("roles_assign_roles_to_user.html") return HttpResponse(template.render(data, request)) else: messages.error( request, DisplayKey.get( "current_role_doesnot_have_permission_to_do_this_action")) return HttpResponseRedirect("../Home")
def saveGroupDetails(request): if request.method == 'POST': form_data = FORM_NewOrganizationGroup(request.POST) if form_data.is_valid(): orgGrp = EN_OrganizationGroup() formData = form_data.cleaned_data orgGrp.group_name = formData.get("groupname") orgGrp.website = formData.get("website") orgGrp.publish_your_site = formData.get("createpage") orgGrp.product_id = EN_SequenceUtil.genProductIdForOrganizationGroup() orgGrp.account_status = TL_AccountStatus.objects.get(code="active") try: orgGrp.save() # --Roles--------------- inst_super_user = EN_Users.objects.get(product_id=formData.get("organization_su_prd_id")) userRole = EN_UserRoles() userRole.user = inst_super_user userRole.role = TL_Roles.objects.get(code=Roles.INSTITUTION_SUPER_USER) userRole.approved = True userRole.request_raised_by_id = 1 userRole.request_raised_on = datetime.datetime.now() userRole.related_organization_group = orgGrp userRole.related_organization = None userRole.related_user = None userRole.request_approved_by_id = 1 userRole.request_approved_on = datetime.datetime.now() try: userRole.save() except Exception as e: orgGrp.delete() messages.error(request, "Failed to assign role : {}".format(e.__context__)) return HttpResponseRedirect("../Organization/RegisterOrganization") try: NotificationHelper(request).notify(recipient_id=inst_super_user.id,type=NotificationTypes.NEW_ROLE_ADDED) except Exception as e: orgGrp.delete() userRole.delete() messages.error(request, "Failed to create activity : {}".format(e.__context__)) return HttpResponseRedirect("../Organization/RegisterOrganization") # --------------------- messages.success(request, DisplayKey.get("org_group_created_successfully")) messages.info(request, "WoKidz ID For Organization {} is {}".format(orgGrp.group_name,orgGrp.product_id)) return HttpResponseRedirect("../Organization/OrganizationGroups") except Exception as e: messages.warning(request, e.__context__) return registerOrgGroup(request) else: return registerOrgGroup(request) else: return HttpResponseRedirect("..Redirects/ErrorPage?page=403")
def index(request): data = UIDataHelper(request).getData(page="is_list_school_timings") user_id = request.session[SessionProperties.USER_ID_KEY] user_role = EN_UserRoles.objects.filter(approved=True, user_id=user_id, is_selected_role=True, role__code=Roles.SCHOOL_ADMIN) if user_role.exists(): user_role = user_role.first() timings = EN_SchoolTimings.objects.filter( organization=user_role.related_organization) dataList = [] for timing in timings: off_days = "" if timing.class_off_on_sunday: off_days += "Sunday, " if timing.class_off_on_monday: off_days += "Monday, " if timing.class_off_on_tuesday: off_days += "Tuesday, " if timing.class_off_on_wednesday: off_days += "Wednesday, " if timing.class_off_on_thursday: off_days += "Thursday, " if timing.class_off_on_friday: off_days += "Friday, " if timing.class_off_on_saturday: off_days += "Saturday, " off_days = off_days.strip() if off_days.__len__() > 0: if off_days[-1] == ",": off_days = off_days[:-1] dataList.append({ "name": timing.timing_name, "timing": "{} to {} ".format(timing.school_starting_time, timing.school_closing_time), "off_days": off_days, }) data.__setitem__("timings", dataList) template = loader.get_template("school_timings_list_all_timings.html") return HttpResponse(template.render(data, request)) else: messages.warning( request, DisplayKey.get("current_role_cannot_perform_this_action")) return HttpResponseRedirect("../Home")
def index(request): user_id = request.session[SessionProperties.USER_ID_KEY] data = UIDataHelper(request).getData(page="is_roles") rh = RolesViewHelper(user_id) roles = rh.getRolesToDisplayOnRolesScreen() if roles == None: messages.error(request, DisplayKey.get("invalid_table_name_on_user_role")) return HttpResponseRedirect("/Home/") else: data.__setitem__("user_roles", roles) data.__setitem__("system_roles", rh.getSystemRolesAsList()) template = loader.get_template("roles_list_all_roles_of_user.html") return HttpResponse(template.render(data, request))
def changeRole(request): user_id = request.session[SessionProperties.USER_ID_KEY] user_role_id = 0 if not "user_role_id" in request.POST else int( request.POST["user_role_id"]) if user_role_id == 0: EN_UserRoles.objects.filter( user_id=user_id, is_selected_role=True).update(is_selected_role=False) request.session[SessionProperties.USER_ACTIVE_ROLE_KEY] = "home" UserRolesHelper(request).updateRolesOnSession() messages.success(request, DisplayKey.get("role_changes_successfully")) elif user_id == 1: #Wokidz User EN_UserRoles.objects.filter(user_id=user_id).update( is_selected_role=True) messages.warning( request, DisplayKey.get("no_role_change_permitted_for_site_admin")) else: try: ur = EN_UserRoles.objects.get(id=user_role_id, approved=True, user_id=user_id) if ur.is_selected_role: messages.warning(request, DisplayKey.get("already_on_the_same_role")) else: EN_UserRoles.objects.filter(user_id=user_id).update( is_selected_role=False) ur.is_selected_role = True ur.save() request.session[ SessionProperties.USER_ACTIVE_ROLE_KEY] = ur.role.code UserRolesHelper(request).updateRolesOnSession() messages.success(request, DisplayKey.get("role_changes_successfully")) except: messages.error(request, DisplayKey.get("no_such_role_for_user")) return HttpResponseRedirect('../Home')
def index(request, is_add_new_class = False): data = UIDataHelper(request).getData(page="is_list_all_classes") user_id = request.session[SessionProperties.USER_ID_KEY] user_role = EN_UserRoles.objects.filter(Q(role__code=Roles.SCHOOL_ADMIN) | Q(role__code=Roles.PRINCIPAL), approved=True, user_id=user_id, is_selected_role=True) if user_role.exists(): user_role = user_role.first() classes = EN_Classes.objects.filter(organization=user_role.related_organization) if request.method == "POST": if "class_names" in request.POST: filter_class = request.POST["class_names"] if filter_class != "all": classes = classes.filter(class_name=filter_class) dataList = [] for classData in classes: dataList.append({ "name" : classData.class_name, "division":classData.class_division, "nickname":classData.batch_nick_name if(classData.batch_nick_name != None and classData.batch_nick_name != "") else " ", "start_date":classData.academic_starting_year, "end_date":classData.academic_ending_year, "batch":classData.batch_name, "class_teacher":classData.class_teacher.name if(classData.class_teacher != None) else "-", }) data.__setitem__("classes",dataList) data.__setitem__("is_add_new_class",is_add_new_class) if request.method == "POST": if "class_names" in request.POST: fd_cls_details = FORM_ClassDetails(request=request) fd_classes = FORM_ClassNames(request.POST,request=request) else: fd_cls_details = FORM_ClassDetails(request.POST,request=request) fd_classes = FORM_ClassNames(request.POST,request=request) else: fd_cls_details = FORM_ClassDetails(request=request) fd_classes = FORM_ClassNames(request=request) data.__setitem__("form",fd_cls_details) data.__setitem__("class_names",fd_classes) template = loader.get_template("classes_list_all_classes.html") return HttpResponse(template.render(data, request)) else: messages.warning(request, DisplayKey.get("current_role_cannot_perform_this_action")) return HttpResponseRedirect("../Home")
def addSchoolTimings_Page1_Submit(request): if request.method == "POST": form_data = FORM_AddModifySchoolTiming_Page1(request.POST, request=request) if form_data.is_valid(): if request.POST["type"] not in ["update", "new"]: messages.warning( request, DisplayKey.get("invalid_school_timing_submit_type")) return HttpResponseRedirect("../SchoolTimings") else: request.session["PAGE_1_DATA"] = json.dumps({ "school_timing_name": form_data["school_timing_name"].value(), "school_timing_id": 0 if request.POST["type"] != "update" else int( form_data["available_timings"].value()), }) return HttpResponseRedirect("TimingDetails") else: return addSchoolTimings_Page1(request) else: messages.warning(request, DisplayKey.get("error_not_a_post_request")) return HttpResponseRedirect("../Home")
def addSchoolTimings_Page3(request): data = UIDataHelper(request).getData(page="is_add_school_timings") user_id = request.session[SessionProperties.USER_ID_KEY] user_role = EN_UserRoles.objects.filter(approved=True, user_id=user_id, is_selected_role=True, role__code=Roles.SCHOOL_ADMIN) if user_role.exists(): user_role = user_role.first() data.__setitem__("school_timings", [{ "id": st.id, "name": st.timing_name } for st in EN_SchoolTimings.objects.filter( organization=user_role.related_organization)]) template = loader.get_template("school_timings_page_3.html") return HttpResponse(template.render(data, request)) else: messages.warning( request, DisplayKey.get("current_role_cannot_perform_this_action")) return HttpResponseRedirect("../Home")
def saveOrganizationDetails(request): if request.method == 'POST': form_data = FORM_NewOrganization(request.POST) if form_data.is_valid(): orgDetails = EN_Organization() formData = form_data.cleaned_data orgDetails.organization_group = EN_OrganizationGroup.objects.get(product_id=formData.get("org_group_product_id")) orgDetails.affiliation = TL_Affiliation.objects.get(code=formData.get("affiliation")) orgDetails.organization_type = TL_InstitutionType.objects.get(code=formData.get("institution_type")) orgDetails.product_id = EN_SequenceUtil.genProductIdForOrganization() orgDetails.school_name = formData.get("school_name") orgDetails.started_date = formData.get("org_start_date") orgDetails.mobile_country_code = EN_Country.objects.get(id=formData.get("mobile_country_code")) orgDetails.mobile_number_1 = formData.get("mobile_number_1") orgDetails.mobile_number_2 = formData.get("mobile_number_2") orgDetails.landline_number_1 = formData.get("landline_1") orgDetails.landline_number_2 = formData.get("landline_2") orgDetails.email_id = formData.get("email_id") orgDetails.website = formData.get("website") orgDetails.publish_your_site = formData.get("createpage") orgDetails.account_status = TL_AccountStatus.objects.get(code="inactive") orgDetails.zipcode = EN_Zipcode.objects.get(id=int(request.POST.get("area"))) orgDetails.street = formData.get("street") orgDetails.registration_id = formData.get("school_registration_id") try: orgDetails.save() except Exception as e: messages.error(request,"Failed To Save Organization : {}".format(e.__context__)) return HttpResponseRedirect("../Organization/RegisterOrganization") messages.success(request, DisplayKey.get("organization_registration_success")) messages.info(request, "WoKidz ID For Organization {} is {}".format(orgDetails.school_name,orgDetails.product_id)) return HttpResponseRedirect("../Organization/Organizations") else: return registerOrganization(request) else: HttpResponseRedirect("RegisterOrganization?message=direct_access_denied")
def sendMessage(request): if request.is_ajax(): user_id = request.session[SessionProperties.USER_ID_KEY] retDict = {"status": False, "message": None} messageObj = EN_Message() #Saving the message try: messageData = request.POST["message"].strip() if (messageData != None and messageData != ""): messageObj.message = messageData else: retDict["message"] = DisplayKey.get("no_message_body") except: retDict["message"] = DisplayKey.get("no_message_body") #Getting the user to whom the message is sent try: if request.POST["send_to"].strip() != None: try: assigned_to = int(request.POST["send_to"]) assigned_to = None if assigned_to == user_id else assigned_to messageObj.send_to = EN_Users.objects.get(id=assigned_to) messageObj.send_by = EN_Users.objects.get(id=user_id) except: retDict["message"] = DisplayKey.get("invalid_user_id") else: retDict["message"] = DisplayKey.get("select_valid_user") except: retDict["message"] = DisplayKey.get("select_valid_user") if retDict["message"] == None: try: messageObj.save() retDict["status"] = True except: retDict["message"] = DisplayKey.get("no_message_body") return HttpResponse(json.dumps(retDict)) else: return HttpResponseRedirect("../Page404/")
def addSchoolTimings_Page2_Submit(request): if request.POST["action"] == "forward": if "PAGE_1_DATA" in request.session: user_id = request.session[SessionProperties.USER_ID_KEY] user_role = EN_UserRoles.objects.filter( approved=True, user_id=user_id, is_selected_role=True, role__code=Roles.SCHOOL_ADMIN) if user_role.exists(): user_role = user_role.first() if (user_role.related_organization != None): form_data = FORM_SchoolTiming(request.POST, request=request) if form_data.is_valid(): pageData = json.loads(request.session["PAGE_1_DATA"]) if pageData["school_timing_id"] == 0: st = EN_SchoolTimings() else: st = EN_SchoolTimings.objects.get( id=int(pageData["school_timing_id"])) try: st.organization = user_role.related_organization st.timing_name = form_data[ "school_timing_name"].value() st.school_starting_time = form_data[ "school_start_time"].value() st.school_closing_time = form_data[ "school_closing_time"].value() st.assembly_duration = int( form_data["assembly_duration"].value( )) if form_data["assembly_duration"].value( ) != "" else None st.assembly_on_sunday = form_data[ "assembly_on_sunday"].value() st.assembly_on_monday = form_data[ "assembly_on_monday"].value() st.assembly_on_tuesday = form_data[ "assembly_on_tuesday"].value() st.assembly_on_wednesday = form_data[ "assembly_on_wednesday"].value() st.assembly_on_thursday = form_data[ "assembly_on_thursday"].value() st.assembly_on_friday = form_data[ "assembly_on_friday"].value() st.assembly_on_saturday = form_data[ "assembly_on_saturday"].value() st.class_off_on_sunday = form_data[ "class_off_on_sunday"].value() st.class_off_on_monday = form_data[ "class_off_on_monday"].value() st.class_off_on_tuesday = form_data[ "class_off_on_tuesday"].value() st.class_off_on_wednesday = form_data[ "class_off_on_wednesday"].value() st.class_off_on_thursday = form_data[ "class_off_on_thursday"].value() st.class_off_on_friday = form_data[ "class_off_on_friday"].value() st.class_off_on_saturday = form_data[ "class_off_on_saturday"].value() st.save() del (request.session["PAGE_1_DATA"]) messages.success( request, "Successfully added/modified school timing") except Exception as e: messages.warning(request, e.__str__()) return addSchoolTimings_Page2(request) else: return addSchoolTimings_Page2(request) else: messages.warning( request, DisplayKey.get( "no_organization_associated_to_this_role")) return HttpResponseRedirect("../SchoolTimings") else: messages.warning( request, DisplayKey.get("current_role_cannot_perform_this_action")) return HttpResponseRedirect("../SchoolTimings") return HttpResponseRedirect("../SchoolTimings") else: messages.warning(request, DisplayKey.get("School Timing Session Expired")) return HttpResponseRedirect("AddModifyTiming") else: return HttpResponseRedirect("AddModifyTiming")
def saveClassDetails(request): if request.method == 'POST': form_data = FORM_ClassDetails(request.POST, request=request) if (form_data.is_valid()): user_id = request.session[SessionProperties.USER_ID_KEY] organization = EN_UserRoles.objects.filter(user_id=user_id, is_selected_role=True, approved=True) if(organization.exists()) : organization = organization.first() divisions = form_data.cleaned_data.get("class_division") timing = EN_SchoolTimings.objects.get(id=int(form_data.cleaned_data.get("class_time_pattern"))) if divisions == None or divisions == "": try: classObj = EN_Classes() classObj.class_name = form_data.cleaned_data.get("class_name") classObj.class_division = "A" classObj.batch_nick_name = form_data.cleaned_data.get("class_nickname") classObj.academic_starting_year = form_data.cleaned_data.get("class_start_date") classObj.academic_ending_year = form_data.cleaned_data.get("class_end_date") classObj.batch_name = classObj.academic_starting_year.year.__str__() + "-" + classObj.academic_ending_year.year.__str__() classObj.organization = organization.related_organization classObj.organization_level = TL_InstitutionLevels.objects.get(code=form_data.cleaned_data.get("institution_levels")) classObj.timing = timing classObj.save() messages.success(request, DisplayKey.get("success_added_class")) return HttpResponseRedirect("../Classes") except IntegrityError as e: messages.error(request,"Similar combination of Class,Division and ClassStartingDate Exists") return index(request, True) except Exception as e: messages.error(request, e.__str__()) return index(request, True) else: for div in divisions.split(","): if not (div.strip() == "" or div.strip() == None): try: classObj = EN_Classes() classObj.class_name = form_data.cleaned_data.get("class_name") classObj.class_division = div.strip().upper() classObj.batch_nick_name = form_data.cleaned_data.get("class_nickname") classObj.academic_starting_year = form_data.cleaned_data.get("class_start_date") classObj.academic_ending_year = form_data.cleaned_data.get("class_end_date") classObj.batch_name = classObj.academic_starting_year.year.__str__() + "-" +classObj.academic_ending_year.year.__str__() classObj.organization = organization.related_organization classObj.organization_level = TL_InstitutionLevels.objects.get(code=form_data.cleaned_data.get("institution_levels")) classObj.timing = timing classObj.save() messages.success(request, "Successfully added class {}-{} ".format(classObj.class_name,classObj.class_division)) except IntegrityError as e: messages.error(request,"Similar combination of Class,Division and ClassStartingDate [{},{},{}] Exists".format(form_data.cleaned_data.get("class_name"),div.strip().upper(),form_data.cleaned_data.get("class_start_date"))) return index(request, True) except Exception as e: messages.warning(request, e.__str__()) return HttpResponseRedirect("../Classes") else: messages.error(request, DisplayKey.get("current_role_doesnot_have_permission_to_do_this_action")) return index(request) else: return index(request,True) else: messages.warning(request, DisplayKey.get("error_not_a_post_request")) return HttpResponseRedirect("../Home")
def SaveTask(request): if request.is_ajax(): retDict = {"status": False, "message": None} taskData = EN_Tasks() # --- Priority --- # try: priority = int(request.POST["priority"]) taskData.priority = 5 if priority > 5 else 1 if priority < 1 else priority except: taskData.priority = 3 # --- Date --- # try: input_date = datetime.strptime(request.POST["date"], "%Y-%m-%d").date() if input_date < datetime.now().date(): retDict["message"] = DisplayKey.get("task_previous_date_error") else: taskData.to_be_done_on = input_date except: retDict["message"] = DisplayKey.get("invalid_date_entry") # --- Time --- # try: taskData.to_be_done_at = datetime.strptime(request.POST["time"], "%H:%M").time() except: taskData.to_be_done_at = datetime.strptime("00:00", "%H:%M").time() # --- Task --- # try: taskData.task = request.POST["taskname"].strip() if taskData.task == None: retDict["message"] = DisplayKey.get("task_name_is_empty") except: retDict["message"] = DisplayKey.get("task_name_is_empty") # --- Assigned by --- # taskData.assigned_by_id = request.session[ SessionProperties.USER_ID_KEY] # --- Assigned To --- # try: if request.POST["assigned_to"].strip() != None: try: assigned_to = int(request.POST["assigned_to"]) taskData.assigned_to = EN_Users.objects.get(id=assigned_to) except: retDict["message"] = DisplayKey.get("invalid_user_id") else: taskData.assigned_to_id = request.session[ SessionProperties.USER_ID_KEY] except: taskData.assigned_to_id = request.session[ SessionProperties.USER_ID_KEY] if retDict["message"] == None: try: taskData.save() retDict["status"] = True except: retDict["message"] = DisplayKey.get( "task_with_same_constraints_already_exist") return HttpResponse(json.dumps(retDict)) else: return HttpResponseRedirect("SaveTask?message=direct_access_denied")
def searchBooks(request): if request.is_ajax(): if request.method == "POST": status = True message = "" book_id_or_name = request.POST.get("book_id_or_name") book_author = request.POST.get("book_author") book_pubilisher = request.POST.get("book_pubilisher") book_published_year = request.POST.get("book_published_year") book_category = request.POST.get("book_category") book_sub_category = request.POST.get("book_sub_category") try: page = int(request.POST.get("page_no")) except: page = 1 status = False message = "Invalid Page number" books = EN_Books.objects filter = False if book_id_or_name != "": books = books.filter( Q(name__contains=book_id_or_name) | Q(book_code__contains=book_id_or_name)) filter = True if book_author != "": books = books.filter(author__contains=book_author) filter = True if book_pubilisher != "": books = books.filter(publisher__contains=book_pubilisher) filter = True if book_published_year != "": try: book_published_year = int(book_published_year) books = books.filter(published_year=book_published_year) filter = True except: status = False message = "Published year should be a number" if book_category != "None": books = books.filter(category__code__exact=book_category) filter = True if book_sub_category != "None" and book_sub_category != "all": books = books.filter( sub_category__code__exact=book_sub_category) filter = True if not filter: books = books.all() totalCount = books.count() perPageDataLimit = 10 if page > int(ceil(totalCount / perPageDataLimit)): page = 1 books = books[((page * perPageDataLimit) - perPageDataLimit):(page * perPageDataLimit)] jsonRetData = { "status": status, "message": message, "page_count": ceil(totalCount / perPageDataLimit), "current_page": page, "booksData": [{ "id": book.id, "name": book.name, "code": book.book_code, "volume": book.volume, "book_code": book.book_code, "author": book.author, "publisher": book.publisher, "published_year": book.published_year, "category": book.category.name, "sub_category": None if book.sub_category == None else book.sub_category.name, } for book in books] } return HttpResponse(json.dumps(jsonRetData)) else: messages.warning(request, DisplayKey.get("error_not_a_post_request")) else: messages.warning(request, DisplayKey.get("error_not_ajax_request")) return HttpResponseRedirect("../Home")
def validateLogin(request): if request.method == 'POST': form_data = FORM_LoginDetails(request.POST) if form_data.is_valid(): username = form_data.cleaned_data.get("username") password = form_data.cleaned_data.get("password") lh = LoginHelper(request) userId = lh.getUserIdAfterAuthentication(username, password) if (userId == None): messages.error(request, DisplayKey.get("invalid_credentials")) return index(request) else: user = EN_Users.objects.get(id=userId) if user.account_status.code == "active": request.session[SessionProperties.USER_ID_KEY] = userId lh.updateOnlineStatusAndLoggedInTime() lh.setStaticUIData() lh.setActiveRole() UserRolesHelper(request).updateRolesOnSession() return HttpResponseRedirect("../../Home") else: if user.account_status.code == "inactive": user.activation_token = uuid4() user.save() template_data = { "url": "{}/SignUp/ActivateAccount".format( request.get_host()), "name": user.name, "token": user.activation_token, "product_id": user.product_id, } try: Email().sendEmail( template=EmailTemplates. ACCOUNT_ACTIVATION_EMAIL, subject="Activate Wokidz Account", recipient_list=[user.contact.email_id], template_data=template_data) messages.warning( request, "Your account inactive. Click on the activation link send to your email id" ) except Exception as e: messages.error( request, "Failed to send activation email | Contact site admin" ) else: messages.warning( request, "Your account status is {}. Please reach out to Wokidz support team." .format(user.account_status.name)) return HttpResponseRedirect("../Login") else: return index(request) else: messages.error(request, DisplayKey.get("direct_access_denied")) return HttpResponseRedirect("Login")
def clean(self): data = self.cleaned_data prdIdListString = (data["product_ids"].replace(" ", "")).strip() if (re.match('^[MY0-9,]+$',prdIdListString) == None): self.add_error("product_ids", DisplayKey.get("invalid_characters_in_product_id_list")) return data
def saveSubject(request): if request.is_ajax(): if request.method == 'POST': subject_name = request.POST.get("subject_name") subject_duration = request.POST.get("subject_duration") tag = request.POST.get("subject_tag") classes_assigned = request.POST.get("classes_assigned") selected_books_id = request.POST.get("selected_books_id") status = True message = "" userRole = EN_UserRoles.objects.filter( approved=True, is_selected_role=True, role__code=Roles.SCHOOL_ADMIN) if (userRole.exists()): userRole = userRole.first() organization = userRole.related_organization #Validating Classes for cls in classes_assigned.split(","): try: cls = EN_Classes.objects.filter(id=int(cls)) if not cls.exists(): raise Exception("Class {}-{} doesnot exist".format( cls.first().class_name, cls.first().class_division)) elif cls.first().organization.id != organization.id: raise Exception( "Class {}-{} doesnot belong to the organization where your current role is set to" .format(cls.first().class_name, cls.first().class_division)) except Exception as e: status = False message = e.__str__() break #Validating Books for book in selected_books_id.split(","): try: EN_Books.objects.get(id=int(book)) except Exception as e: status = False message = e.__str__() break if status: subjectObj = EN_Subjects() subjectObj.subject_name = subject_name subjectObj.tag = tag try: subjectObj.duration = int( subject_duration ) if subject_duration != None or subject_duration != "" else None except: subjectObj.duration = None subjectObj.organization = organization subjectObj.save() for cls in classes_assigned.split(","): cs = EN_ClassSubjects() cs.subject = subjectObj cs.class_fk_id = int(cls) cs.organization = organization cs.save() for book_id in selected_books_id.split(","): sb = EN_SubjectBooks() sb.book_id = int(book_id) sb.organization = organization sb.subject = subjectObj sb.save() message = "Subjects Saved Successfully" else: status = False message = "Selected Roles does not have permission to perform this action" return HttpResponse( json.dumps({ "status": status, "message": message })) else: messages.warning(request, DisplayKey.get("error_not_a_post_request")) return HttpResponseRedirect("../Home") else: messages.warning(request, DisplayKey.get("error_not_ajax_request")) return HttpResponseRedirect("../Home")
def saveAssignedRole(request): if request.is_ajax(): if request.method == "POST": retDict = {"status": False, "message": None} ids = request.POST["ids"] selected_role = TL_Roles.objects.get( code=request.POST["selected_role"]) user_id = request.session[SessionProperties.USER_ID_KEY] accepted_user_list = [ Roles.INSTITUTION_SUPER_USER, Roles.SCHOOL_ADMIN, Roles.TEACHER ] active_role = EN_UserRoles.objects.filter( approved=True, user_id=user_id, role__code__in=accepted_user_list, is_selected_role=True) notifyHelper = NotificationHelper(request) if active_role.exists(): active_role = active_role.first() approved = (active_role.role.code in [ Roles.INSTITUTION_SUPER_USER, Roles.SCHOOL_ADMIN ]) idList = [int(s) for s in (ids.strip()).split(',')] for user in EN_Users.objects.filter(id__in=idList): userRole = EN_UserRoles() userRole.user = user userRole.role = selected_role userRole.approved = approved userRole.request_raised_by_id = user_id userRole.request_raised_on = datetime.datetime.now() if ((selected_role.code in [ Roles.INSTITUTION_SUPER_USER, Roles.DIRECTOR, Roles.BOARD_MEMBER ]) and (active_role.role.code in [Roles.INSTITUTION_SUPER_USER])): userRole.related_organization_group = active_role.related_organization_group userRole.request_approved_by_id = user_id userRole.request_approved_on = datetime.datetime.now() try: userRole.validate_unique() userRole.save() notifyHelper.notify( recipient_id=user.id, type=NotificationTypes.NEW_ROLE_ADDED) retDict["status"] = True except Exception as e: retDict["message"] = e.__str__() #---- SCHOOL ADMIN---------------------- elif ((selected_role.code in [Roles.SCHOOL_ADMIN]) and (active_role.role.code in [ Roles.INSTITUTION_SUPER_USER, Roles.SCHOOL_ADMIN ])): selected_organization = EN_Organization.objects.filter( id=int(request.POST["organization_id"])) if selected_organization.exists(): selected_organization = selected_organization.first( ) if active_role.related_organization_group.id == selected_organization.organization_group.id: userRole.related_organization = selected_organization userRole.request_approved_by_id = user_id userRole.request_approved_on = datetime.datetime.now( ) userRole.validate_unique() try: userRole.save() notifyHelper.notify( recipient_id=user.id, type=NotificationTypes.NEW_ROLE_ADDED) retDict["status"] = True except Exception as e: retDict["message"] = e.__str__() else: retDict["message"] = DisplayKey.get( "current_role_have_no_privilage_on_selected_organization" ) else: retDict["message"] = DisplayKey.get( "invalid_organization_id") # ---- ALL SCHOOL LEVEL ROLES FROM SCHOOL ADMIN ---------------------- elif ((selected_role.code in [ Roles.PRINCIPAL, Roles.TEACHER, Roles.STUDENT, Roles.PARENT, Roles.LIBRARIAN, Roles.ACCOUNTANT, Roles.LAB_ASSISTANT, Roles.ENQUIRY_ASSISTANT, Roles.SECURITY ]) and (active_role.role.code in [Roles.SCHOOL_ADMIN])): if selected_role.code == Roles.PARENT: selected_student = EN_Users.objects.filter( id=int(request.POST["student_id"])) if selected_student.exists(): selected_student_role = EN_UserRoles.objects.filter( approved=True, related_organization=active_role. related_organization, role__code=Roles.STUDENT) if selected_student_role.exists(): userRole.related_user = selected_student.first( ) userRole.related_organization = active_role.related_organization userRole.request_approved_by_id = user_id userRole.request_approved_on = datetime.datetime.now() try: userRole.validate_unique() userRole.save() notifyHelper.notify( recipient_id=user.id, type=NotificationTypes.NEW_ROLE_ADDED) retDict["status"] = True except Exception as e: retDict["message"] = e.__str__() # ---- STUDENT REQUEST FROM TEACHER---------------------- elif ((selected_role.code in [Roles.STUDENT]) and (active_role.role.code in [Roles.TEACHER])): userRole.related_organization = active_role.related_organization try: userRole.validate_unique() userRole.save() approvers = EN_UserRoles.objects.filter( approved=True, related_organization=active_role. related_organization, role__code=Roles.SCHOOL_ADMIN) if approvers.exists(): for approver in approvers: notifyHelper.notify( recipient_id=approver.id, type=NotificationTypes. ROLE_APPROVAL_REQUEST_RECEIVED, change_read_status_direclty=False) retDict["status"] = True else: userRole.delete() retDict["message"] = DisplayKey.get( "no_approvers_found_for_this_organization") except Exception as e: retDict["message"] = e.__str__() elif ((selected_role.code in [Roles.PARENT]) and (active_role.role.code in [Roles.TEACHER])): selected_student = EN_Users.objects.filter( id=int(request.POST["student_id"])) if selected_student.exists(): selected_student_role = EN_UserRoles.objects.filter( approved=True, related_organization=active_role. related_organization, role__code=Roles.STUDENT) if selected_student_role.exists(): userRole.related_organization = active_role.related_organization userRole.related_user = selected_student.first( ) try: userRole.validate_unique() userRole.save() approvers = EN_UserRoles.objects.filter( approved=True, related_organization=active_role. related_organization, role__code=Roles.SCHOOL_ADMIN) if approvers.exists(): for approver in approvers: notifyHelper.notify( recipient_id=approver.id, type=NotificationTypes. ROLE_APPROVAL_REQUEST_RECEIVED, change_read_status_direclty= False) retDict["status"] = True else: userRole.delete() retDict["message"] = DisplayKey.get( "no_approvers_found_for_this_organization" ) except Exception as e: retDict["message"] = e.__str__() else: retDict["message"] = DisplayKey.get( "selected_student_does_not_belong_to_your_school" ) else: retDict["message"] = DisplayKey.get( "student_not_found") else: retDict["message"] = DisplayKey.get( "selected_role_lacks_permission_to_send_or_approve_role_request" ) else: retDict["message"] = DisplayKey.get( "selected_role_lacks_permission_to_send_or_approve_role_request" ) if retDict["status"] == True and selected_role.code != Roles.PARENT: messages.success(request, DisplayKey.get("role_raised_successfully")) return HttpResponse(json.dumps(retDict)) else: messages.warning(request, DisplayKey.get("error_not_a_post_request")) return HttpResponseRedirect("../Home") else: return HttpResponseRedirect("../Redirects/ErrorPage?page=404")
def validateAssignedRole(request): if request.method == "POST": user_id = request.session[SessionProperties.USER_ID_KEY] accepted_user_list = [ Roles.INSTITUTION_SUPER_USER, Roles.SCHOOL_ADMIN, Roles.TEACHER ] ur = EN_UserRoles.objects.filter(approved=True, user_id=user_id, role__code__in=accepted_user_list, is_selected_role=True) if ur.exists(): ur = ur[0] form_data = FORM_UserRoleAssignment(request.POST) try: selected_role = TL_Roles.objects.get( code=request.POST["role_selected"]) except: messages.error(request, "Invalid Role Selected") return loadRoleSettingPage(request) str = form_data["product_ids"].data prdIdListString = (str.replace(" ", "")).strip() productIdList = list(prdIdListString.split(",")) users = EN_Users.objects.filter(product_id__in=productIdList) retList = [] prodComparisonList = [] active_role = EN_UserRoles.objects.filter( approved=True, user_id=user_id, role__code__in=accepted_user_list, is_selected_role=True) if active_role.exists(): active_role = active_role.first() else: messages.error( request, DisplayKey.get( "selected_role_lacks_permission_to_send_or_approve_role_request" )) return loadRoleSettingPage(request) students_not_of_this_org = [] for user in users: if selected_role.code == Roles.PARENT: ur = EN_UserRoles.objects.filter( approved=True, related_organization=active_role.related_organization, user=user, role__code=Roles.STUDENT) if not ur.exists(): students_not_of_this_org.append(user.product_id) if students_not_of_this_org.__len__() > 0: messages.error( request, "User(s) {} are not approved students of {}".format( list(students_not_of_this_org).__str__(), active_role.related_organization.school_name)) return loadRoleSettingPage(request) for user in users: addr = EN_AddressBook.objects.get(user=user, is_permanent_address=True) permanent_adr = addr.house_name + ", " + addr.street retDict = { "id": user.id, "name": user.name, "gender": user.gender.code, "contact_no": user.contact.mobile_number, "address": permanent_adr, "dp": user.display_picture, "product_id": user.product_id } prodComparisonList.append(user.product_id) retList.append(retDict) diff = set(productIdList) - set(prodComparisonList) if diff.__len__() > 0: messages.warning( request, "Invalid Wokidz IDs found : {}".format( (", ".join(diff)))) return loadRoleSettingPage(request) data = UIDataHelper(request).getData(page="is_raise_role_request") data.__setitem__( "organization_id", 0 if "organization_id" not in request.POST else request.POST["organization_id"]) data.__setitem__("selected_role", selected_role.code) try: data.__setitem__("my_role", ur.role.code) except: data.__setitem__("my_role", ur[0].role.code) data.__setitem__("user_list", retList) template = "roles_parent_role_page.html" if selected_role.code == Roles.PARENT else "roles_user_list_page.html" template = loader.get_template(template) return HttpResponse(template.render(data, request)) else: return loadRoleSettingPage(request) else: messages.warning(request, DisplayKey.get("error_not_a_post_request")) return HttpResponseRedirect("../Home")
def index(request): data = UIDataHelper(request).getData(page="is_list_all_subjects") user_id = request.session[SessionProperties.USER_ID_KEY] user_role = EN_UserRoles.objects.filter(approved=True, user_id=user_id, is_selected_role=True) if user_role.exists(): user_role = user_role.first() classes = EN_Classes.objects.filter( organization=user_role.related_organization) teachers = EN_UserRoles.objects.filter( related_organization=user_role.related_organization, role__code=Roles.TEACHER, approved=True) if not teachers.exists(): messages.warning(request, "No Teachers added to this Organization.") teacherList = None else: teacherList = [ { "id": teacher.id, #setting role_id, not user_id "name": teacher.user.name + " [" + teacher.user.product_id + "]" } for teacher in teachers ] data.__setitem__("teachersList", teacherList) if request.method == "POST": if "class_names" in request.POST and "class_div" in request.POST: filter_class = request.POST["class_names"] filter_div = request.POST["class_div"] if filter_class != "all" and filter_div == "all": classes = classes.filter(class_name=filter_class) elif filter_class == "all" and filter_div != "all": classes = classes.filter(class_division=filter_div) elif filter_class != "all" and filter_div != "all": classes = classes.filter(class_name=filter_class, class_division=filter_div) if not classes.exists(): messages.error( request, "The given combination of class and division does not exist" ) dataList = None dataList = [{ "id": cs.subject.id, "name": cs.subject.subject_name, "duration": cs.subject.duration, "assigned_to_class": cs.class_fk.class_name + "-" + cs.class_fk.class_division } for cs in EN_ClassSubjects.objects.filter(class_fk__in=list(classes)) ] data.__setitem__("subjects", dataList) fd_classes = FORM_ClassNamesForSubject( request.POST, request=request ) if request.method == "POST" else FORM_ClassNamesForSubject( request=request) data.__setitem__("class_names", fd_classes) template = loader.get_template("sub_list_all_subjects.html") return HttpResponse(template.render(data, request)) else: messages.warning( request, DisplayKey.get("current_role_cannot_perform_this_action")) return HttpResponseRedirect("../Home")