예제 #1
0
class createPreCourse(SubjectMixiner, BaseAction):
    def __init__(self):
        self.params = ParamUtil(request)
        self.accessControlService = __spring__.getBean("accessControlService")
        self.pc_svc = __jitar__.getPrepareCourseService()
        self.user_svc = __jitar__.getUserService()
        self.group_svc = __jitar__.getGroupService()
        self.printer = ShowError()
        self.groupId = 0
        self.group = None
        self.prepareCoursePlan = None
        
    def execute(self):

    
        if self.loginUser == None:
            self.printer.msg = u"请先<a href='../../login.jsp'>登录</a>,然后才能进行操作。"
            return self.printer.printError()
                
        baseUser = self.user_svc.getUserByUsername(self.loginUser.loginName)
        accessControlService = __spring__.getBean("accessControlService")
        if not(baseUser.role ==1 or baseUser.role == 3) and accessControlService.isSystemAdmin(self.loginUser) == False:
            self.printer.msg = u"只有管理员和老师身份才能创建备课。<br/><br/><a href='cocourses.action'>返回</a>"
            return self.printer.printError()
        
        self.prepareCourse = None
        self.prepareCourseId = self.params.getIntParam("prepareCourseId")
        request.setAttribute("loginUser", self.loginUser)
        
        if self.prepareCourseId > 0:
            self.prepareCourse = self.pc_svc.getPrepareCourse(self.prepareCourseId)
            # 检查是否是管理员
            if self.pc_svc.checkUserCanManagePreCourse(self.prepareCourseId,self.loginUser) == False:
                self.printer.msg = u"权限被拒绝。"
                return self.printer.printError()
                        
            if self.prepareCourse != None:
                request.setAttribute("prepareCourse", self.prepareCourse)
                g = self.pc_svc.getGroupOfPrepareCourse(self.prepareCourse.prepareCourseId)
                if g != None:
                    request.setAttribute("group", g)
            
        else:
            self.printer.msg = u"此处不能再创建集备了,信息不足。"
            return self.printer.printError()
    
            self.groupId = self.params.safeGetIntParam("groupId")
            self.group = self.group_svc.getGroup(self.groupId)            
            if self.group == None:
                self.printer.msg = u"现在创建集备,需要选择一个协作组。"
                return self.printer.printError()
            self.prepareCoursePlan = self.pc_svc.getDefaultPrepareCoursePlanOfGroup(self.group.groupId)
            if self.prepareCoursePlan == None:
                self.printer.msg = u"该协作组没有默认的备课计划,请到协作组里面进行创建。"
                return self.printer.printError()
            
        if request.getMethod() == "POST":
            return self.saveOrUpdatePrepareCourse()
        else:
            return self.getPrepareCourse()        
    
    def getPrepareCourse(self):
        site_config = SiteConfig()
        site_config.get_config()
        
        self.get_subject_list()
        self.get_grade_list()
        
        request.setAttribute("head_nav", "cocourses")
        
        response.setContentType("text/html; charset=UTF-8")
        return "/WEB-INF/ftl/course/course_create.ftl"
    
    def saveOrUpdatePrepareCourse(self):
        if self.prepareCourse == None:
            self.prepareCourse = PrepareCourse()
            self.prepareCourse.setPrepareCoursePlanId(self.prepareCoursePlan.prepareCoursePlanId)
        else:
            # 只有admin 和 主备人进行修改
            if not(self.accessControlService.isSystemAdmin(self.loginUser) or self.loginUser.userId == self.prepareCourse.createUserId ):
                self.printer.msg = u"只有 admin 或者创建人、主备人才能进行修改。<br/><br/><a href='createPreCourse.py'>返回</a>"
                return self.printer.printError()
        
        pcTitle = self.params.safeGetStringParam("pcTitle")
        pcStartDate = self.params.safeGetStringParam("pcStartDate")
        pcEndDate = self.params.safeGetStringParam("pcEndDate")
        pcGradeId = self.params.getIntParamZeroAsNull("pcGrade")
        pcMetaSubjectId = self.params.getIntParamZeroAsNull("pcMetaSubject")
        pcDescription = self.params.safeGetStringParam("pcDescription")
        pcLeader = self.params.safeGetIntParam("pcLeader")     
        pcTags = self.params.safeGetStringParam("pcTags")
        
        if pcLeader == 0:
            user_leader = self.loginUser
        else:       
            user_leader = self.user_svc.getUserById(pcLeader)
            if user_leader == None:
                self.printer.msg = u"该用户不存在。<br/><br/><a href='createPreCourse.py'>返回</a>"
                return self.printer.printError()
        
        if pcGradeId == None or pcGradeId == 0:
            self.printer.msg = u"你必须选择一个学段。"
            return self.printer.printError()
        
        if pcMetaSubjectId == None or pcMetaSubjectId == 0:
            self.printer.msg = u"你必须选择一个学科。"
            return self.printer.printError()
        
        pcStartDateTime = SimpleDateFormat("yyyy-MM-dd").parse(pcStartDate)
        pcEndDateTime = SimpleDateFormat("yyyy-MM-dd").parse(pcEndDate)
        
        self.prepareCourse.setTitle(pcTitle)
        self.prepareCourse.setStartDate(pcStartDateTime)
        self.prepareCourse.setEndDate(pcEndDateTime)
        self.prepareCourse.setDescription(pcDescription)
        self.prepareCourse.setMetaSubjectId(int(pcMetaSubjectId))
        self.prepareCourse.setGradeId(int(pcGradeId))
        self.prepareCourse.setCreateUserId(self.loginUser.userId)
        self.prepareCourse.setCreateDate(Date())
        self.prepareCourse.setLockedDate(Date())
        self.prepareCourse.setLeaderId(user_leader.getUserId())
        self.prepareCourse.setLockedUserId(0)
        self.prepareCourse.setPrepareCourseEditId(0)
        self.prepareCourse.setTags(pcTags)        
        if self.prepareCourseId > 0:
            self.pc_svc.updatePrepareCourse(self.prepareCourse)
            self.printer.msg = u"您的 <span style='color:#f00'>" + pcTitle + u"</span> 修改成功。<br/><br/><a href='showPrepareCourse.py?prepareCourseId=" + str(self.prepareCourse.prepareCourseId) + "'>返回</a>"
            return self.printer.printError()
        else:
            self.pc_svc.createPrepareCourse(self.prepareCourse)
            self.printer.msg = u"您的 <span style='color:#f00'>" + pcTitle + u"</span> 创建成功。<br/><br/><a href='showPrepareCourse.py?prepareCourseId=" + str(self.prepareCourse.prepareCourseId) + "'>返回</a>"
            return self.printer.printError()

    def get_subject_list(self):
         self.putSubjectList()

    def get_grade_list(self):
        request.setAttribute("gradeId", self.params.getIntParamZeroAsNull("gradeId"))
        self.putGradeList()
예제 #2
0
    def addCourse(self):
        startDate = self.params.getStringParam("startDate")
        endDate = self.params.getStringParam("endDate")
        pctitle = self.params.getStringParam("pctitle")
        pcdesc = self.params.safeGetStringParam("pcdesc")
        pcleader = self.params.safeGetIntParam("pcLeader")
        pctags = self.params.getStringParam("pctags")
        pc_itemorder = self.params.safeGetIntParam("pc_itemorder")
        contentType = self.params.safeGetIntParam("contentType")
        if pctitle == None or pctitle == "":
            actionErrors = [u"请输入课题名称"]
            request.setAttribute("actionErrors", actionErrors)
            return self.ERROR

        if startDate == None or startDate == "":
            actionErrors = [u"请输入开始时间"]
            request.setAttribute("actionErrors", actionErrors)
            return self.ERROR

        sd = Date()
        ed = Date()
        try:
            sd = SimpleDateFormat("yyyy-MM-dd").parse(startDate)
        except:
            actionErrors = [u"输入的开始日期格式不正确,应当是: '年年年年-月月-日日' 格式"]
            request.setAttribute("actionErrors", actionErrors)
            return self.ERROR

        if endDate == None or endDate == "":
            actionErrors = [u"请输入结束时间"]
            request.setAttribute("actionErrors", actionErrors)
            return self.ERROR

        try:
            ed = SimpleDateFormat("yyyy-MM-dd").parse(endDate)
        except:
            actionErrors = [u"输入的结束日期格式不正确,应当是: '年年年年-月月-日日' 格式"]
            request.setAttribute("actionErrors", actionErrors)
            return self.ERROR

        if pcleader == 0:
            pcleader = self.loginUser.userId
            #actionErrors = [u"请输入主备人"]
            #request.setAttribute("actionErrors",actionErrors)
            #return self.ERROR

        prepareCourse = PrepareCourse()
        prepareCourse.setTitle(pctitle)
        prepareCourse.setCreateUserId(self.loginUser.userId)
        prepareCourse.setLeaderId(pcleader)
        prepareCourse.setCreateDate(Date())
        prepareCourse.setStartDate(sd)
        prepareCourse.setEndDate(ed)
        prepareCourse.setDescription(pcdesc)
        prepareCourse.setCommonContent("")
        prepareCourse.setMetaSubjectId(self.prepareCoursePlan.getSubjectId())
        prepareCourse.setGradeId(self.prepareCoursePlan.getGradeId())
        prepareCourse.setTags(pctags)
        prepareCourse.setStatus(0)
        prepareCourse.setLockedDate(Date())
        prepareCourse.setLockedUserId(0)
        prepareCourse.setPrepareCourseEditId(0)
        prepareCourse.setItemOrder(pc_itemorder)
        prepareCourse.setPrepareCoursePlanId(
            self.prepareCoursePlan.prepareCoursePlanId)
        prepareCourse.setPrepareCourseGenerated(True)
        prepareCourse.setContentType(contentType)
        self.prepareCourseService.createPrepareCourse(prepareCourse)

        # 得到协作组所有成员
        qry = GroupMemberQuery("gm.userId")
        qry.memberStatus = 0
        qry.groupId = self.prepareCoursePlan.groupId
        user_list = qry.query_map(qry.count())

        pcmContentType = 0

        #对于创建者和主备人,需要更新下个人信息,主要是ContentType属性
        m = self.prepareCourseService.getPrepareCourseMemberByCourseIdAndUserId(
            prepareCourse.prepareCourseId, prepareCourse.createUserId)
        if m != None:
            m.setContentType(pcmContentType)
            self.prepareCourseService.updatePrepareCourseMember(m)

        if prepareCourse.createUserId != prepareCourse.leaderId:
            m = self.prepareCourseService.getPrepareCourseMemberByCourseIdAndUserId(
                prepareCourse.prepareCourseId, prepareCourse.leaderId)
            if m != None:
                m.setContentType(pcmContentType)
                self.prepareCourseService.updatePrepareCourseMember(m)
        # 添加成员
        for u in user_list:
            if self.prepareCourseService.checkUserExistsInPrepareCourse(
                    prepareCourse.prepareCourseId, u["userId"]) == False:
                m = PrepareCourseMember()
                m.setPrepareCourseId(prepareCourse.prepareCourseId)
                m.setUserId(u["userId"])
                m.setJoinDate(Date())
                m.setStatus(0)
                m.setReplyCount(0)
                m.setContentLastupdated(Date())
                m.setContentType(pcmContentType)
                self.prepareCourseService.addPrepareCourseMember(m)

        # 更新统计信息
        self.prepareCourseService.updatePrepareCourse(prepareCourse)
        self.prepareCourseService.countPrepareCourseData(
            prepareCourse.prepareCourseId)

        actionLinks = ActionLink(
            u"返回", "group_course_plan_edit.py?groupId=" + str(self.groupId) +
            "&prepareCoursePlanId=" + str(self.prepareCoursePlanId) + "&tmp=" +
            str(Date().hashCode()), "_self")

        request.setAttribute("actionLinks", [actionLinks])
        return self.SUCCESS
예제 #3
0
class show_preparecourse_edit(PrepareCoursePageService):
    def __init__(self):
        self.printer = response.getWriter()
        self.prepareCourseEdit = None
        self.accessControlService = __spring__.getBean("accessControlService")
        self.pc_svc = __jitar__.getPrepareCourseService()
        self.user_svc = __jitar__.getUserService()
        self.sub_svc = __jitar__.subjectService

    def execute(self):
        self.getBaseData()
        response.setContentType("text/html; charset=UTF-8")
        if self.loginUser == None:
            self.printer.write(
                u"请先登录。<a href='../../../../login.jsp'>登录页面</a>")
            return

        baseUser = self.user_svc.getUserByUsername(self.loginUser.loginName)
        accessControlService = __spring__.getBean("accessControlService")
        if not (baseUser.role == 1
                or baseUser.role == 3) and accessControlService.isSystemAdmin(
                    self.loginUser) == False:
            self.printer.write(
                u"只有管理员和老师身份才能创建备课。<br/><br/><a href='../../../../cocourses.action'>返回</a>"
            )
            return

        if self.prepareCourseId == 0:
            self.printer.write(u"无效的课程标识。")
            return
        prepareCourse = self.getBasePrepareCourse()
        if prepareCourse == None:
            self.printer.write(u"没有加载到所请求的备课。")
            return
        if self.canManage(prepareCourse) == False:
            self.printer.write(u"您无权管理本备课。")
            return

        page = self.getPrepareCoursePageWithCustomSkin(prepareCourse)
        widgets = [{
            "id": "placerholder1",
            "pageId": 0,
            "columnIndex": 2,
            "title": "",
            "module": "placeholder",
            "ico": "",
            "data": ""
        }]

        request.setAttribute("widget_list", widgets)
        request.setAttribute("page", page)
        request.setAttribute("prepareCourse", prepareCourse)
        request.setAttribute("prepareCourseId", self.prepareCourseId)

        self.prepareCourseMember = self.pc_svc.getPrepareCourseMemberByCourseIdAndUserId(
            self.prepareCourseId, self.loginUser.userId)
        if self.prepareCourseMember == None:
            operation_result = u"您不是该课的成员,或者加载对象失败。"
            request.setAttribute("operation_result", operation_result)
            return "/WEB-INF/ftl/course/show_preparecourse_ok_info.ftl"

        request.setAttribute("prepareCourseMember", self.prepareCourseMember)

        if request.getMethod() == "POST":
            return self.saveOrUpdatePrepareCourse()

        self.get_subject_list()
        self.get_grade_list()

        return "/WEB-INF/ftl/course/show_preparecourse_edit.ftl"

    def saveOrUpdatePrepareCourse(self):
        if self.prepareCourse == None:
            self.prepareCourse = PrepareCourse()
        else:
            # 只有admin 和 主备人进行修改
            if not (self.accessControlService.isSystemAdmin(self.loginUser) or
                    self.loginUser.userId == self.prepareCourse.createUserId):
                return self.getReturnInfo(u"只有 admin 或者创建人、主备人才能进行修改。")

        pcTitle = self.params.safeGetStringParam("pcTitle")
        pcStartDate = self.params.safeGetStringParam("pcStartDate")
        pcEndDate = self.params.safeGetStringParam("pcEndDate")
        pcGradeId = self.params.getIntParamZeroAsNull("pcGrade")
        pcMetaSubjectId = self.params.getIntParamZeroAsNull("pcMetaSubject")
        pcDescription = self.params.safeGetStringParam("pcDescription")
        pcLeader = self.params.safeGetIntParam("pcLeader")
        pcTags = self.params.safeGetStringParam("pcTags")

        if pcLeader == "":
            user_leader = self.loginUser
        else:
            user_leader = self.user_svc.getUserById(pcLeader)
            if user_leader == None:
                return self.getReturnInfo(u"该用户不存在。")

        if pcGradeId == None or pcGradeId == 0:
            return self.getReturnInfo(u"你必须选择一个学段。")

        if pcMetaSubjectId == None or pcMetaSubjectId == 0:
            return self.getReturnInfo(u"你必须选择一个学科。")

        pcStartDateTime = SimpleDateFormat("yyyy-MM-d").parse(pcStartDate)
        pcEndDateTime = SimpleDateFormat("yyyy-MM-d").parse(pcEndDate)

        self.prepareCourse.setTitle(pcTitle)
        self.prepareCourse.setStartDate(pcStartDateTime)
        self.prepareCourse.setEndDate(pcEndDateTime)
        self.prepareCourse.setDescription(pcDescription)
        self.prepareCourse.setMetaSubjectId(int(pcMetaSubjectId))
        self.prepareCourse.setGradeId(int(pcGradeId))
        self.prepareCourse.setCreateUserId(self.loginUser.userId)
        self.prepareCourse.setCreateDate(Date())
        self.prepareCourse.setLockedDate(Date())
        self.prepareCourse.setLeaderId(user_leader.getUserId())
        self.prepareCourse.setLockedUserId(0)
        self.prepareCourse.setPrepareCourseEditId(0)
        self.prepareCourse.setTags(pcTags)
        if self.prepareCourseId > 0:
            self.pc_svc.updatePrepareCourse(self.prepareCourse)
            return self.getReturnInfo(u"您的 <span style='color:#f00'>" +
                                      pcTitle + u"</span> 修改成功。")
        else:
            self.pc_svc.createPrepareCourse(self.prepareCourse)
            return self.getReturnInfo(u"您的 <span style='color:#f00'>" +
                                      pcTitle + u"</span> 创建成功。")

    def get_subject_list(self):
        subject_list = self.sub_svc.getMetaSubjectList()
        request.setAttribute("subject_list", subject_list)

    def get_grade_list(self):
        request.setAttribute("gradeId",
                             self.params.getIntParamZeroAsNull("gradeId"))
        grade_list = self.sub_svc.getGradeList()
        request.setAttribute("grade_list", grade_list)

    def getReturnInfo(self, strMesage):
        request.setAttribute("operation_result", strMesage)
        return "/WEB-INF/ftl/course/show_preparecourse_ok_info.ftl"