Beispiel #1
0
    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
Beispiel #2
0
 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"
Beispiel #3
0
    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"