def genernate_news_content(self, webpart): cache_key = "sbj" + str(self.subject.subjectId) + "_" + str( webpart.getSubjectWebpartId()) + self.cacheKeyFix content = cache.get(cache_key) if content != None: request.setAttribute(cache_key, content) return map = HashMap() qry = SiteNewsQuery(""" snews.newsId, snews.title, snews.createDate""") qry.subjectId = self.subject.subjectId qry.hasPicture = False subject_text_news = qry.query_map(6) map.put("subject_text_news", subject_text_news) map.put("subject", self.subject) map.put("SubjectRootUrl", self.subjectRootUrl) map.put("webpart", webpart) map.put("unitId", self.unitId) content = self.templateProcessor.processTemplate( map, "/WEB-INF/subjectpage/" + self.templateName + "/text_news.ftl", "utf-8") request.setAttribute(cache_key, content) cache.put(cache_key, content)
def get_news_list(self): qry = SiteNewsQuery( """ snews.createDate, snews.newsId, snews.title """) qry.subjectId = self.get_subjectId() qry.gradeId = self.get_current_gradeId() news_list = qry.query_map(7) request.setAttribute("news_list", news_list)
def get_pic_news(self): cache_key = 'index_pic_news' pic_news = cache.get(cache_key) if pic_news == None: qry = SiteNewsQuery( """ snews.newsId, snews.title, snews.picture """) qry.hasPicture = True qry.subjectId = 0 pic_news = qry.query_map(5) if pic_news == None: return for p in pic_news: p_url = p["picture"] p_url_path = p_url[0:p_url.rfind("/") + 1] p_url_fileName = p_url[p_url.rfind("/") + 1:p_url.rfind(".")] p_url_fileExt = p_url[p_url.rfind("."):] p_url_fileName = CommonUtil.escape( CommonUtil.urlGB2312Encode(p_url_fileName)) p["picture"] = p_url_path + p_url_fileName + p_url_fileExt cache.put(cache_key, pic_news) request.setAttribute("pic_news", pic_news)
def news_list(self): qry = SiteNewsQuery( """ snews.newsId, snews.title, snews.picture, snews.status, snews.newsType, snews.createDate, snews.viewCount, snews.userId """ ) qry.subjectId = self.subject.subjectId qry.status = None pager = self.params.createPager() pager.itemName = u"新闻" pager.itemUnit = u"个" pager.pageSize = 25 pager.totalRows = qry.count() subject_news_list = qry.query_map(pager) request.setAttribute("subject", self.subject) request.setAttribute("subject_news_list", subject_news_list) return "/WEB-INF/subjectmanage/news_list.ftl"
def execute(self): if self.subject == None: self.addActionError(u"无法加载指定的学科。") return self.ERROR self.templateName = "template1" if self.subject.templateName != None: self.templateName = self.subject.templateName type = self.params.safeGetStringParam("type") qry = SiteNewsQuery( " snews.newsId, snews.title, snews.createDate, snews.picture ") qry.subjectId = self.subject.subjectId Page_Title = self.params.safeGetStringParam("title") if "pic" == type: if Page_Title == "": Page_Title = u"图片新闻" qry.hasPicture = True elif "text" == type: qry.hasPicture = False if Page_Title == "": Page_Title = u"学科动态" else: if Page_Title == "": Page_Title = u"学科新闻" pager = None pager = self.params.createPager() pager.pageSize = 10 pager.itemName = u"新闻" pager.itemUnit = u"条" pager.totalRows = qry.count() news_list = qry.query_map(pager) request.setAttribute("Page_Title", Page_Title) request.setAttribute("news_list", news_list) request.setAttribute("pager", pager) request.setAttribute("subject", self.subject) return "/WEB-INF/subjectpage/" + self.templateName + "/newsList.ftl"
def get_jitar_news(self): cache_key = 'index_jitar_news' jitar_news = cache.get(cache_key) # 从缓存中查找. if jitar_news == None: qry = SiteNewsQuery( " snews.newsId, snews.title, snews.createDate ") qry.subjectId = 0 qry.orderType = 0 qry.hasPicture = None jitar_news = qry.query_map(15) qry = SiteNewsQuery("snews.newsId") qry.hasPicture = True qry.subjectId = 0 qry.orderType = 0 pic_news = qry.query_map(5) str_picid = "_" if pic_news != None: for p in pic_news: str_picid += str(p["newsId"]) + "_" i = 0 jitar_news2 = ArrayList() if jitar_news != None: for news in jitar_news: if str_picid.find("_" + str(news["newsId"]) + "_") == -1: jitar_news2.add(news) i += 1 if i > 8: break request.setAttribute("jitar_news", jitar_news2)