def getTeachingByTea(teaid, type, index): teachingsearch = Teaching.objects.filter(teacherid=teaid, status=type, isdelete=CONSTANTS.ISDELETE_NOT) try: teachinglist = teachingsearch.all() except: return None else: paginator = Paginator(teachinglist, 10) teachingPageList = paginator.page(index) teachingDictPageList = [] for teaching in teachingPageList: teachingDict = { "id": teaching.id, "experimentid": teaching.experimentid, "deadline": teaching.deadline, "teacherid": teaching.teacherid, "point": teaching.point, "remark": teaching.remark, "dataurl": teaching.dataurl, "stulisturl": teaching.stulisturl, "templateid": teaching.templateid, "videos": teaching.videos, "status": teaching.status, "isdelete": teaching.isdelete, "createtime": teaching.createtime, "updatetime": teaching.updatetime } experiment = ExperimentService.getExperimentById(teaching.experimentid) teachingDict["f_experiment_name"] = experiment.name teachingDict["f_experiment_desc"] = experiment.desc teachingDict["f_experiment_url"] = experiment.url teacher = TeacherService.getTeacherById(teaching.teacherid) teachingDict["f_teacher_name"] = teacher.name teachingDict["f_teacher_id"] = teacher.id videoids = teaching.videos.split(",") videos = [] for id in videoids: video = VideoService.getVideoById(id) video.url = "/getVideoById/?videourl=" + video.url videoobj = { "id": video.id, "url": video.url, "name": video.name } videos.append(videoobj) teachingDict["videos"] = json.dumps(videos) stuCount = ReportService.getCountStuByTeachingid(teaching.id) teachingDict["stuCount"] = stuCount complapprepcount = ReportService.getCountStuByTeachingidAndStatus(teaching.id, CONSTANTS.REPORT_STATUS_SCORE) submitcount = ReportService.getCountStuByTeachingidAndStatus(teaching.id, CONSTANTS.REPORT_STATUS_SUBMIT) teachingDict["complapprepcount"] = complapprepcount if complapprepcount == stuCount: teachingDict["f_report_status"] = 2 else: teachingDict["f_report_status"] = 1 teachingDictPageList.append(teachingDict) return teachingDictPageList
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__())
def getTeachingByStu(stuid, type, index): reportList = ReportService.getReportByStuId(stuid) teachingIds = [] for i in range(len(reportList)): if i >= len(reportList): break teachingIds.append(reportList[i].teachingid) try: teachinglist = Teaching.objects.filter(id__in=teachingIds, status=type, isdelete=CONSTANTS.ISDELETE_NOT).all() except: return None else: teachingDictList = [] for teaching in teachinglist: teachingDict = { "id": teaching.id, "experimentid": teaching.experimentid, "deadline": teaching.deadline, "teacherid": teaching.teacherid, "point": teaching.point, "remark": teaching.remark, "dataurl": teaching.dataurl, "stulisturl": teaching.stulisturl, "templateid": teaching.templateid, "videos": teaching.videos, "status": teaching.status, "isdelete": teaching.isdelete, "createtime": teaching.createtime, "updatetime": teaching.updatetime, } experiment = ExperimentService.getExperimentById(teaching.experimentid) teachingDict["f_experiment_name"] = experiment.name teachingDict["f_experiment_desc"] = experiment.desc teachingDict["f_experiment_url"] = experiment.url teacher = TeacherService.getTeacherById(teaching.teacherid) teachingDict["f_teacher_name"] = teacher.name teachingDict["f_teacher_id"] = teacher.id videoids = teaching.videos.split(",") videos = [] for id in videoids: video = VideoService.getVideoById(id) video.url = "/getVideoById/?videourl=" + video.url videoobj = { "url": video.url, "name": video.name } videos.append(videoobj) teachingDict["videos"] = json.dumps(videos) for report in reportList: if report.teachingid == teaching.id: teachingDict["f_report_status"] = report.status teachingDict["f_report_id"] = report.id if (report.url is None) or (report.url == "") or report.url == "none": teachingDict["f_report_url"] = "" else: teachingDict["f_report_url"] = report.url if report.score > 0: teachingDict["f_score"] = report.score else: teachingDict["f_score"] = 0 teachingDictList.append(teachingDict) return teachingDictList