示例#1
0
def all(req):
    if not is_login(req):
        return HttpResponseNotAllowed()
    service=TechService()
    data={'code': 200}
    data['data'] = list(service.list())
    return HttpResponse(json.dumps(data))
示例#2
0
def findById(req, id):
    if not is_login(req):
        return HttpResponseNotAllowed()
    service=TechService()
    data={'code': 200}
    data['data'] = dict(service.findById(id))
    return HttpResponse(json.dumps(data))
示例#3
0
def query(req):
    if not is_login(req):
        return HttpResponseNotAllowed()
    name=req.GET.get('name')
    value=req.GET.get('value')
    service=TechService()
    data={'code': 200}
    data['data'] = list(service.query(name, value))
    return HttpResponse(json.dumps(data))
示例#4
0
def delete(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()
    id = req.POST.get('id')
    service=TechService()
    service.delete(id)
    return HttpResponse(json.dumps({'code': 200}))
示例#5
0
文件: auth.py 项目: freshman88/aedu
def tech_login(req, uname, pw, utype):
    service = TechService()
    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}))
示例#6
0
def save(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()
    service=TechService()
    service.save(
        name=req.POST.get('name'), 
        sex=req.POST.get('sex'), 
        age=req.POST.get('age'), 
        techAge=req.POST.get('techAge'), 
        baseUnit=req.POST.get('baseUnit')
    )
    return HttpResponse(json.dumps({'code': 200}))
示例#7
0
def save(req):
    if req.method != 'POST':
        return HttpResponseNotFound()

    if not is_login(req):
        return HttpResponseNotAllowed()
    techerId=None
    if 'tech' == req.session['utype']:
        techerId = req.session['id']
        techer=TechService().findById(techerId)
        service=CourseService()
        service.save(
            name=req.POST.get('name'), 
            purpose=req.POST.get('purpose'), 
            techerId=techerId,
            techerNumber=techer['number'],
            techerName=techer['name']
        )
        return HttpResponse(json.dumps({'code': 200}))
    else:
        return HttpResponseNotAllowed()