def login_redirect(request,identity): """ When the user login, it will decide to jump the according page, in other words, school user will be imported /school/ page, if the user have many authorities, the system will jump randomly """ #TODO: I will use reverse function to redirect, like school and expert loginfo(identity) if identity == "adminUser": if check_auth(request.user,ADMINSTAFF_USER): identity = ADMINSTAFF_USER elif check_auth(request.user,FINANCE_USER): identity = FINANCE_USER elif check_auth(request.user,SCHOOL_USER): identity = SCHOOL_USER else: logout(request) return render_to_response('registration/logentry_error.html', context_instance=RequestContext(request)) elif check_auth(request.user,identity): loginfo(request.user) pass else: try: del request.session['auth_role'] except: pass logout(request) return render_to_response('registration/logentry_error.html', context_instance=RequestContext(request)) redirect_url = '/'+identity+'/' request.session['auth_role'] = identity loginfo(redirect_url) return HttpResponseRedirect(redirect_url)
def login_redirect(request, identity): """ When the user login, it will decide to jump the according page, in other words, school user will be imported /school/ page, if the user have many authorities, the system will jump randomly """ #TODO: I will use reverse function to redirect, like school and expert loginfo(identity) if identity == "adminUser": if check_auth(request.user, ADMINSTAFF_USER): identity = ADMINSTAFF_USER elif check_auth(request.user, FINANCE_USER): identity = FINANCE_USER elif check_auth(request.user, SCHOOL_USER): identity = SCHOOL_USER else: logout(request) return render_to_response('registration/logentry_error.html', context_instance=RequestContext(request)) elif check_auth(request.user, identity): loginfo(request.user) pass else: try: del request.session['auth_role'] except: pass logout(request) return render_to_response('registration/logentry_error.html', context_instance=RequestContext(request)) redirect_url = '/' + identity + '/' request.session['auth_role'] = identity loginfo(redirect_url) return HttpResponseRedirect(redirect_url)
def login_redirect(request): """ When the user login, it will decide to jump the according page, in other words, school user will be imported /school/ page, if the user have many authorities, the system will jump randomly """ #TODO: I will use reverse function to redirect, like school and expert if check_auth(request.user, ADMINSTAFF_USER): return HttpResponseRedirect('/admin/') elif check_auth(request.user, NORMAL_USER): return HttpResponseRedirect('/normal/') elif check_auth(request.user, VISITOR_USER): return HttpResponseRedirect('/') else: return HttpResponseRedirect('/')
def checkCanAddMember(request, icard): if check_auth(request.user, TEACHER_USER): if TeacherProfile.objects.get( userid=request.user).teacherinfosetting.card == icard: return False #检查是否把自己加入团队列表 try: teacherInfo = TeacherInfoSetting.objects.get(card=icard) pro = ProjectSingle.objects.filter( Q(teacher=teacherInfo.teacher) & Q(project_status__status__lt=PROJECT_STATUS_OVER)) except: pro = ProjectSingle.objects.none() member = ProjectMember.objects.filter( Q(card=icard) & Q(project__project_status__status__lt=PROJECT_STATUS_OVER)) if member.count() + pro.count() < 3: # 每年申报最多3个 print member.count() + pro.count() return True else: for item in member: print item.project print "" for item in pro: print item return False
def searchStudent(request, search_value): students = StudentProfile.objects.filter(Q(baseinfo_name = search_value) | Q(baseinfo_studentid = search_value)) if check_auth(request.user, TEACHER_USER): teacher = TeacherProfile.objects.get(userid = request.user) students = students.filter(small_class = teacher.small_class) context = getContext(students, 1, "item", 0) return render_to_string("teacher/widgets/student_set_table.html", context)
def login_redirect(request, identity): """ When the user login, it will decide to jump the according page, in other words, school user will be imported /school/ page, if the user have many authorities, the system will jump randomly """ #TODO: I will use reverse function to redirect, like school and expert loginfo(identity) if check_auth(request.user, identity): loginfo(request.user) pass else: try: del request.session['auth_role'] except: pass logout(request) return HttpResponseRedirect('/identityerror') if identity == ADMINSTAFF_USER: redirect_url = '/' + identity + '/' + "studentmanage" else: redirect_url = '/' + identity + '/' + "homepage" request.session['auth_role'] = identity return HttpResponseRedirect(redirect_url)
def login_redirect(request,identity): """ When the user login, it will decide to jump the according page, in other words, school user will be imported /school/ page, if the user have many authorities, the system will jump randomly """ #TODO: I will use reverse function to redirect, like school and expert loginfo(identity) if check_auth(request.user,identity): loginfo(request.user) pass else: try: del request.session['auth_role'] except: pass logout(request) return HttpResponseRedirect('/identityerror') if identity==ADMINSTAFF_USER: redirect_url = '/'+identity+'/'+"studentmanage" else: redirect_url = '/'+identity+'/'+"homepage" request.session['auth_role'] = identity return HttpResponseRedirect(redirect_url)
def userauth_settings(request): """ The context processor will add user authorities variables into all template """ loginfo(request.META['HTTP_USER_AGENT']) userauth = { "is_adminstaff": False, "is_schooler": False, "is_colleger":False, "is_experter": False, "is_teacher": False, "is_finance":False, } auth_choices= { "adminStaff":ADMINSTAFF_USER, "school":SCHOOL_USER, "college":COLLEGE_USER, "teacher":TEACHER_USER, "expert":EXPERT_USER, "finance":FINANCE_USER, } identity = request.session.get('auth_role', "") userauth["user"]=identity if identity == ADMINSTAFF_USER and check_auth(user=request.user, authority=ADMINSTAFF_USER): userauth["is_adminstaff"] = True try: userauth["adminstaff"] = AdminStaffProfile.objects.get(userid=request.user) except AdminStaffProfile.DoesNotExist, err: loginfo(p=err, label="context AdminStaffProfile")
def searchStudent(request, search_value): students = StudentProfile.objects.filter( Q(baseinfo_name=search_value) | Q(baseinfo_studentid=search_value)) if check_auth(request.user, TEACHER_USER): teacher = TeacherProfile.objects.get(userid=request.user) students = students.filter(small_class=teacher.small_class) context = getContext(students, 1, "item", 0) return render_to_string("teacher/widgets/student_set_table.html", context)
def identity_redirect(request): """ Redirect user based on identity. Author: David """ if check_auth(request.user, ADMINSTAFF_USER): return HttpResponseRedirect('/adminStaff/') elif check_auth(request.user, SCHOOL_USER): return HttpResponseRedirect(reverse('school.views.home_view')) elif check_auth(request.user, EXPERT_USER): return HttpResponseRedirect(reverse('expert.views.home_view')) elif check_auth(request.user, STUDENT_USER): return HttpResponseRedirect(reverse('school.views.student_view')) else: logout(request) return render_to_response('registration/logentry_error.html', context_instance=RequestContext(request))
def studentlogin_redirect(request): """ When the user login, it will decide to jump the according page, in other words, school user will be imported /school/ page, if the user have many authorities, the system will jump randomly """ if check_auth(request.user, STUDENT_USER): return HttpResponseRedirect(reverse('school.views.student_view')) else: logout(request) return render_to_response('registration/logentry_error.html', context_instance=RequestContext(request))
def provincelogin_redirect(request): """ When the user login, it will decide to jump the according page, in other words, school user will be imported /school/ page, if the user have many authorities, the system will jump randomly """ if check_auth(request.user, ADMINSTAFF_USER): return HttpResponseRedirect('/adminStaff/') else: logout(request) return render_to_response('registration/logentry_error.html', context_instance=RequestContext(request))
def getStudentList(request, year, page_numbers, cls, page): page = int(page) page_numbers = int(page_numbers) students = StudentProfile.objects.all() if year != "-1": students = students.filter(innovation_grade = year) if check_auth(request.user, TEACHER_USER): teacher = TeacherProfile.objects.get(userid = request.user) students = students.filter(small_class = teacher.small_class) elif cls != "-1": students = students.filter(small_class__practice_class__userid__username = cls) context = getContext(students, page, "item", 0, page_numbers) return render_to_string("teacher/widgets/student_set_table.html", context)
def checkCanAddMember(request,icard): if check_auth(request.user,TEACHER_USER): if TeacherProfile.objects.get(userid=request.user).teacherinfosetting.card == icard: return False try: teacherInfo =TeacherInfoSetting.objects.get(card=icard) pro = ProjectSingle.objects.filter(Q(teacher=teacherInfo.teacher) & Q(project_status__status__lt =PROJECT_STATUS_OVER)) except: pro = ProjectSingle.objects.none() member = ProjectMember.objects.filter(card = icard) if member.count() + pro.count() < 3: return True else: return False
def getStudentList(request, year, page_numbers, cls, page): page = int(page) page_numbers = int(page_numbers) students = StudentProfile.objects.all() if year != "-1": students = students.filter(innovation_grade=year) if check_auth(request.user, TEACHER_USER): teacher = TeacherProfile.objects.get(userid=request.user) students = students.filter(small_class=teacher.small_class) elif cls != "-1": students = students.filter( small_class__practice_class__userid__username=cls) context = getContext(students, page, "item", 0, page_numbers) return render_to_string("teacher/widgets/student_set_table.html", context)
def userauth_settings(request): """ The context processor will add user authorities variables into all template """ userauth = {"is_schooler": False, "is_adminstaff": False, "is_experter": False } if check_auth(user=request.user, authority=SCHOOL_USER): userauth["is_schooler"] = True try: userauth["school"] = SchoolProfile.objects.get(userid=request.user) except SchoolProfile.DoesNotExist, err: loginfo(p=err, label="context SchoolProfile")
def checkCanAddMember(request, icard): if check_auth(request.user, TEACHER_USER): if TeacherProfile.objects.get( userid=request.user).teacherinfosetting.card == icard: return False try: teacherInfo = TeacherInfoSetting.objects.get(card=icard) pro = ProjectSingle.objects.filter( Q(teacher=teacherInfo.teacher) & Q(project_status__status__lt=PROJECT_STATUS_OVER)) except: pro = ProjectSingle.objects.none() member = ProjectMember.objects.filter(card=icard) if member.count() + pro.count() < 3: return True else: return False
def userauth_settings(request): """ The context processor will add user authorities variables into all template """ userauth = { "is_schooler": False, "is_adminstaff": False, "is_experter": False } if check_auth(user=request.user, authority=SCHOOL_USER): userauth["is_schooler"] = True try: userauth["school"] = SchoolProfile.objects.get(userid=request.user) except SchoolProfile.DoesNotExist, err: loginfo(p=err, label="context SchoolProfile")
def getCourseList(request, year, term, grade, page_numbers, cls, page): try: print "ddddddddddd" page = int(page) page_numbers = int(page_numbers) courses = Course.objects.all() if year != "-1": courses = courses.filter(start_year = year) if term != "-1": courses = courses.filter(course_id__course_term = term) if grade != "-1": courses = courses.filter(course_id__course_grade = grade) if check_auth(request.user, TEACHER_USER): teacher = TeacherProfile.objects.get(userid = request.user) courses = courses.filter(teacher = teacher) elif cls != "-1": courses = courses.filter(course_id__course_practice__userid__username = cls) context = getContext(courses, page, "item", 1, page_numbers) html = render_to_string("teacher/widgets/course_set_table.html", context) except Exception,e: print "aaaaaaaaa"
def getCourseList(request, year, term, grade, page_numbers, cls, page): try: print "ddddddddddd" page = int(page) page_numbers = int(page_numbers) courses = Course.objects.all() if year != "-1": courses = courses.filter(start_year=year) if term != "-1": courses = courses.filter(course_id__course_term=term) if grade != "-1": courses = courses.filter(course_id__course_grade=grade) if check_auth(request.user, TEACHER_USER): teacher = TeacherProfile.objects.get(userid=request.user) courses = courses.filter(teacher=teacher) elif cls != "-1": courses = courses.filter( course_id__course_practice__userid__username=cls) context = getContext(courses, page, "item", 1, page_numbers) html = render_to_string("teacher/widgets/course_set_table.html", context) except Exception, e: print "aaaaaaaaa"
The context processor will add user authorities variables into all template """ userauth = {"is_schooler": False, "is_adminstaff": False, "is_experter": False } if check_auth(user=request.user, authority=SCHOOL_USER): userauth["is_schooler"] = True try: userauth["school"] = SchoolProfile.objects.get(userid=request.user) except SchoolProfile.DoesNotExist, err: loginfo(p=err, label="context SchoolProfile") if check_auth(user=request.user, authority=STUDENT_USER): loginfo(p="*"*20) userauth["is_student"] = True try: userauth["student"] = StudentProfile.objects.get(user=request.user) except StudentProfile.DoesNotExist, err: loginfo(p=err, label="context StudentProfile") if check_auth(user=request.user, authority=ADMINSTAFF_USER): userauth["is_adminstaff"] = True try: userauth["adminstaff"] = AdminStaffProfile.objects.get(userid=request.user) except AdminStaffProfile.DoesNotExist, err: loginfo(p=err, label="context AdminStaffProfile") if check_auth(user=request.user, authority=EXPERT_USER):
into all template """ userauth = { "is_schooler": False, "is_adminstaff": False, "is_experter": False } if check_auth(user=request.user, authority=SCHOOL_USER): userauth["is_schooler"] = True try: userauth["school"] = SchoolProfile.objects.get(userid=request.user) except SchoolProfile.DoesNotExist, err: loginfo(p=err, label="context SchoolProfile") if check_auth(user=request.user, authority=STUDENT_USER): loginfo(p="*" * 20) userauth["is_student"] = True try: userauth["student"] = StudentProfile.objects.get(user=request.user) except StudentProfile.DoesNotExist, err: loginfo(p=err, label="context StudentProfile") if check_auth(user=request.user, authority=ADMINSTAFF_USER): userauth["is_adminstaff"] = True try: userauth["adminstaff"] = AdminStaffProfile.objects.get( userid=request.user) except AdminStaffProfile.DoesNotExist, err: loginfo(p=err, label="context AdminStaffProfile")
"adminStaff":ADMINSTAFF_USER, "school":SCHOOL_USER, "college":COLLEGE_USER, "teacher":TEACHER_USER, "expert":EXPERT_USER, "finance":FINANCE_USER, } identity = request.session.get('auth_role', "") userauth["user"]=identity if identity == ADMINSTAFF_USER and check_auth(user=request.user, authority=ADMINSTAFF_USER): userauth["is_adminstaff"] = True try: userauth["adminstaff"] = AdminStaffProfile.objects.get(userid=request.user) except AdminStaffProfile.DoesNotExist, err: loginfo(p=err, label="context AdminStaffProfile") if identity == FINANCE_USER and check_auth(user=request.user, authority=FINANCE_USER): userauth["is_finance"] = True try: userauth["finance"] = FinanceProfile.objects.get(userid=request.user) except FinanceProfile.DoesNotExist, err: loginfo(p=err, label="context FinanceProfile") if identity == SCHOOL_USER and check_auth(user=request.user, authority=SCHOOL_USER): userauth["is_schooler"] = True try: userauth["school"] = SchoolProfile.objects.get(userid=request.user) except SchoolProfile.DoesNotExist, err: loginfo(p=err, label="context SchoolProfile") if identity == COLLEGE_USER and check_auth(user=request.user, authority=COLLEGE_USER): userauth["is_colleger"] = True try: