Beispiel #1
0
def v_completedexp(request):
    stuid = utils.getCookie(request, "stuid")
    if (stuid is None) or stuid == "":
        return getloginResponse(request)
    stuname = utils.getCookie(request, "stuname")
    page = utils.getParam(request, "page")
    if (page is None) or page == "":
        page = 1
    else:
        page = int(page)
    count = TeachingService.getCountPageByStu(stuid, CONSTANTS.TEACHING_IS_STOP)
    countpage = 0
    i = 0
    if count > 0:
        if count % 10 > 0:
            i = 1
        countpage = count / 10 + i
    teachingRunList = TeachingService.getTeachingByStu(stuid, CONSTANTS.TEACHING_IS_STOP, page)
    experimentList = ExperimentService.getAllExperiment()
    # 获取用于菜单的实验列表
    experimentMenuList = []
    for experiment in experimentList:
        experimentTemp = experiment.copy()
        experimentName = experimentTemp["name"]
        if len(experimentName) > 8:
            experimentName = experimentName[0:10] + "..."
        experimentTemp["name"] = experimentName
        experimentMenuList.append(experimentTemp)

    teachingCount = getTeachingCount(stuid)
    return render(request, "completedexp.html",
                  {"teachingList": teachingRunList, "countpage": countpage, "experimentMenuList": experimentMenuList,
                   "experimentList": experimentList, "teachingCount": teachingCount, "stuname": stuname})
Beispiel #2
0
def updateTeachingTemplate(request):
    teacherid = utils.getCookie(request, "teacherid")
    if (teacherid is None) or teacherid == "":
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    teachingid = utils.getParam(request, "teachingid")
    experimentid = utils.getParam(request, "experimentid")
    file = request.FILES.get('file', None)
    if file is None:
        return HttpResponse(
            "<script>if(confirm('上传的文件为空')){history.go(-1);location.reload()}else{history.go(-1);location.reload()}</script>"
        )
    filename = file.name
    filesuffix = os.path.splitext(filename)[1]
    if filesuffix != ".doc" and filesuffix != ".docx":
        return HttpResponse(
            "<script>if(confirm('模板必须为word格式')){history.go(-1);location.reload()}else{history.go(-1);location.reload()}</script>"
        )
    filename = str(uuid.uuid1()) + filesuffix
    fp = open(os.path.join(CONSTANTS.TEMPLATEURL_PRE, filename), 'wb+')
    for chunk in file.chunks():  # 分块写入文件
        fp.write(chunk)
    fp.close()
    templateid = TemplateService.addTemplate(experimentid, filename)
    TeachingService.uploadTemplate(teachingid, templateid)
    return HttpResponse(
        "<script>if(confirm('上传成功')){history.go(-1);location.reload()}else{history.go(-1);location.reload()}</script>"
    )
Beispiel #3
0
def uploadData(request):
    teacherid = utils.getCookie(request, "teacherid")
    if (teacherid is None) or teacherid == "":
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    teachingid = utils.getParam(request, "teachingid")
    file = request.FILES.get('file', None)
    if file is None:
        return HttpResponse(
            "<script>if(confirm('上传的文件为空')){history.go(-1);location.reload()}else{history.go(-1);location.reload()}</script>"
        )
    filename = file.name
    filesuffix = os.path.splitext(filename)[1]
    if filesuffix != ".xsl" and filesuffix != ".xlsx":
        return HttpResponse(
            "<script>if(confirm('实验数据必须为excel')){history.go(-1);location.reload()}else{history.go(-1);location.reload()}</script>"
        )
    filename = str(uuid.uuid1()) + filesuffix
    fp = open(os.path.join(CONSTANTS.DATAURL_PRE, filename), 'wb+')
    for chunk in file.chunks():  # 分块写入文件
        fp.write(chunk)
    fp.close()
    TeachingService.uploadData(teachingid, filename)
    return HttpResponse(
        "<script>if(confirm('上传成功')){history.go(-1);location.reload()}else{history.go(-1);location.reload()}</script>"
    )
Beispiel #4
0
def getTeachingCount(teacherid):
    runCount = TeachingService.getCountPageByTea(teacherid,
                                                 CONSTANTS.TEACHING_IS_RUNNING)
    stopCount = TeachingService.getCountPageByTea(teacherid,
                                                  CONSTANTS.TEACHING_IS_STOP)
    teachingCount = {"runCount": runCount, "stopCount": stopCount}
    return teachingCount
Beispiel #5
0
def deleteTeachingByid(request):
    teacherid = utils.getCookie(request, "teacherid")
    if (teacherid is None) or teacherid == "":
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    teachingid = utils.getParam(request, "teachingid")
    TeachingService.deleteTeachingByid(teachingid)
    responseReturn = Response(None, None)
    return HttpResponse(responseReturn.__str__())
Beispiel #6
0
def updateTeachingDeadline(request):
    teacherid = utils.getCookie(request, "teacherid")
    if (teacherid is None) or teacherid == "":
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    teachingid = utils.getParam(request, "teachingid")
    deadlinestr = utils.getParam(request, "deadline") + " 00:00:00"
    deadline = datetime.datetime.strptime(deadlinestr, "%Y-%m-%d %H:%M:%S")
    TeachingService.updateTeachingDeadlineById(teachingid, deadline)
    responseReturn = Response(None, None)
    return HttpResponse(responseReturn.__str__())
Beispiel #7
0
def updateTeachingVideo(request):
    teacherid = utils.getCookie(request, "teacherid")
    if (teacherid is None) or teacherid == "":
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    teachingid = utils.getParam(request, "teachingid")
    videos = utils.getParam(request, "videos")
    if teachingid == "" or teachingid is None:
        responseReturn = Response(-1, "操作有误,请重试")
        return HttpResponse(responseReturn.__str__())
    if videos == "" or videos is None:
        responseReturn = Response(-1, "更换的视频不能为空")
        return HttpResponse(responseReturn.__str__())
    TeachingService.updateTeachingVideoById(teachingid, videos)
    responseReturn = Response(None, None)
    return HttpResponse(responseReturn.__str__())
Beispiel #8
0
def deleteTeacherByid(request):
    adminid = utils.getCookie(request, "adminid")
    if adminid == "" or adminid is None:
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    teacherid = utils.getParam(request, "teacherid")
    count = TeachingService.getCountByTea(teacherid)
    if count > 0:
        responseReturn = Response("-1", "该教师下有未删除的实验教学")
        return HttpResponse(responseReturn.__str__())
    TeacherService.deleteTeacher(teacherid)
    responseReturn = Response(None, None)
    return HttpResponse(responseReturn.__str__())
Beispiel #9
0
def deleteAdminByid(request):
    adminid = utils.getCookie(request, "adminid")
    if adminid == "" or adminid is None:
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    issuperadmin = utils.getCookie(request, "issuperadmin")
    if issuperadmin != "1" or issuperadmin is None:
        responseReturn = Response("-1", "您不是超级管理员,没有删除管理员的权限!")
        return HttpResponse(responseReturn.__str__())
    deleteadminid = utils.getParam(request, "adminid")
    deleteAdmin = AdminService.getAdminById(deleteadminid)
    count = TeachingService.getCountByTea(deleteAdmin.teacherid)
    if count > 0:
        responseReturn = Response("-1", "该教师下有未删除的实验教学")
        return HttpResponse(responseReturn.__str__())
    admin = AdminService.deleteAmin(deleteadminid)
    if admin is None:
        responseReturn = Response("-1", "删除失败!")
        return HttpResponse(responseReturn.__str__())
    responseReturn = Response(None, None)
    return HttpResponse(responseReturn.__str__())
Beispiel #10
0
def addexperiment(request):
    teacherid = utils.getCookie(request, "teacherid")
    if (teacherid is None) or teacherid == "":
        responseReturn = Response(-2, "请登录")
        return HttpResponse(responseReturn.__str__())
    experimentid = utils.getParam(request, "experimentid")
    deadlinestr = utils.getParam(request, "deadline") + " 00:00:00"
    templatetype = utils.getParam(request, "templatetype")
    videotype = utils.getParam(request, "videotype")
    datatype = utils.getParam(request, "datatype")
    videoids = utils.getParam(request, "videos")
    point = utils.getParam(request, "point")
    remark = utils.getParam(request, "remark")
    studentids = utils.getParam(request, "studentids")
    '''
        获得实验详情
    '''
    experiment = ExperimentService.getExperimentById(experimentid)
    if experiment is None:
        responseReturn = Response(-1, "选择实验异常!")
        return HttpResponse(responseReturn.__str__())
    try:
        deadline = datetime.datetime.strptime(deadlinestr, "%Y-%m-%d %H:%M:%S")
    except:
        responseReturn = Response(-1, "请选择报告提交截止日期!")
        return HttpResponse(responseReturn.__str__())
    '''
        获得模板
    '''
    if templatetype == "1":
        templateid = experiment.templateid
    else:  # 文件上传
        templatefile = request.FILES.get('templatefile', None)
        if templatefile is None:
            responseReturn = Response(-1, "请选择你要上传的模板文件!")
            return HttpResponse(responseReturn.__str__())
        filename = templatefile.name
        filesuffix = os.path.splitext(filename)[1]
        if filesuffix != ".doc" and filesuffix != ".docx":
            responseReturn = Response(-1, "模板必须为word格式!")
            return HttpResponse(responseReturn.__str__())
        filename = str(uuid.uuid1()) + filesuffix
        fp = open(os.path.join(CONSTANTS.DATAURL_PRE, filename), 'wb+')
        for chunk in templatefile.chunks():  # 分块写入文件
            fp.write(chunk)
        fp.close()
        templateid = TemplateService.addTemplate(experimentid, filename)
    '''
        获得视频
    '''
    if videotype == "1":
        videos = experiment.videos
    else:
        videos = videoids
    '''
        获得实验数据
    '''
    if datatype == "1":  # 稍后上传
        dataurl = "none"
    else:  # 上传实验数据
        datafile = request.FILES.get('datafile', None)
        if datafile is None:
            responseReturn = Response(-1, "请选择你要上传的实验数据!")
            return HttpResponse(responseReturn.__str__())
        filename = datafile.name
        filesuffix = os.path.splitext(filename)[1]
        if filesuffix != ".xsl" and filesuffix != ".xlsx":
            responseReturn = Response(-1, "实验数据必须为excel!")
            return HttpResponse(responseReturn.__str__())
        filename = str(uuid.uuid1()) + filesuffix
        fp = open(os.path.join(CONSTANTS.DATAURL_PRE, filename), 'wb+')
        for chunk in datafile.chunks():  # 分块写入文件
            fp.write(chunk)
        fp.close()
        dataurl = filename
    '''
        获得学生名单
    '''
    studentidList = studentids.split(",")
    # 添加
    teachingid = TeachingService.addTeaching(int(experimentid), deadline,
                                             teacherid, point, remark, dataurl,
                                             "", templateid, videos)
    if teachingid is None:
        responseReturn = Response(-1, "添加失败,请重试")
        return HttpResponse(responseReturn.__str__())
    for id in studentidList:
        studentobj = None
        studentobj = StudentService.getStudentById(id)
        if studentobj is None:
            TeachingService.deleteTeachingByid(teachingid)
            responseReturn = Response(-1, "选择学生异常,请重试!")
            return HttpResponse(responseReturn.__str__())
        ReportService.addReport(teachingid, studentobj.id)

    responseReturn = Response(0, "添加成功!")
    return HttpResponse(responseReturn.__str__())