Пример #1
0
 def updateGroupResourceCategoryId(self, category):
   cmd = Command(""" UPDATE GroupResource SET groupCateId = NULL
       WHERE groupId = :groupId AND groupCateId = :groupCateId """)
   cmd.setInteger("groupId", self.group.groupId)
   cmd.setInteger("groupCateId", category.categoryId)
   count = cmd.update()
   
Пример #2
0
 def get_childs(self, group):
     hql = """ FROM Group WHERE parentId = :parentId ORDER BY id DESC """
     cmd = Command(hql)
     cmd.setInteger("parentId", group.groupId)
     group_list = cmd.open(-1)
     request.setAttribute("group_list", group_list)
     return
Пример #3
0
 def getUserById(self, userId):
   cmd = Command(""" FROM User u WHERE u.userId = :userId """)
   cmd.setInteger("userId", userId)
   user_list = cmd.open(1)
   if user_list == None or user_list.size() == 0:
     return None
   return user_list[0]
Пример #4
0
 def getGroupById(self, groupId):
     cmd = Command(""" FROM Group g WHERE g.groupId = :groupId """)
     cmd.setInteger("groupId", groupId)
     group_list = cmd.open(1)
     if group_list == None or group_list.size() == 0:
         return None
     return group_list[0]
Пример #5
0
    def get_comment_star(self):
        # 注意:如果没有记录,返回的结果是 StarCount 为 Null,StarNumber 为 0,所以 commentStar 永远不会为 None
        sql = """ SELECT SUM(star) AS StarCount, COUNT(star) AS StarNumber FROM Comment WHERE objId = :articleId """
        cmd = Command(sql)
        cmd.setInteger("articleId", self.article.articleId)
        commentStar = cmd.first()
        if commentStar == None:
            return
        else:
            if commentStar[0] == None:
                return
            else:
                StarCount = int(commentStar[0])

            if commentStar[1] == None:
                return
            else:
                StarNumber = int(commentStar[1])
            if StarNumber < 1:
                return

            AveStar = StarCount / StarNumber
            request.setAttribute("StarCount", StarCount)
            request.setAttribute("StarNumber", StarNumber)
            request.setAttribute("AveStar", AveStar)
Пример #6
0
 def getArticleAndAuthor(self, articleId):
   cmd = Command("SELECT a, u FROM Article a, User u WHERE a.userId = u.userId AND a.articleId = :articleId")
   cmd.setInteger("articleId", articleId)
   list = cmd.open(1)
   if list == None or list.size() == 0:
     return None
   au = list[0]
   return ArticleAndUser(au[0], au[1])
Пример #7
0
 def deleteChannelCategory(self, resType, category):
     if category == None: return
     cmd = Command(
         " UPDATE " + resType +
         " SET channelCate = NULL,channelCateId = NULL WHERE channelId = :channelId AND channelCateId = :channelCateId "
     )
     cmd.setInteger("channelId", self.channel.channelId)
     cmd.setInteger("channelCateId", category.categoryId)
     count = cmd.update()
Пример #8
0
    def execute(self):
        params = ParamUtil(request)
        cmt_svc = __jitar__.getCommentService()
        writer = response.getWriter()
        if self.loginUser == None:
            writer.write(u"请先登录。")
            return
        userName = self.loginUser.trueName
        if userName == None:
            userName = self.loginUser.loginName
        title = params.getStringParam("title")
        objtype = params.getIntParam("objtype")
        aboutUserId = params.getIntParam("aboutUserId")
        objId = params.getIntParam("photoId")
        star = params.getIntParam("star")
        content = params.getStringParam("content")
        userIP = request.getHeader("x-forwarded-for")
        if userIP == None or userIP == "":
            userIP = request.getRemoteAddr()

        if title == "":
            writer.write(u"请输入标题。")
            return
        if content == "" or content == "<span></span>":
            writer.write(u"请输入评论内容。")
            return

        cmt = Comment()
        cmt.setTitle(title)
        cmt.setAboutUserId(aboutUserId)
        cmt.setIp(userIP)
        cmt.setUserName(userName)
        cmt.setUserId(self.loginUser.userId)
        cmt.setCreateDate(Date())
        cmt.setStar(star)
        cmt.setAudit(True)
        cmt.setContent(content)
        cmt.setObjId(objId)
        cmt.setObjType(objtype)
        cmt_svc.saveComment(cmt)

        # 评论计数器
        cmd = Command(
            """ UPDATE Photo SET commentCount = commentCount + 1 WHERE photoId = :photoId """
        )
        cmd.setInteger("photoId", objId)
        cmd.update()

        photoUser = params.getStringParam("photoUser")
        if request.getHeader("Referer") != None:
            response.sendRedirect(request.getHeader("Referer"))
            return
        request.setAttribute(
            "redUrl",
            photoUser + "/py/user_photo_show.py?photoId=" + str(objId))
        return "/WEB-INF/ftl/photo/PhotoComment_Success.ftl"
Пример #9
0
 def get_links(self, group):
     hql = """ FROM Link WHERE objectType = :objectType AND objectId = :objectId 
       ORDER BY linkId DESC """
     cmd = Command(hql)
     cmd.setInteger("objectType", OBJECT_TYPE_GROUP)
     cmd.setInteger("objectId", group.groupId)
     # 取出最新 5 个友情链接.
     link_list = cmd.open(5)
     request.setAttribute("link_list", link_list)
     return
Пример #10
0
 def getPhotoAndAuthor(self, photoId):
     cmd = Command(
         "SELECT p, u FROM Photo p, User u WHERE p.userId = u.userId AND p.photoId = :photoId"
     )
     cmd.setInteger("photoId", photoId)
     list = cmd.open(1)
     if list == None or list.size() == 0:
         return None
     pu = list[0]
     return PhotoAndUser(pu[0], pu[1])
Пример #11
0
 def getResourceAndAuthor(self, resourceId):
     cmd = Command(
         "SELECT r, u FROM Resource r, User u WHERE r.userId = u.userId AND r.resourceId = :resourceId"
     )
     cmd.setInteger("resourceId", resourceId)
     list = cmd.open(1)
     if list == None or list.size() == 0:
         return None
     ru = list[0]
     return ResourceAndUser(ru[0], ru[1])
Пример #12
0
    def list(self):
        pager = self.params.createPager()
        pager.itemName = u"机构链接"
        pager.itemUnit = u"个"

        # 计算总数.
        hql = """ SELECT COUNT(*) FROM Link 
         WHERE objectType = :objectType AND objectId = :objectId """
        cmd = Command(hql)
        cmd.setInteger("objectType", self.ObjectType_System)
        cmd.setInteger("objectId", self.ObjectId_School)
        pager.totalRows = cmd.int_scalar()

        # 获取当前页.
        hql = """ FROM Link 
         WHERE objectType = :objectType AND objectId = :objectId 
         ORDER BY linkId DESC """
        cmd = Command(hql)
        cmd.setInteger("objectType", self.ObjectType_System)
        cmd.setInteger("objectId", self.ObjectId_School)
        link_list = cmd.open(pager)

        request.setAttribute("link_list", link_list)
        request.setAttribute("pager", pager)

        #DEBUG: print "link_list = ", link_list
        return "/WEB-INF/ftl/admin/school_link_list.ftl"
Пример #13
0
 def updateChannelCateId(self, resType, category):
     # 得到该分类及其下级所有分类
     cmd = Command(
         "SELECT categoryId FROM Category WHERE itemType = :itemType")
     cmd.setString("itemType", self.itemType)
     cateIdList = cmd.open()
     for id in cateIdList:
         cate = self.categoryService.getCategory(id)
         if cate != None:
             catePath = CommonUtil.convertIntFrom36To10(
                 cate.parentPath) + str(id) + "/"
             cmd = Command(
                 " UPDATE " + resType +
                 " SET channelCate = :channelCate WHERE channelCateId = :channelCateId "
             )
             cmd.setString("channelCate", catePath)
             cmd.setInteger("channelCateId", id)
             count = cmd.update()
Пример #14
0
    def list(self):
        if self.login_user == None:
            self.writer.write("logon")
            return
        favUser = self.login_user.userId
        fav_list = self.favo_svc.getUFavoritesList(favUser)
        pager = self.createPager()
        if fav_list == None:
            pager.totalRows = 0
        else:
            pager.totalRows = fav_list.size()

        hql = """ from UFavorites Where favUser=:favUser ORDER BY favId DESC"""
        cmd = Command(hql)
        cmd.setInteger("favUser", favUser)
        fav_list = cmd.open(pager)
        request.setAttribute("pager", pager)
        request.setAttribute("fav_list", fav_list)
        return "/WEB-INF/ftl/user/fav_list.ftl"
Пример #15
0
    def execute(self):
        site_config = SiteConfig()
        site_config.get_config()

        param = ParamUtil(request)
        newsId = param.getIntParam("newsId")
        if newsId == None or newsId == "":
            return
        self.sub_svc = __jitar__.getSubjectService()

        news = self.sub_svc.getSiteNews(newsId)
        if news == None:
            return
        sql = """ Update SiteNews Set viewCount = viewCount + 1 Where newsId = :newsId """
        cmd = Command(sql)
        cmd.setInteger("newsId", newsId)
        cmd.update()
        request.setAttribute("news", news)
        response.setContentType("text/html; charset=UTF-8")
        return "/WEB-INF/ftl/show_news.ftl"
Пример #16
0
 def actionPost(self):
     ErrMsg = ""
     cmd = self.params.getStringParam("cmd")
     guids = self.params.safeGetIntValues("guid")
     if guids.size() < 1:
         self.addActionError(u"请先选择一个活动")
         self.addActionLink(u"返回", "myaction.py")
         return self.ERROR
     for actId in guids:
         action = self.act_svc.getActionByActionUserId(actId)
         if action.status != 0:
             ErrMsg = ErrMsg + u"<li>名为 " + action.title + u" 的活动不是一个正常状态。无法进行操作."
             continue
         if cmd == "attend":
             qry = """ UPDATE ActionUser Set status = 1 WHERE actionUserId = :actionUserId """
             command = Command(qry)
             command.setInteger("actionUserId", actId)
             command.update()
         if cmd == "quit":
             qry = """ UPDATE ActionUser Set status = 2 WHERE actionUserId = :actionUserId"""
             command = Command(qry)
             command.setInteger("actionUserId", actId)
             command.update()
         if cmd == "leave":
             qry = """ UPDATE ActionUser Set status = 3 WHERE actionUserId = :actionUserId """
             command = Command(qry)
             command.setInteger("actionUserId", actId)
             command.update()
     if ErrMsg == "": ErrMsg = u"操作已完成"
     self.addActionMessage(ErrMsg)
     self.addActionLink(u"返回", "myaction.py")
     return self.SUCCESS
Пример #17
0
    def execute(self):
        site_config = SiteConfig()
        site_config.get_config()

        photoId = self.params.getIntParam("photoId")

        photo = self.photo_svc.findById(photoId)
        request.setAttribute("photo", photo)
        #DEBUG print "photoId = ", photoId, ", photo = ", self.photo
        #print "===photo.sysCateId===:",photo.sysCateId
        if photo != None:
            if photo.sysCateId != None:
                category = self.cate_svc.getCategory(photo.sysCateId)
                request.setAttribute("category", category)
            # 更新访问计数
            cmd = Command(
                """ UPDATE Photo SET viewCount = viewCount + 1 WHERE photoId = :photoId """
            )
            cmd.setInteger("photoId", photo.photoId)
            cmd.update()

        return "/WEB-INF/ftl/showPhoto.ftl"
Пример #18
0
    def execute(self):
        photoService = __jitar__.getPhotoService()
        photoStapleService = __jitar__.getPhotoStapleService()
        self.params = ParamUtil(request)
        writer = response.getWriter()

        loginName = request.getAttribute("loginName")
        photoId = self.params.safeGetIntParam("photoId")
        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)

        # 得到照片对象
        photo = photoService.findById(photoId)
        if photo == None:
            self.addActionError(u"无法加载该照片。")
            return self.ERROR

        request.setAttribute("photo", photo)
        if photo.userStaple != None:
            photoStaple = photoStapleService.findById(photo.userStaple)
            request.setAttribute("photoStaple", photoStaple)

        cmd = Command(
            """ UPDATE Photo SET viewCount = viewCount + 1 WHERE photoId = :photoId """
        )
        cmd.setInteger("photoId", photo.photoId)
        cmd.update()

        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)

        qry = CommentQuery(
            """ cmt.content,cmt.createDate,cmt.star,cmt.title,u.loginName,u.userId,u.userIcon
                            """)
        qry.objType = 11
        qry.orderType = 3
        qry.objId = photo.photoId
        pager = self.params.createPager()
        pager.setPageSize(10)
        pager.totalRows = qry.count()
        pager.itemName = u"评论"
        pager.itemUnit = u"条"

        result = qry.query_map(pager)
        request.setAttribute("photo_comment_list", result)
        request.setAttribute("pager", pager)

        response.setContentType("text/html; charset=UTF-8")
        return "/WEB-INF/user/default/user_photo_show.ftl"