Exemplo n.º 1
0
    def execute(self):
        if self.loginUser == None:
            return ActionResult.LOGIN

        accessControlService = __spring__.getBean("accessControlService")
        if accessControlService.isSystemAdmin(self.loginUser) == False:
            self.addActionError(u"没有管理站点配置的权限,只有超级管理员才能进行管理。")
            return ActionResult.ERROR

        strFile = request.getServletContext().getRealPath("/")
        strFile = strFile + "html" + File.separator
        strFile = URLDecoder.decode(strFile, "utf-8")
        file = File(strFile)
        if file.exists() == False:
            file.mkdirs()
        #创建学科导航
        strFile = strFile + "updateinfo.htm"
        file = File(strFile)
        if request.getMethod() == "POST":
            params = ParamUtil(request)
            html = params.safeGetStringParam("updateInfo")
            fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
            fw.flush()
            fw.write(html)
            fw.close()
            siteIndexPartService = __spring__.getBean("siteIndexPartService")
            if html == "":
                siteIndexPart = siteIndexPartService.getSiteIndexPartByModuleName(
                    u"系统维护通知")
                if siteIndexPart != None:
                    siteIndexPartService.deleteSiteIndexPart(siteIndexPart)
            else:
                siteIndexPart = siteIndexPartService.getSiteIndexPartByModuleName(
                    u"系统维护通知")
                if siteIndexPart == None:
                    siteIndexPart = SiteIndexPart()
                siteIndexPart.setModuleName(u"系统维护通知")
                siteIndexPart.setModuleZone(1)
                siteIndexPart.setModuleOrder(0)
                siteIndexPart.setModuleDisplay(1)
                siteIndexPart.setModuleHeight(0)
                siteIndexPart.setContent(html)
                siteIndexPart.setPartType(100)
                siteIndexPart.setShowType(0)
                siteIndexPart.setShowBorder(0)
                siteIndexPartService.saveOrUpdateSiteIndexPart(siteIndexPart)
            request.setAttribute("deleteCache", "1")
        else:
            html = CommonUtil.readFile(file.getCanonicalPath(), "UTF-8")
            request.setAttribute("deleteCache", "0")

        request.setAttribute("updateInfo", html)
        return "/WEB-INF/ftl/admin/admin_site_update.ftl"
Exemplo n.º 2
0
    def execute(self):
        #print "MemcachedExpireTimeConfig.getSiteIndexExpireTime()=",MemcachedExpireTimeConfig.getSiteIndexExpireTime()
        if self.viewcount_svc == None:
            self.addActionError(
                u"无法加载组织机构服务,请检查 applicationContext.xml 配置文件,是否缺少 viewCountService 节点。"
            )
            return self.ERROR

        if self.templateProcessor == None:
            self.addActionError(
                u"无法加载组织机构服务,请检查 applicationContext.xml 配置文件,是否缺少 templateProcessor 节点。"
            )
            return self.ERROR

        if self.unitService == None:
            self.addActionError(
                u"无法加载组织机构服务,请检查 applicationContext.xml 配置文件,是否缺少 unitService 节点。"
            )
            return self.ERROR

        self.unit = self.getUnit()
        if self.unit == None:
            self.addActionError(u"您所访问的机构不存在!")
            return self.ERROR
        #print "self.unit.parentId = ", self.unit.parentId
        if self.unit.delState == True:
            self.addActionError(u"您所访问的机构已经被删除!")
            return self.ERROR
        if self.unit.parentId == 0:
            configSiteRoot = request.getAttribute("configSiteRoot")
            if configSiteRoot == None or len(configSiteRoot) == 0:
                response.sendRedirect(request.getContextPath() + "/")
            else:
                response.sendRedirect(configSiteRoot)
            return
        preview = self.params.safeGetStringParam("preview")
        if self.isUnitAdmin() == False or preview == "":
            fc = FileCache()
            html = ""
            out = response.getWriter()
            theme = self.params.safeGetStringParam("theme")

            if theme != "":
                #这是预览
                html = self.htmlGeneratorService.UnitIndex(
                    self.unit, "", theme)
                out.write(html)
            else:
                unitIndexHtmlPath = fc.getUnitHtmlFolder(
                    self.unit.unitName) + "index.html"
                if fc.contentIsExpired(
                        unitIndexHtmlPath,
                        MemcachedExpireTimeConfig.getSiteIndexExpireTime() /
                        60) == True:
                    html = self.htmlGeneratorService.UnitIndex(self.unit)
                    out.write(html)
                else:
                    file = File(unitIndexHtmlPath)
                    out.write(
                        CommonUtil.readFile(file.getCanonicalPath(), "UTF-8"))
                    file = None
            fc = None
            #request.getSession().getServletContext().getRequestDispatcher("/html/unit/" + self.unit.unitName + "/index.html").forward(request, response)
            return
        """""" """
                        注意:以下代码只有管理员执行!!!!!!!
        """ """"""
        self.templateName = "template1"
        if self.unit.templateName != None:
            self.templateName = self.unit.templateName

        webpartList = self.unitService.getUnitWebpartList(self.unit.unitId)
        if self.params.existParam("tm") == False:
            if len(webpartList) < 1:
                self.genWebparts()
                response.sendRedirect("?tm=1")
                return

        for webpart in webpartList:
            self.set_webpart_flag(webpart)
            #print "webpart.moduleName = ", webpart.moduleName
            # 生成具体的内容,放到content字段内
            if webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_ARTICLE:
                self.genernate_article_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_RESOURCE:
                self.genernate_resoure_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_PHOTO:
                self.genernate_photo_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_VIDEO:
                self.genernate_video_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_PICNEWS:
                self.genernate_picnews_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_NEWESTNEWS:
                self.genernate_newestnews_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_UNITNOTICE:
                self.genernate_unitnotice_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_LINKS:
                self.genernate_links_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_STATISTICS:
                self.genernate_statistics_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_VOTE:
                self.genernate_vote_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_UNITSUBJECT:
                self.genernate_unitsubject_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_UNITGROUP:
                self.genernate_group_content(webpart)
            elif webpart.moduleName == UnitWebpart.WEBPART_MODULENAME_UNITPREPARECOURSE:
                self.genernate_preparecourse_content(webpart)
            else:
                #自写内容,无需处理
                cache_key = "unit" + str(self.unit.unitId) + "_" + str(
                    webpart.getUnitWebpartId())
                content = cache.get(cache_key)
                if content != None:
                    request.setAttribute(cache_key, content)
                else:
                    map = HashMap()
                    map.put("unit", self.unit)
                    map.put("UnitRootUrl", self.unitRootUrl)
                    map.put("webpart", webpart)
                    content = self.templateProcessor.processTemplate(
                        map, "/WEB-INF/unitspage/" + self.templateName +
                        "/custorm.ftl", "utf-8")
                    request.setAttribute(cache_key, content)
                    cache.put(cache_key, content)

        theme = self.params.safeGetStringParam("theme")
        request.setAttribute("head_nav", "unit")
        request.setAttribute("unit", self.unit)
        request.setAttribute("webpartList", webpartList)
        if theme != "":
            request.setAttribute("theme", theme)

        if self.loginUser != None:
            request.setAttribute("loginUser", self.loginUser)

            if self.isUnitAdmin() == True and preview != "":
                request.setAttribute("role", "admin")

        request.setAttribute("req", request)
        return "/WEB-INF/unitspage/" + self.templateName + "/index.ftl"