Пример #1
0
    def post(self, topic_id=None):
        
        if not topic_id:
            self.about(404)
        
        topic = fetch_cached_board_topic(topic_id)
        if not topic:
            self.about(404)
        node = topic.node
        people = self.current_user
        
        comment_schema = BoardCommentForm(self)
        comment_content = self.get_argument('comment_content', '')
        if comment_schema.validate():
            topic_id = comment_schema.params.get('topic_id')
            topic_url = comment_schema.params.get('topic_url')
            comment_content = comment_schema.params.get('comment_content')
            
            comment = BoardComment()
            comment.content = comment_content
            topic = fetch_cached_board_topic(topic_id)
            comment.topic = topic
            comment.people = people
            
            comment.save()
            topic.add_comment(comment)
            fetch_cached_board_topic(topic.id, reflush=True)
            
            comment_content = ''
            return self.redirect(topic_url)
        else:
            comment_content_error = comment_schema.form_errors.get('comment_content')
            #node_list = fetch_cached_board_nodelist()
            #limit = PageMaxLimit
            #total_pages = topic.comment_count/limit
            #last_page = topic.comment_count  % limit
            #if last_page > 0:
            #    total_pages += 1
            #pagination = Pagination(page, total_pages)
            #page = self.get_argument("page", "1")
            #page = string2int(page)
            #if page < 1:
            #    page = 1
            #offset = (page-1) * PageMaxLimit
            #comments = topic.get_comments(limit=limit, offset=offset)
            #comment_content = comment_schema.params.get('comment_content')
            #return self.render("board/topic.html", timeover=timeover,  topic=topic, node=node, node_list=node_list,
            #       xsrf_token=self.xsrf_token, pagination=pagination, comment_list=comments, topic_has_voted=topic_has_voted, topic_can_edit=topic_can_edit,
            #       comment_content_error=comment_content_error, comment_content=comment_content)

        return self._get_topic(topic_id, comment_content_error=comment_content_error, comment_content=comment_content)
Пример #2
0
  def post(self, tag_name=None):
      people = self.current_user
      if self.current_user == None:
          return dict(result='redirect', url='/login')
      
      topic_id = self.get_argument('id', None)
      dir = self.get_argument('dir', None)
  
      topic = fetch_cached_board_topic(topic_id)
  
  
      if topic.people.id != people.id:
          #result = json.dumps(dict(result='error', info='people is the author'))
          return dict(result='error', info='people is the author')
  
      if BoardTopicVoter.has_voted(people.id, topic.id):
          #result = json.dumps(dict(result='error', info='topic has voted'))
          return dict(result='error', info='topic has voted')
      
      try:
          voter = BoardTopicVoter()
          voter.topic_id = topic.id
          voter.member_id = people.id
          voter.save()
          topic.add_voter(voter)
          fetch_cached_news_topic(topic.id, reflush=True)
 
          return dict(result='ok', vote=topic.up_vote+1)
          
      except OperationError, err:
          return dict(result='error', info='not vid')
Пример #3
0
    def get(self):
        offset = self.get_argument("offset", 0)
        limit = PageMaxLimit
        action = self.get_argument("action", None)
        node_list = fetch_cached_board_nodelist()

        if action == "delete":
            topic_id = self.get_argument("topic_id", None)
            if not topic_id:
                return about(404)
            topic = fetch_cached_board_topic(topic_id)
            deltopic = BoardTopicDeleted()

            deltopic.id = topic.id
            deltopic.people = topic.people
            deltopic.content = topic.content
            deltopic.more_content = topic.more_content
            deltopic.images = topic.images
            deltopic.video_urls = topic.video_urls
            deltopic.attach_urls = topic.attach_urls
            deltopic.logo = topic.logo
            deltopic.up_vote = topic.up_vote
            deltopic.down_vote = topic.down_vote
            deltopic.comment_count = topic.comment_count
            deltopic.create_time = topic.create_time
            deltopic.update_time = topic.update_time
            deltopic.node = topic.node
            deltopic.tags = topic.tags
            deltopic.save()
            tid = topic.id
            topic.delete()
            fetch_cached_board_topic(tid, reflush=True)
            return self.redirect("/admin/board/topic")
        elif action == "list":

            node_name = self.get_argument("node", None)
            node = BoardNode.get_by_name(node_name)
            if not node:
                return about(404)
            topic_list = BoardTopic.get_last_node_topics(node, limit=limit, offset=offset)
            return self.render("/admin/board_topic_list.html", topic_list=topic_list, node_list=node_list)

        topic_list = BoardTopic.get_last_topics(limit=limit, offset=offset)
        return self.render("/admin/board_topic_list.html", topic_list=topic_list, node_list=node_list)
Пример #4
0
 def get(self):
     tid = self.get_argument('topic_id', None)
     if not tid:
         return self.write('')
     topic = fetch_cached_board_topic(tid)
     page = self.get_argument('page', 0)
     
     limit = PageMaxLimit
     start = string2int(page) * limit
     
     if topic:
         comment_list = topic.get_comments(limit=limit, offset=start)
         return self.render('board/comments.html', topic=topic, comment_list=comment_list, timeover=timeover)
     else:
         return self.write('')
Пример #5
0
    def get(self, topic_id=None, comment_content_error=None, comment_content=''):
        if not topic_id:
            self.about(404)
        
        topic = fetch_cached_board_topic(topic_id)
        topic_more_content = fetch_cached_board_topic_morecontent(topic_id)
        if not topic:
            self.about(404)
        node = topic.node
    
        topic_has_voted = False
        people_id = None
        people = None
        page = self.get_argument("page", "1")
        page = string2int(page)
        if page < 1:
            page = 1
    
        if people_id:
            topic_has_voted = topic.has_voted(people_id)
        limit = PageMaxLimit
        offset = (page-1) * PageMaxLimit
        comments = topic.get_comments(limit=limit, offset=offset)
        total_pages = topic.comment_count/limit
        last_page = topic.comment_count  % limit
        if last_page > 0:
            total_pages += 1
     

    
        node_list = fetch_cached_board_nodelist()
        to = timeout(topic.create_time)
        topic_can_edit = False
        #if people and to < 600 and topic.is_author(people):
        #    topic_can_edit = True
        
        pagination = Pagination(page, total_pages)
        #return self.write(topic_more_content)
        self.render("board/topic.html", timeover=timeover,  topic=topic, topic_more_content=topic_more_content, node=node, node_list=node_list,
                   xsrf_token=self.xsrf_token, pagination=pagination, comment_list=comments, topic_has_voted=topic_has_voted, topic_can_edit=topic_can_edit,
                   comment_content_error=comment_content_error, comment_content=comment_content)
Пример #6
0
 def get(self):
     
     
     page = self.get_argument('page', '1')
     
     page_no = string2int(page, -1)
     if page_no == -1:
         self.about(404)
     if page_no < 1:
         page_no = 1
     offset = (page_no-1) * PageMaxLimit*2
     
     node_list = fetch_cached_board_nodelist()
     topics = BoardTopic.get_last_topics(limit=PageMaxLimit, offset=offset)
     topic_list = []
     for t in topics:
         topic = fetch_cached_board_topic(t.id)
         topic_list.append(topic)
     now = time.time()
     
     self.render("board/index.html", timeover=timeover, topic_list=topic_list, topic_count=len(topic_list), node_list=node_list, now_time=now,
                 page=page_no, offset=offset)
Пример #7
0
 def get(self, node_name=None):
     if not node_name:
         self.about(404)
     
     
     node = BoardNode.get_by_name(node_name)
     if not node:
         self.about(404)
     
     
     page = self.get_argument('page', '1')
     
     page_no = string2int(page, -1)
     if page_no == -1:
         self.about(404)
     if page_no < 1:
         page_no = 1
     offset = (page_no-1) * PageMaxLimit
     
     node_list = fetch_cached_board_nodelist()
     topics = BoardTopic.get_last_node_topics(node, limit=PageMaxLimit, offset=offset)
     topic_list = []
     for t in topics:
         topic = fetch_cached_board_topic(t.id)
         topic_list.append(topic)
     now = time.time()
     total_count = BoardTopic.get_node_topics_count(node)
     total_pages = total_count / PageMaxLimit
     last_page = total_count  % PageMaxLimit
     if last_page > 0:
         total_pages += 1
         
     pagination = Pagination(page_no, total_pages)
     
     self.render("board/node.html", timeover=timeover, topic_list=topic_list, topic_count=len(topic_list), node_list=node_list, node = node, now_time=now,
                 pagination=pagination, offset=offset)