Esempio n. 1
0
def saveuseredit(request):
    user=request.user
    if not checkUser(user) == 'manager':
        return HttpResponse(u'权限不足,禁止访问')
    if "fullname" in request.POST:
        name=request.POST["fullname"]
    if "studentid" in request.POST:
        id=request.POST["studentid"]
    if "sex" in request.POST:
        sex=request.POST["sex"]
    if "mobilephone" in request.POST:
        mobilephone=request.POST["mobilephone"]
    if "institute" in request.POST:
        institute=request.POST["institute"]
    if "major" in request.POST:
        major=request.POST["major"]
    if "description" in request.POST:
        description=request.POST["description"]
    if "status" in request.POST:
        status=request.POST["status"]
    username=request.user.username
    su=User.objects.filter(username=id)[0]

    student = Student.objects.filter(user=su)
    if student:
        student=student[0]
        student.description=description
        student.name=name
        student.sex=sex
        student.mobilephone=mobilephone
        student.major=major
        student.institute=institute
        student.save()

        stulist=Student.objects.all()
        role = "admin"
        return render_to_response("stulist.html",
                           { "username":username,
                              "role":role,
    			              "stulist" : stulist,
                           } ,
                            context_instance=RequestContext(request))  
    else:
        teacher = Teacher.objects.filter(user=su)[0]
        teacher.description=description
        teacher.name=name
        teacher.sex=sex
        teacher.mobilephone=mobilephone
        teacher.major=major
        teacher.institute=institute
        teacher.save()

        tealist=Teacher.objects.all()
        role = "admin"
        return render_to_response("tealist.html",
                           { "username":username,
                              "role":role,
                              "tealist" : tealist,
                           } ,
                            context_instance=RequestContext(request))  
Esempio n. 2
0
def addnewuser(request):
    user=request.user
    if not checkUser(user)=='manager':
        return HttpResponse(u'权限不足,禁止访问')
    if "fullname" in request.POST:
        name=request.POST["fullname"]
    if "studentid" in request.POST:
        id=request.POST["studentid"]
    if "sex" in request.POST:
        sex=request.POST["sex"]
    if "mobilephone" in request.POST:
        mobilephone=request.POST["mobilephone"]
    if "institute" in request.POST:
        institute=request.POST["institute"]
    if "major" in request.POST:
        major=request.POST["major"]
    if "description" in request.POST:
        description=request.POST["description"]
    if "status" in request.POST:
        status=request.POST["status"]
    username=request.user.username
    role = "admin"
    
    try:
        u=User(username=id)
        u.save()
        if status=="student":
            student = Student(user=u,description=description,name=name,sex=sex,mobilephone=mobilephone,major=major
                ,institute=institute)
            student.save()
            log = LogDetail(manager = request.user.manager,detail = u'添加学生'+id)
            log.save()
            stulist=Student.objects.all()
            
            return render_to_response("stulist.html",
                               { "username":username,
                                  "role":role,
                                  "stulist" : stulist,
                               } ,
                                context_instance=RequestContext(request))  
        else:
            teacher = Teacher(user=u,description=description,name=name,mobilephone=mobilephone,institute=institute)
            teacher.save()
            log = LogDetail(manager = request.user.manager,detail = u'添加教师'+id)
            log.save()
            tealist=Teacher.objects.all()
            
            return render_to_response("tealist.html",
                               { "username":username,
                                  "role":role,
                                  "tealist" : tealist,
                               } ,
                                context_instance=RequestContext(request))  
    except Exception:
        if status=="student":
            return render_to_response("newuser.html",
                           { "username":username,
                              "role":role,
                              "infomation":"the user exist!!!",
                           } ,
                            context_instance=RequestContext(request))
        else:
            return render_to_response("newtea.html",
                           { "username":username,
                              "role":role,
                              "infomation":"the user exist!!!",
                           } ,
                            context_instance=RequestContext(request))