def get_photo_category(self): # 得到根一级图片分类. photo_cates = self.get_photo_root_category() # 得到每个分类的最新的 6 张图片. qry = PhotoQuery(""" p.photoId, p.title, p.href, u.loginName """) for c in photo_cates: qry.sysCateId = c["categoryId"] c["photo_list"] = qry.query_map(6) #如果没有分类,则显示当前的全部图片 if len(photo_cates) == 0: photo_cates = None pager = self.params.createPager() pager.itemName = u"图片" pager.itemUnit = u"张" pager.pageSize = 24 qry = PhotoQuery( """ p.photoId, p.title, p.createDate, p.href, u.userId, u.loginName, u.nickName, p.summary """ ) qry.orderType = 0 pager.totalRows = qry.count() photo_list_all = qry.query_map(pager) request.setAttribute("photo_list_all", photo_list_all) request.setAttribute("pager", pager) #DEBUG: print "photo_cates = ", photo_cates request.setAttribute("photo_cates", photo_cates)
def show_specialSubject(self): qry = PhotoQuery(""" p.photoId, p.title, p.userId,p.href, p.userTrueName,u.loginName """) qry.specialSubjectId = self.specialSubject.specialSubjectId qry.extName = ".jpg" ssp_list = qry.query_map(6) qry = SpecialSubjectArticleQuery(""" ssa.articleId, ssa.title, ssa.userId, ssa.userTrueName, ssa.createDate, ssa.loginName, ssa.typeState """) qry.specialSubjectId = self.specialSubject.specialSubjectId ssa_list = qry.query_map(10) qry = SpecialSubjectQuery(""" ss.specialSubjectId, ss.objectGuid, ss.title,ss.logo,ss.description,ss.createDate,ss.expiresDate """) qry.objectId = self.subject.subjectId qry.objectType = "subject" ss_list = qry.query_map(10) if ssp_list != None and len(ssp_list) > 0: request.setAttribute("specialSubjectPhotoList", ssp_list) request.setAttribute("specialSubjectArticleList", ssa_list) request.setAttribute("specialSubjectList", ss_list) request.setAttribute("specialSubject", self.specialSubject) request.setAttribute("subject", self.subject) request.setAttribute("head_nav", "specialsubject") if self.unitId != None and self.unitId != 0: request.setAttribute("unitId", self.unitId) self.video_list() return "/WEB-INF/subjectpage/" + self.templateName + "/specialsubject_page.ftl"
def get_new_photo_list(self): qry = PhotoQuery( """ p.photoId, p.title, p.createDate, p.href, u.userId, u.loginName, u.nickName, p.summary """ ) qry.orderType = PhotoQuery.ORDER_TYPE_PHOTOID_DESC new_photo_list = qry.query_map(10) request.setAttribute("new_photo_list", new_photo_list)
def execute(self): self.params = ParamUtil(request) userId = self.params.safeGetIntParam("userId", 0) listCount = self.params.safeGetIntParam("count", 4) fwidth = self.params.safeGetIntParam("fwidth", 200) fheight = self.params.safeGetIntParam("fheight", 200) ftxtheight = self.params.safeGetIntParam("ftxtheight", 36) fbgcolor = self.params.safeGetStringParam("fbgcolor") if fbgcolor == "": fbgcolor = "#E5ECF4" if userId == 0: request.setAttribute("ErrText", "没有找到所查询的图片") return "/WEB-INF/ftl/webpart_error.ftl" user = user_svc.getUserById(userId) if user == None: request.setAttribute("ErrText", "没有找到该用户") return "/WEB-INF/ftl/webpart_error.ftl" qry = PhotoQuery(""" p.photoId, p.title, p.href """) qry.userId = userId qry.orderType = 0 qry.extName = ".jpg" qry.isPrivateShow = None result = qry.query_map(listCount) request.setAttribute("user", user) request.setAttribute("photo_list", result) request.setAttribute("fwidth", fwidth) request.setAttribute("fheight", fheight) request.setAttribute("ftxtheight", ftxtheight) request.setAttribute("fbgcolor", fbgcolor) response.contentType = "text/html; charset=UTF-8" return "/WEB-INF/user/default/flash_photo.ftl"
def get_new_photo_list(self): qry = PhotoQuery( """ p.photoId, p.title, p.createDate, p.href, u.userId, u.loginName, u.nickName, p.summary """ ) qry.sysCateId = int(self.categoryId) qry.orderType = 0 # photoId DESC new_photo_list = qry.query_map(10) request.setAttribute("new_photo_list", new_photo_list)
def get_unit_photo_list(self): qry = PhotoQuery( """ p.photoId, p.title, p.createDate, p.href, u.userId, u.loginName, u.nickName, p.summary """ ) qry.unitId = self.unit.unitId pager = self.createPager() pager.totalRows = qry.count() photo_list = qry.query_map(pager) request.setAttribute("photo_list", photo_list) request.setAttribute("pager", pager)
def photoList(self): pager = self.params.createPager() pager.itemName = u"图片" pager.itemUnit = u"张" pager.pageSize = 48 qry = PhotoQuery(""" p.photoId, p.title, p.userId,p.href, p.userTrueName,u.loginName """) qry.specialSubjectId = self.specialSubjectId pager.totalRows = qry.count() photo_list = qry.query_map(pager) request.setAttribute("photo_list", photo_list) request.setAttribute("pager", pager) return "/WEB-INF/ftl/specialsubject/specialsubject_photo_list.ftl"
def execute(self): params = ParamUtil(request) self.userName = params.safeGetStringParam("loginName") title = params.safeGetStringParam("title") userCateId = params.safeGetIntParam("userCateId") #print "-----------------------------category_photo.py-----------------------------" #print "self.userName="******"title="+title #print "userCateId="+str(userCateId) if userCateId == 0: response.getWriter().write( u"<div style='text-align:center;'>请选择一个个人图片分类。</div>") return fc = FileCache() content = fc.getUserFileCacheContent( self.userName, "category_photo_" + str(userCateId) + ".html", 30) if content != "": response.getWriter().write(content) fc = None return count = params.safeGetIntParam("count") if count == 0: count = 9 #print "count="+str(count) user = __jitar__.userService.getUserByLoginName(self.userName) if user == None: response.getWriter().write(u"不能加载当前用户。") return qry = PhotoQuery( """ p.photoId, p.title, p.createDate, p.lastModified, p.href, p.commentCount,p.viewCount, p.userStaple, u.nickName, u.loginName, u.userIcon, stap.title as stapleTitle """) qry.userStapleId = userCateId qry.userId = user.userId photo_list = qry.query_map(count) templateProcessor = __spring__.getBean("templateProcessor") map = HashMap() map.put("photo_list", photo_list) map.put("UserSiteUrl", self.getUserSiteUrl()) map.put("userCateId", userCateId) map.put("title", title) map.put("user", user) content = templateProcessor.processTemplate( map, "/WEB-INF/user/default/category_photo.ftl", "utf-8") fc.writeUserFileCacheContent( self.userName, "category_photo_" + str(userCateId) + ".html", content) response.getWriter().write(content) fc = None
def get_method(self): qry = PhotoQuery( """ p.title, p.photoId, p.userId, p.createDate, p.href """) qry.specialSubjectId = self.specialSubject.specialSubjectId pager = self.params.createPager() pager.itemName = u"图片" pager.itemUnit = u"个" pager.pageSize = 20 pager.totalRows = qry.count() photo_list = qry.query_map(pager) request.setAttribute("photo_list", photo_list) request.setAttribute("pager", pager) request.setAttribute("specialSubject", self.specialSubject) return "/WEB-INF/subjectmanage/specialsubject_photo_list.ftl"
def get_photo_with_pager(self): pager = self.params.createPager() pager.itemName = u"图片" pager.itemUnit = u"张" pager.pageSize = 24 qry = PhotoQuery( """ p.photoId, p.title, p.createDate, p.href, u.userId, u.loginName, u.nickName, p.summary """ ) qry.sysCateId = int(self.categoryId) qry.orderType = 0 pager.totalRows = qry.count() photo_list = qry.query_map(pager) request.setAttribute("photo_list", photo_list) request.setAttribute("pager", pager)
def List(self) : # 构造查询. query = PhotoQuery(""" p.photoId, p.title, p.summary, p.href, p.tags, stap.title as stapTitle, sc.name as sysPhotoName, p.viewCount, p.createDate, p.addIp, u.nickName, u.loginName, p.auditState, p.delState, p.isPrivateShow """) query.unitId = self.unit.unitId query.isPrivateShow = None query.auditState = None query.delState = None auditState = self.params.safeGetStringParam("auditState") if auditState=="1": query.auditState = 1 elif auditState=="0": query.auditState = 0 isPrivateShow = self.params.safeGetStringParam("isPrivateShow") if isPrivateShow=="1": query.isPrivateShow = 1 elif isPrivateShow=="0": query.isPrivateShow = 0 query.k = self.params.safeGetStringParam("k") query.f = self.params.safeGetStringParam("f") query.sysCateId = self.params.getIntParamZeroAsNull("sc") query.photoStaple = self.params.getIntParamZeroAsNull("ps") self.putSysCategoryTree() self.putPhotoStaple() # TODO: 权限检查. # 调用分页函数. pager = self.createPager() pager.totalRows = query.count() # 得到所有照片的列表. photoList = query.query_map(pager) #print "photoList = ", photoList # 传给页面. request.setAttribute("photoList", photoList) request.setAttribute("pager", pager) request.setAttribute("auditState", auditState) request.setAttribute("isPrivateShow", isPrivateShow) request.setAttribute("k", query.k) request.setAttribute("f", query.f) request.setAttribute("sc", query.sysCateId) request.setAttribute("ps", query.photoStaple)
def execute(self): self.params = ParamUtil(request) self.type = self.params.getIntParam("type") userId = self.params.safeGetIntParam("userId", 0) listCount = self.params.safeGetIntParam("count", 4) user = __jitar__.userService.getUserById(userId) if user == None: request.setAttribute("MessageText", "没有找到所查询的图片") return "/WEB-INF/ftl/show_message.ftl" else: self.userName = user.loginName fc = FileCache() if self.type == 2: content = fc.getUserFileCacheContent(self.userName, "user_photo2.html", 60) else: content = fc.getUserFileCacheContent(self.userName, "user_photo.html", 60) if content != "": response.getWriter().write(content) fc = None return qry = PhotoQuery( """ p.photoId, p.title, p.createDate, p.lastModified, p.href, u.nickName, u.loginName, u.userIcon, sc.name """) qry.userId = userId qry.orderType = 0 qry.isPrivateShow = None photo_list = qry.query_map(int(listCount)) templateProcessor = __spring__.getBean("templateProcessor") map = HashMap() map.put("photo_list", photo_list) map.put("UserSiteUrl", self.getUserSiteUrl()) if self.type == 2: content = templateProcessor.processTemplate( map, "/WEB-INF/user/default/user_photo2.ftl", "utf-8") fc.writeUserFileCacheContent(self.userName, "user_photo2.html", content) else: content = templateProcessor.processTemplate( map, "/WEB-INF/user/default/user_photo.ftl", "utf-8") fc.writeUserFileCacheContent(self.userName, "user_photo.html", content) response.getWriter().write(content) fc = None
def show_specialsubject_photo_list(self): qry = PhotoQuery( """ p.photoId, p.title, p.userId,p.href, p.userTrueName,u.loginName """ ) qry.specialSubjectId = self.specialSubject.specialSubjectId pager = self.params.createPager() pager.itemName = u"图片" pager.itemUnit = u"个" pager.pageSize = 20 pager.totalRows = qry.count() photo_list = qry.query_map(pager) request.setAttribute("photo_list", photo_list) request.setAttribute("pager", pager) request.setAttribute("specialSubject", self.specialSubject) request.setAttribute("subject", self.subject) request.setAttribute("head_nav", "specialsubject") return "/WEB-INF/subjectpage/" + self.templateName + "/show_photo_list.ftl"
def get_hot_hot_list(self): pw = request.getSession().getServletContext().getInitParameter( "photo_width") ph = request.getSession().getServletContext().getInitParameter( "photo_height") if pw == None or pw == "" or pw.isdigit() == False: pw = 150 if ph == None or ph == "" or ph.isdigit() == False: ph = 120 request.setAttribute("pw", pw) request.setAttribute("ph", ph) cache_key = "hot_photo_list" hot_photo_list = cache.get(cache_key) if hot_photo_list == None: qry = PhotoQuery( " p.id , p.title, p.createDate, p.href, u.userId, u.loginName, u.trueName, p.summary " ) qry.orderType = 2 #viewCount desc hot_photo_list = qry.query_map(10) cache.put(cache_key, hot_photo_list) request.setAttribute("hot_photo_list", hot_photo_list)
def photo(self): qry = PhotoQuery(""" p.photoId, p.title, p.createDate, p.lastModified, p.href, u.loginName, u.userIcon, u.trueName, sc.name """) userId = request.getParameter("userId") if(request.getParameter("userId") != None): qry.userId = int(userId) request.setAttribute("showType", "user") qry.orderType = 0 result = qry.query_map(20) #print "result = ", result #return for a in result: str = a['lastModified'] str = CommonUtil.rssDateFormat(str) a['lastModifiedString'] = str request.setAttribute("photo_list", result) response.setContentType("text/xml; charset=UTF-8") return "/WEB-INF/ftl/site_rss_photo.ftl"
def genernate_photo_content(self, webpart): cache_key = "unit" + str(self.unit.unitId) + "_" + str( webpart.getUnitWebpartId()) content = cache.get(cache_key) if content != None: request.setAttribute(cache_key, content) return map = HashMap() qry = PhotoQuery( " p.photoId, p.title, p.createDate, p.href, u.userId, u.loginName, u.nickName, p.summary " ) qry.unitId = self.unit.unitId photo_list = qry.query_map(6) map.put("photo_list", photo_list) map.put("unit", self.unit) map.put("webpart", webpart) map.put("UnitRootUrl", self.unitRootUrl) map.put("UserUrlPattern", request.getAttribute("UserUrlPattern")) content = self.templateProcessor.processTemplate( map, "/WEB-INF/unitspage/" + self.templateName + "/photo.ftl", "utf-8") request.setAttribute(cache_key, content) cache.put(cache_key, content)
def execute(self): self.params = ParamUtil(request) self.loginName = request.getAttribute("loginName") title = self.params.safeGetStringParam("title") if title != "": request.setAttribute("title", title) # 解析 uri. if self.parseUri() == False: return self.sendNotFound(self.uri) # 得到要工作室主人, 并验证用户状态. self.user = user_svc.getUserByLoginName(self.loginName) request.setAttribute("user", self.user) request.setAttribute("loginUser", self.loginUser) #print "self.user = "******"loginUser", self.loginUser) # 创建分页对象 pager = self.params.createPager() pager.setPageSize(18) qry = PhotoQuery( """ p.photoId, p.title, p.createDate, p.lastModified, p.href, p.commentCount,p.viewCount, p.userStaple, u.nickName, u.loginName, u.userIcon, stap.title as stapleTitle """) qry.userId = self.user.userId qry.isPrivateShow = None if self.categoryId != 0: qry.userStapleId = self.categoryId photoStaple = photoStapleService.findById(self.categoryId) if photoStaple != None: request.setAttribute("photoStaple", photoStaple) #print "userStapleId = ", userStapleId pager.totalRows = qry.count() pager.itemName = u"图片" pager.itemUnit = u"张" qry.orderType = 0 result = qry.query_map(pager) request.setAttribute("photo_list", result) request.setAttribute("pager", pager) hql = """SELECT new Map(p.skin as skin) FROM Page p WHERE p.name = 'index' and p.objId = :userId and p.objType = 1 """ pageSkin = Command(hql).setInteger("userId", self.user.userId).first() # 构造页面数据,由于页面不是在数据库存在的,这里的数据是虚拟数据. #pages : [{id: ${page.pageId}, title: '${user.blogName!?js_string}', layoutId: ${page.layoutId!0} }], page = { "pageId": 0, "layoutId": 2, # 固定是布局2 "isSystemPage": "true", "owner": "user", "title": "", "skin": pageSkin["skin"] } request.setAttribute("page", page) self.page = self.getUserProfilePage(self.user) if self.page.customSkin != None: customSkin = JSONObject.parse(self.page.customSkin) request.setAttribute("customSkin", customSkin) # 构造widgets . widgets = [{ "id": "1", "pageId": 0, "columnIndex": 1, "title": u"个人档案", "module": "profile", "ico": "", "data": "" }, { "id": "2", "pageId": 0, "columnIndex": 1, "title": u"相册分类", "module": "photo_cate", "ico": "", "data": "" }, { "id": "placerholder1", "pageId": 0, "columnIndex": 2, "title": "", "module": "placeholder", "ico": "", "data": "" }] request.setAttribute("widgets", widgets) request.setAttribute("widget_list", widgets) response.setContentType("text/html; charset=UTF-8") return "/WEB-INF/user/default/user_photos.ftl"
def execute(self): #需要添加到内容:当前用户的首页skin,当前用户的用户对象,当前用户是否登录过. writer = response.getWriter() photoStapleService = __jitar__.getPhotoStapleService() self.params = ParamUtil(request) userStapleId = self.params.safeGetIntParam("userStapleId") loginName = request.getAttribute("loginName") if (loginName == None or loginName == ''): writer.write(u"没有该用户。") return # 加载当前用户对象. user = __jitar__.userService.getUserByLoginName(loginName) request.setAttribute("user", user) if self.canVisitUser(user) == False: return self.ACCESS_ERROR # loginUser 对象来自基类 BaseAdminAction . request.setAttribute("loginUser", self.loginUser) # 创建分页对象 pager = self.params.createPager() pager.setPageSize(6) qry = PhotoQuery(""" p.photoId, p.title, p.createDate, p.lastModified, p.href, p.commentCount,p.viewCount, p.userStaple, u.nickName, u.loginName, u.userIcon, stap.title as stapleTitle """) qry.userId = user.userId qry.isPrivateShow = None if userStapleId != 0 : qry.userStapleId = userStapleId photoStaple = photoStapleService.findById(userStapleId) if photoStaple != None: request.setAttribute("photoStaple",photoStaple) #print "userStapleId = ", userStapleId pager.totalRows = qry.count() pager.itemName = u"图片" pager.itemUnit = u"张" qry.orderType = 0 result = qry.query_map(pager) request.setAttribute("photo_list",result) request.setAttribute("pager",pager) hql = """SELECT new Map(p.skin as skin) FROM Page p WHERE p.name = 'index' and p.objId = :userId and p.objType = 1 """ pageSkin = Command(hql).setInteger("userId", user.userId).first() # 构造页面数据,由于页面不是在数据库存在的,这里的数据是虚拟数据. #pages : [{id: ${page.pageId}, title: '${user.blogName!?js_string}', layoutId: ${page.layoutId!0} }], page = { "pageId":0, "layoutId":2, # 固定是布局2 "isSystemPage" : "true", "owner" : "user", "title" :"", "skin":pageSkin["skin"] } request.setAttribute("page", page) self.page = self.getUserProfilePage(user) if self.page.customSkin != None: customSkin = JSONValue.parse(self.page.customSkin) request.setAttribute("customSkin", customSkin) # 构造widgets . widgets = [ {"id": "1", "pageId":0, "columnIndex":1,"title":u"个人档案","module":"profile", "ico":"", "data":""} ,{"id": "2", "pageId":0, "columnIndex":1,"title":u"相册分类","module":"photo_cate", "ico":"", "data":""} ,{"id": "placerholder1", "pageId":0, "columnIndex":2,"title":"","module":"placeholder", "ico":"", "data":""} ] request.setAttribute("widgets", widgets) request.setAttribute("widget_list", widgets) response.setContentType("text/html; charset=UTF-8") return "/WEB-INF/user/default/user_photos.ftl"
def get_hot_photo_list(self): qry = PhotoQuery(""" p.photoId, p.title,u.loginName """) qry.orderType = PhotoQuery.ORDER_TYPE_VIEWCOUNT_DESC hot_photo_list = qry.query_map(20) request.setAttribute("hot_photo_list", hot_photo_list)
def get_hot_photo_list(self): qry = PhotoQuery(""" p.photoId, p.title,u.loginName """) qry.sysCateId = int(self.categoryId) qry.orderType = 2 # viewCount DESC hot_photo_list = qry.query_map(20) request.setAttribute("hot_photo_list", hot_photo_list)