Ejemplo n.º 1
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
Ejemplo n.º 2
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"
Ejemplo n.º 3
0
 def subject_options(self):
   gradeId = self.params.safeGetStringParam("gradeId")
   if gradeId == None or gradeId == "":
     qry = Command(""" SELECT distinct metaSubject as metaSubject FROM Subject """)
   else:
     gradeId = gradeId[0] + "000"
     qry = Command(""" SELECT metaSubject as metaSubject FROM Subject Where metaGradeId =""" + gradeId)
   subjectList = qry.open()
   request.setAttribute("subject_list", subjectList)
   
   return "/WEB-INF/ftl/admin/subject_options_ajax.ftl"
Ejemplo n.º 4
0
 def user_list123(self):
     hql = """SELECT new Map(u.userId as userId, u.loginName as loginName, u.trueName as trueName)
      FROM User u
      ORDER BY u.userId """
     user_list = Command(hql).open(6)
     request.setAttribute("userList", user_list)
     return "/WEB-INF/ftl/admin/Admin_Stat_List_1.ftl"
Ejemplo n.º 5
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]
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    def execute(self):
        self.config = self.cfg_svc.getConfigure()

        # 群组
        self.groupList()
        user_list = None
        singleuser = self.params.getIntParam("singleuser")  #1 用户单选 2 用户多选
        if singleuser == None:
            singleuser = 1

        closewindow = self.params.getIntParam("closewindow")
        if closewindow == None:
            closewindow = 0
        groupids = self.params.getStringParam("groupids")
        if groupids == None:
            closewindow = 0
        else:
            if closewindow == 1:
                hql = """SELECT new Map(u.userId as userId,u.gender, u.loginName as loginName, u.trueName as trueName) FROM User u Where u.userId In(Select gm.userId from GroupMember gm  Where gm.groupId In(""" + groupids + """))"""
                user_list = Command(hql).open()

        request.setAttribute("closewindow", closewindow)
        request.setAttribute("user_list", user_list)
        inputUser_Id = self.params.getStringParam("inputUser_Id")
        inputUserName_Id = self.params.getStringParam("inputUserName_Id")
        inputLoginName_Id = self.params.getStringParam("inputLoginName_Id")
        request.setAttribute("singleuser", singleuser)
        request.setAttribute("inputUser_Id", inputUser_Id)
        request.setAttribute("inputUserName_Id", inputUserName_Id)
        request.setAttribute("inputLoginName_Id", inputLoginName_Id)
        # 返回
        response.contentType = "text/html; charset=UTF-8"
        return "/WEB-INF/ftl/searchUserList1.ftl"
Ejemplo n.º 8
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]
Ejemplo n.º 9
0
 def save_post(self):
     cmd = self.params.safeGetStringParam("cmd")
     guids = self.params.safeGetIntValues("guid")
     for g in guids:
         user = self.userService.getUserById(g)
         if user != None:
             if cmd == "delete":
                 #检查用户是否创建了群组:
                 sql = "SELECT COUNT(*) AS JoinedCount FROM Group WHERE createUserId=" + str(
                     user.userId)
                 JoinedCount = Command(sql).int_scalar()
                 if JoinedCount > 0:
                     response.getWriter().println(
                         u"用户【" + user.trueName + u"(" + user.loginName +
                         u")】还有创建的协作组没有处理,请先转让该用户创建的协作组。")
                     return
                 self.userService.deleteUser(user.userId)
             elif cmd == "audit":
                 user.setUserStatus(0)
                 self.userService.updateUser(user, False)
                 self.userService.updateUserStatus(user,
                                                   User.USER_STATUS_NORMAL)
             else:
                 self.addActionError(u"无效的命令。")
                 return self.ERROR
Ejemplo n.º 10
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()
   
Ejemplo n.º 11
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
Ejemplo n.º 12
0
    def subject_options(self):
        gradeId = self.params.safeGetIntParam("gradeId")
        if gradeId == None or gradeId == 0:
            qry = Command(
                """ SELECT distinct metaSubject as metaSubject FROM Subject """
            )
        else:
            gradeId = CommonUtil.convertRoundMinNumber(gradeId)
            #gradeId=gradeId[0]+"000"
            qry = Command(
                """ SELECT metaSubject as metaSubject FROM Subject Where metaGradeId ="""
                + str(gradeId))
        subjectList = qry.open()
        #print subjectList
        request.setAttribute("subject_list", subjectList)

        return "/WEB-INF/ftl/admin/subject_options_ajax.ftl"
Ejemplo n.º 13
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])
Ejemplo n.º 14
0
    def main(self):
        qry = UserQuery(
            """ u.userId, u.loginName, u.userIcon, u.gender, u.trueName, u.email, u.blogName, u.blogIntroduce, 
                        u.myArticleCount, u.otherArticleCount, u.historyMyArticleCount, u.historyOtherArticleCount, u.visitCount,u.resourceCount,
                        u.commentCount,u.photoCount,u.subjectId, u.gradeId, u.positionId,
                        subj.subjectName, grad.gradeName, unit.unitTitle, sc.name
             """)
        qry.userStatus = None
        qry.loginName = self.loginUser.loginName
        users = qry.query_map()
        if users.size() == 0:
            response.sendRedirect("../login.jsp")

        user = users[0]
        request.setAttribute("user", user)

        # TODO: 下面的查询用 XxxQuery 改写, 现在统计不对.
        hql = """ select count(*) as groupCount
                          FROM GroupMember gm
                          where gm.userId = """ + str(
            self.loginUser.userId) + """
                         """
        cmd = Command(hql)
        groupCount = cmd.int_scalar()
        request.setAttribute("groupCount", groupCount)

        hql = """ select count(*) as messageCount
                          FROM Message m
                          where m.receiveId = """ + str(
            self.loginUser.userId) + """
                         """
        cmd = Command(hql)
        messageCount = cmd.int_scalar()
        request.setAttribute("messageCount", messageCount)

        hql = """ select count(*) as friendCount
                          FROM Friend f
                          where f.userId = """ + str(
            self.loginUser.userId) + """
                         """
        cmd = Command(hql)
        friendCount = cmd.int_scalar()
        request.setAttribute("friendCount", friendCount)

        return "/WEB-INF/ftl/user/manage_main.ftl"
Ejemplo n.º 15
0
 def execute(self):
     self.loginName = request.getAttribute("loginName")
     # 加载当前用户对象.
     self.user = user_svc.getUserByLoginName(self.loginName)
     request.setAttribute("user", self.user)
     
     pager = self.params.createPager()  
     qry = ActionQuery(""" act.title, act.createDate, act.actionId, act.ownerId, act.ownerType, act.createUserId, act.actionType,
                           act.description, act.userLimit, act.startDateTime,act.finishDateTime, act.attendLimitDateTime, act.place,
                           act.status, act.visibility, act.attendCount
                         """)
     qry.ownerType = "user"
     qry.status = 0
     qry.createUserId = self.user.userId
     pager.setPageSize(16)        
     pager.itemName = u"活动"
     pager.itemUnit = u"个"
     action_list = qry.query_map(pager)
     pager.totalRows = action_list.size()
     
     #print "group_list = " , group_list
     request.setAttribute("action_list", action_list)        
     request.setAttribute("pager",pager)        
     hql = """SELECT p.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()
     #print "pageSkin = ", pageSkin
     if pageSkin == None or pageSkin == "": pageSkin = "skin1"
     
     # 构造页面数据,由于页面不是在数据库存在的,这里的数据是虚拟数据.
     #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
             }        
     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": "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_actions.ftl"
Ejemplo n.º 16
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()
Ejemplo n.º 17
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()
Ejemplo n.º 18
0
    def execute(self):
        request.setAttribute("ChatRoomName", u"聊天室")
        if self.loginUser == None:
            return
        userName = self.loginUser.trueName
        if userName == None:
            userName = self.loginUser.loginName
        userId = self.loginUser.userId
        roomId = self.params.safeGetIntParam("roomId")
        if roomId == None or roomId == 0:
            roomId = 1
        qry = Command(
            """ SELECT new Map(userId as userId,userName as userName) FROM ChatUser Where isLeave=0 and roomId="""
            + str(roomId) + """ ORDER BY sayDate desc """)
        userList = qry.open()

        qry = Command(
            " SELECT new Map(colorName as colorName,colorValue as colorValue) FROM ChatColor "
        )
        colorList = qry.open()
        #得到自己的颜色

        chtuser = self.userchat_svc.getChatUser(roomId, userId)
        if chtuser == None:
            chatUser = ChatUser()
            chatUser.userId = userId
            chatUser.roomId = roomId
            chatUser.isLeave = False
            chatUser.isActived = True
            chatUser.userName = userName
            self.userchat_svc.saveChatUser(chatUser)
        elif chtuser.isActived == False:
            self.userchat_svc.updateChatUserIsLeave(roomId, userId, False)

        chtuser = self.userchat_svc.getChatUser(roomId, userId)
        mycolor = chtuser.fontColor
        if mycolor == None or mycolor == "":
            mycolor = "#000000"
        request.setAttribute("mycolor", mycolor)
        request.setAttribute("roomId", roomId)
        request.setAttribute("userList", userList)

        request.setAttribute("colorList", colorList)
        return "/WEB-INF/ftl/chat/manage.ftl"
Ejemplo n.º 19
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"
Ejemplo n.º 20
0
 def query_group_activity_list(self):
     # 活跃度算法 (g.userCount + g.articleCount + g.topicCount + g.resourceCount) / 10
     hql = """ select new Map( g.groupId as groupId, g.groupTitle as groupTitle, g.parentId, (g.userCount + g.articleCount + g.topicCount + g.resourceCount) / 10 as totalCount)
                   FROM Group g
                   where g.groupState = 0
                   ORDER BY (g.userCount + g.articleCount + g.topicCount + g.resourceCount) DESC
                  """
     cmd = Command(hql)
     group_activity_list = cmd.open(25)
     request.setAttribute("group_activity_list", group_activity_list)
Ejemplo n.º 21
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])
Ejemplo n.º 22
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])
Ejemplo n.º 23
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
Ejemplo n.º 24
0
    def school_link(self):
        cache_key = "school_show"
        school_link = cache.get(cache_key)
        if school_link == None:
            # 机构风采 objectType = 100, objectId = 1.
            # cmd = Command(""" FROM Link WHERE objectType = 100 AND objectId = 1 ORDER BY linkId DESC """)
            cmd = Command(" FROM Unit Where parentId <> 0 ORDER BY rank DESC ")
            school_link = cmd.open(10)
            cache.put(cache_key, school_link)

        request.setAttribute("school_link", school_link)
 def execute(self):
     self.loginName = request.getAttribute("loginName")          
     writer = response.getWriter()                
     # 加载当前用户对象.
     self.user = user_svc.getUserByLoginName(self.loginName)
     request.setAttribute("user", self.user)
     hql = """SELECT p.skin
          FROM Page p 
          WHERE p.name = 'index' and p.objId = :userId and p.objType = 1
          """ 
     pageSkin = Command(hql).setInteger("userId", self.user.userId).scalar()
     #print "pageSkin = ", pageSkin
     if pageSkin == None or pageSkin == "": pageSkin = "skin1"
     
     # 构造页面数据,由于页面不是在数据库存在的,这里的数据是虚拟数据.
     #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
             }        
     request.setAttribute("page", page)
     self.page = self.getUserProfilePage(self.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": "placerholder1", "pageId":0, "columnIndex":2,"title":"","module":"placeholder", "ico":"", "data":""}
               ]
     request.setAttribute("widgets",widgets)
     request.setAttribute("widget_list",widgets)
     #得到当前用户的创建的活动
     pager = self.params.createPager()
     qry = PrepareCourseMemberQuery(""" pc.prepareCourseId,pc.title, pc.createDate,pc.memberCount,pc.articleCount,pc.resourceCount,pc.actionCount,pc.topicCount,pc.topicReplyCount """)
     qry.status = 0
     qry.userId = self.user.userId
     pager.setPageSize(16)        
     pager.itemName = u"备课"
     pager.itemUnit = u"个"
     course_list = qry.query_map(pager)
     pager.totalRows = course_list.size()
     request.setAttribute("course_list", course_list)
     request.setAttribute("pager", pager)
     response.setContentType("text/html; charset=UTF-8")
     return "/WEB-INF/user/default/user_joinedpreparecourse_list.ftl"
Ejemplo n.º 26
0
    def execute(self):
        accessControlService = __spring__.getBean("accessControlService")
        cmd = request.getParameter("cmd")
        isSystemAdmin = accessControlService.isSystemAdmin(self.loginUser)
        isChannelSystemAdminList = accessControlService.getAllAccessControlByUserAndObjectType(
            self.loginUser, 11)
        isChannelUserAdminList = accessControlService.getAllAccessControlByUserAndObjectType(
            self.loginUser, 12)
        isChannelContentAdminList = accessControlService.getAllAccessControlByUserAndObjectType(
            self.loginUser, 13)

        if isSystemAdmin == False and len(
                isChannelSystemAdminList) < 1 and len(
                    isChannelSystemAdminList) < 1 and len(
                        isChannelSystemAdminList) < 1:
            self.addActionError(u"你无权管理频道。")
            return self.ERROR

        if cmd == "menu":

            channel_list = None
            #判断是否是系统管理员

            if isSystemAdmin:
                request.setAttribute("admin_type", "admin")
                channel_list = self.channelPageService.getChannelList()
            else:
                # 得到当前用户可以管理的频道列表
                qry = Command(
                    "SELECT DISTINCT objectId as objectId FROM AccessControl Where userId = "
                    + str(self.loginUser.userId) +
                    " And (objectType = 11 or objectType = 12 or objectType = 13) Order By objectId ASC"
                    "")
                ChannelID = qry.open()
                channel_list = []
                for id in ChannelID:
                    channel = self.channelPageService.getChannel(id)
                    channel_list.append(channel)
                if len(channel_list) > 0:
                    request.setAttribute("admin_type", "channeladmin")
                else:
                    request.setAttribute("admin_type", "")

            request.setAttribute("channel_list", channel_list)
            return "/WEB-INF/ftl/channel/menu.ftl"
        elif cmd == "main":
            return "/WEB-INF/ftl/channel/main.ftl"
        elif cmd == "head":
            return "/WEB-INF/ftl/channel/head.ftl"
        else:
            return "/WEB-INF/ftl/channel/index.ftl"
Ejemplo n.º 27
0
    def get_subject_list(self):

        #self.subjectService = __jitar__.subjectService
        # 另外一种写法,数据显示存在问题
        #cachekey_grade = "grade"
        #GradeList = None#self.cache.get(cachekey_grade)
        #if GradeList == None:
        #    GradeList = self.subjectService.getGradeListOnlyIsGrade()
        #    self.cache.put(cachekey_grade, GradeList)

        #SubjectArray = ArrayList()
        #for g in GradeList:
        #    cachekey = "subject" + str(g.gradeId)
        #    SubjectOfGrade = self.subjectService.getSubjectByGradeId(g.gradeId)
        #    SubjectArray.add({"grade" : g, "subject": SubjectOfGrade})
        #request.setAttribute("SubjectArray", SubjectArray)

        cache_key1 = "metaSubject"
        cache_key2 = "metaGrade"
        metaSubject = self.cache.get(cache_key1)
        MetaGrade = self.cache.get(cache_key2)
        if metaSubject == None:
            #先得到年级
            subjectService = __spring__.getBean("subjectService")
            qry = Command(
                """ SELECT gradeId, gradeName FROM Grade Where isGrade = true Order By gradeId DESC"""
            )
            MetaGrade = qry.open()
            self.cache.put(cache_key2, MetaGrade)
            #print "meta_Grade:", MetaGrade
            metaSubject = ArrayList()
            for grade in MetaGrade:
                subj = subjectService.getSubjectByGradeId(int(grade[0]))
                m = ArrayList()
                if subj != None:
                    for sj in range(0, subj.size()):
                        m.add(subj[sj].metaSubject)
                    metaSubject.add({
                        "gradeName": grade[1],
                        "gradeId": grade[0],
                        "metaSubject": m
                    })

            self.cache.put(cache_key1, metaSubject)

        request.setAttribute("metaGrade", MetaGrade)
        request.setAttribute("meta_Grade", MetaGrade)
        request.setAttribute("SubjectNav", metaSubject)
Ejemplo n.º 28
0
 def GenSubjectNav(self):
     strFile = request.getServletContext().getRealPath("/")
     strFile = URLDecoder.decode(strFile, "utf-8")
     strSubjectFile = strFile + "html" + File.separator
     file = File(strSubjectFile)
     if file.exists() == False:
         file.mkdirs()
     #创建学科导航
     strSubjectFile = strSubjectFile + "subject_nav.html"
     file = File(strSubjectFile)
     #先得到年级
     subjectService = __spring__.getBean("subjectService")
     qry = Command(
         " SELECT DISTINCT metaGrade.gradeId FROM Subject Order By metaGrade.gradeId ASC"
     )
     mGradeId = qry.open()
     MetaGrade = ArrayList()
     metaSubject = ArrayList()
     for grade in mGradeId:
         mGrade = subjectService.getGrade(int(grade))
         MetaGrade.add(mGrade)
         subj = subjectService.getSubjectByGradeId(int(grade))
         m = ArrayList()
         if subj != None:
             for sj in range(0, subj.size()):
                 m.add(subj[sj].metaSubject)
             metaSubject.add({
                 "gradeName": mGrade.gradeName,
                 "gradeId": grade,
                 "metaSubject": m
             })
     map = HashMap()
     map.put("metaGrade", MetaGrade)
     map.put("meta_Grade", MetaGrade)
     map.put("SubjectNav", metaSubject)
     templateProcessor = __spring__.getBean("templateProcessor")
     str = templateProcessor.processTemplate(
         map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8")
     try:
         fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
         fw.flush()
         fw.write(str)
         fw.close()
     finally:
         file = None
         fw = None
Ejemplo n.º 29
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"
Ejemplo n.º 30
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"