Пример #1
0
def findById(req, id):
    if not is_login(req):
        return HttpResponseNotAllowed()
    service=StuService()
    data={'code': 200}
    data['data'] = dict(service.findById(id))
    return HttpResponse(json.dumps(data))
Пример #2
0
def findById(req, id):
    if not is_login(req):
        return HttpResponseNotAllowed()
    service = StuService()
    data = {'code': 200}
    data['data'] = dict(service.findById(id))
    return HttpResponse(json.dumps(data))
Пример #3
0
def delete(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()
    id = req.POST.get('id')
    service = StuService()
    service.delete(id)
    return HttpResponse(json.dumps({'code': 200}))
Пример #4
0
def delete(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()
    id = req.POST.get('id')
    service=StuService()
    service.delete(id)
    return HttpResponse(json.dumps({'code': 200}))
Пример #5
0
def all(req):
    if not is_login(req):
        return HttpResponseNotAllowed()
    techerId = None
    if 'tech' == req.session['utype']:
        techerId = req.session['id']
    service = StuService()
    data = {'code': 200}

    data['data'] = list(service.list(techerId))
    return HttpResponse(json.dumps(data))
Пример #6
0
def all(req):
    if not is_login(req):
        return HttpResponseNotAllowed()
    techerId=None
    if 'tech' == req.session['utype']:
        techerId = req.session['id']
    service=StuService()
    data={'code': 200}
    
    data['data'] = list(service.list(techerId))
    return HttpResponse(json.dumps(data))
Пример #7
0
def query(req):
    if not is_login(req):
        return HttpResponseNotAllowed()
    techerId = None
    if 'tech' == req.session['utype']:
        techerId = req.session['id']
    name = req.GET.get('name')
    value = req.GET.get('value')
    service = StuService()
    data = {'code': 200}
    data['data'] = list(service.query(name, value, techerId))
    return HttpResponse(json.dumps(data))
Пример #8
0
def query(req):
    if not is_login(req):
        return HttpResponseNotAllowed()
    techerId=None
    if 'tech' == req.session['utype']:
        techerId = req.session['id']
    name=req.GET.get('name')
    value=req.GET.get('value')
    service=StuService()
    data={'code': 200}
    data['data'] = list(service.query(name, value, techerId))
    return HttpResponse(json.dumps(data))
Пример #9
0
def stu_login(req, uname, pw, utype):
    service = StuService()
    rs = service.findByNumber(uname)
    if rs is None:
        return HttpResponse(json.dumps({"code": 400, "message": error_msg1}))
    elif rs.password != pw:
        return HttpResponse(json.dumps({"code": 400, "message": error_msg2}))
    else:
        req.session["uname"] = uname
        req.session["utype"] = utype
        req.session["id"] = rs.id
        req.session["name"] = rs.name
        return HttpResponse(json.dumps({"code": 200}))
Пример #10
0
def save(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()
    service = StuService()
    service.save(name=req.POST.get('name'),
                 sex=req.POST.get('sex'),
                 age=req.POST.get('age'),
                 register=req.POST.get('register'),
                 baseUnit=req.POST.get('baseUnit'),
                 techerId=req.POST.get('techerId'),
                 techerNumber=req.POST.get('techerNumber'),
                 techerName=req.POST.get('techerName'))
    return HttpResponse(json.dumps({'code': 200}))
Пример #11
0
def grade(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()

    if 'stu' != req.session['utype']:
        return HttpResponseNotAllowed()

    answer_list = req.POST.get('answers').split(',')
    # print(req.POST.get('answers'))
    service=QuestionService()
    totalPoint = 0
    point = 0
    i = 0
    for idStr in req.POST.get('ids').split(','):
        q = service.findById(int(idStr))
        if q.rightAnswer == answer_list[i]:
            point = point + q.point
        totalPoint = totalPoint + q.point
        i = i+1
    
    c_service=CourseService()
    courseId = req.POST.get('courseId')
    course=c_service.findById(courseId)

    s_service=StuService()
    stuId = req.session['id']
    stu = s_service.findById(stuId)

    g_service=GradeService()
    g_service.save(
        totalPoint=totalPoint,
        point=point, 
        courseId=courseId, 
        courseName=course.name, 
        techerId=course.techerId, 
        techerNumber=course.techerNumber, 
        techerName=course.techerName,
        stuId=stuId, 
        stuNumber=stu.number,
        stuName=stu.name
    )
    return HttpResponse(json.dumps({'code': 200}))
Пример #12
0
def save(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()
    service=StuService()
    service.save(
        name=req.POST.get('name'), 
        sex=req.POST.get('sex'), 
        age=req.POST.get('age'), 
        register=req.POST.get('register'), 
        baseUnit=req.POST.get('baseUnit'),
        techerId=req.POST.get('techerId'),
        techerNumber=req.POST.get('techerNumber'),
        techerName=req.POST.get('techerName')
    )
    return HttpResponse(json.dumps({'code': 200}))
Пример #13
0
def grade(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()

    if 'stu' != req.session['utype']:
        return HttpResponseNotAllowed()

    answer_list = req.POST.get('answers').split(',')
    # print(req.POST.get('answers'))
    service = QuestionService()
    totalPoint = 0
    point = 0
    i = 0
    for idStr in req.POST.get('ids').split(','):
        q = service.findById(int(idStr))
        if q.rightAnswer == answer_list[i]:
            point = point + q.point
        totalPoint = totalPoint + q.point
        i = i + 1

    c_service = CourseService()
    courseId = req.POST.get('courseId')
    course = c_service.findById(courseId)

    s_service = StuService()
    stuId = req.session['id']
    stu = s_service.findById(stuId)

    g_service = GradeService()
    g_service.save(totalPoint=totalPoint,
                   point=point,
                   courseId=courseId,
                   courseName=course.name,
                   techerId=course.techerId,
                   techerNumber=course.techerNumber,
                   techerName=course.techerName,
                   stuId=stuId,
                   stuNumber=stu.number,
                   stuName=stu.name)
    return HttpResponse(json.dumps({'code': 200}))