예제 #1
0
class PostInfo(CommentPostInfo):
    """Информация о посте"""
    def __init__(self, id, author, date, text):
        CommentPostInfo.__init__( self, id, author, date, text )
        self.replies = SortedDict() #комменты - ответы на пост
        #информация о кол-ве скрытых комментов
        self.hidden_replies_info = None
        self.hidden_replies_has_shown = False
        
        # прикрепленные картинки: список кортежей
        # (thumbnail_url, full_picture_url)
        self.images = []
        
        self.links = [] # список прикрепленных URL

    def get_hide_comments_url(self):
        if self.hidden_replies_info:
            return PostInfo.hidden_comments_url(self.id)
        return None
        
    @staticmethod
    def hidden_comments_url(post_id):
        return '-' + post_id

    def get_is_new(self):
        return self._is_new

    def set_is_new(self, value):
        self._is_new = value
        if value:
            for reply in self.replies:
                reply.is_new = True

    is_new = property( get_is_new, set_is_new, doc=u'Свойство-флаг новизны поста' )

    def __cmp__(self, other):
        if self.id == other.id and self.author == other.author and \
            self.date == other.date and self.text == other.text and self.replies == other.replies:
            return 0
        return 1

    def add_reply(self, comment):
        """
            comment_id - идентификатор поста-комментария
            comment - CommentPostInfo комментария
        """
        self.replies[comment.id] = comment

    def prepend_list_of_replies(self, comments_list):
        comments_list.reverse()
        for reply in comments_list:
            self.replies.insert( 0, reply.id, reply)

    def remove_all_hidden_replies(self):
        """Удаляет все скрыте комменты, т.е в случае если комментарием больше, чем 3,
         удаляются все комменты, кроме последних трех"""
        while len(self.replies) > 3:
            self.replies.pop(self.replies.keys()[0])
예제 #2
0
class GroupWall(object):
    def __init__(self):
        self.posts = SortedDict()

    def add_new_post(self, post):
        """
            post_id - идентификатор поста
            post - PostInfo комментария
        """
        self.posts[post.id] = post

    def check_for_new_posts_and_comments(self, wall):
        """Сравнивает текущее состояние стены с состоянием стены переданным через
         параметр wall. В случае, если состояния одинаковы, возвращает False иначе
         проставляет новым запиясям флаг is_new и возвращает True"""
        has_something_new = False
        for post_id, post in self.posts.iteritems():
            #проверка является ли пост новым
            if not wall.posts.has_key( post_id ):
                post.is_new = True
                has_something_new = True
            else:
                for reply_id, reply in post.replies.iteritems():
                    if not wall.posts[post_id].replies.has_key(reply_id):
                        reply.is_new = True
                        has_something_new = True
        return has_something_new

    def __cmp__(self, other):
        if self.posts == other.posts:
            return 0
        return 1
예제 #3
0
 def __init__(self, id, author, date, text):
     CommentPostInfo.__init__( self, id, author, date, text )
     self.replies = SortedDict() #комменты - ответы на пост
     #информация о кол-ве скрытых комментов
     self.hidden_replies_info = None
     self.hidden_replies_has_shown = False
     
     # прикрепленные картинки: список кортежей
     # (thumbnail_url, full_picture_url)
     self.images = []
     
     self.links = [] # список прикрепленных URL
예제 #4
0
 def __init__(self):
     self.posts = SortedDict()