Exemplo n.º 1
0
def getStudentByFilterInfoId(request):
    teacherid = utils.getCookie(request, "teacherid")
    if (teacherid is None) or teacherid == "":
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    filterid = utils.getParam(request, "filterid")
    if (filterid == "" or filterid is None):
        responseReturn = Response(-1, "请选择班级!")
        return HttpResponse(responseReturn.__str__())
    filterinfo = FilterInfoService.getFilterInfoById(filterid)
    if filterinfo is None:
        responseReturn = Response(-1, "班级不存在!")
        return HttpResponse(responseReturn.__str__())
    studentList = StudentService.getStudentListByFilterInfo(filterid)
    if studentList is None:
        responseReturn = Response(-1, "此班级没有学生!")
        return HttpResponse(responseReturn.__str__())
    studentDictList = []
    for student in studentList:
        dict = model_to_dict(student)
        del dict["isdelete"]
        del dict["createtime"]
        del dict["updatetime"]
        dict["registyear"] = filterinfo.registyear
        dict["major"] = filterinfo.major
        dict["classname"] = filterinfo.classname
        studentDictList.append(dict)
    studentDictListStr = json.dumps(studentDictList, ensure_ascii=False)
    responseReturn = Response(None, None)
    responseReturn.setRes(studentDictListStr)
    return HttpResponse(responseReturn.__str__())
Exemplo n.º 2
0
def uploadVideo(request):
    teacherid = utils.getCookie(request, "teacherid")
    if (teacherid is None) or teacherid == "":
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    experimentid = utils.getParam(request, "experimentid")
    file = request.FILES.get('file', None)
    name = utils.getParam(request, "name")
    if experimentid == "":
        responseReturn = Response(-1, "请选择实验!")
        return HttpResponse(responseReturn.__str__())
    if file is None:
        responseReturn = Response(-1, "上传文件为空!")
        return HttpResponse(responseReturn.__str__())
    filename = file.name
    filesuffix = os.path.splitext(filename)[1]
    if filesuffix != ".mp4" and filesuffix != ".rmvb":
        responseReturn = Response(-1, "视屏格式应为MP4、rmvb!")
        return HttpResponse(responseReturn.__str__())
    filename = str(uuid.uuid1()) + filesuffix
    fp = open(os.path.join(CONSTANTS.EXPERIMENTVIDEOURL_PRE, filename), 'wb+')
    for chunk in file.chunks():  # 分块写入文件
        fp.write(chunk)
    fp.close()
    videoid = VideoService.saveVideo(name, filename, experimentid)
    if videoid is None:
        responseReturn = Response(-1, "上传失败,请重试!")
        return HttpResponse(responseReturn.__str__())
    video = {"id": videoid, "name": name, "url": filename}
    responseReturn = Response(None, None)
    responseReturn.setRes(json.dumps(video))
    return HttpResponse(responseReturn.__str__())