Exemplo n.º 1
0
    def handle(self):
        shard_record, shard_and_state_list = list_topics(
            self.shard, self.user_id).get_result()

        out = []
        for shard, read_state in shard_and_state_list:
            shard_dict = dict(
                shardId=shard.shard_id,
                title=shard.title,
                description=shard.description,
                creationTimeMs=models.datetime_to_stamp_ms(
                    shard.creation_time),
                creationNickname=shard.creation_nickname,
                updateTimeMs=models.datetime_to_stamp_ms(shard.update_time),
                sequenceNumber=shard.sequence_number,
                isRoot=shard.root_shard is None,
            )

            if read_state:
                shard_dict.update(
                    firstReadTime=models.datetime_to_stamp_ms(
                        read_state.first_read_time),
                    lastReadSequence=read_state.last_read_sequence,
                    lastReadTimeMs=models.datetime_to_stamp_ms(
                        read_state.last_read_time))

            out.append(shard_dict)

        self.json_response['currentTopicId'] = shard_record.current_topic
        if shard_record.topic_change_time:
            self.json_response['currentTopicTimeMs'] = \
                models.datetime_to_stamp_ms(shard_record.topic_change_time)
        self.json_response['topics'] = out
Exemplo n.º 2
0
def marshal_posts(shard, post_list):
    """Organizes a list of posts into a JSON-serializable list."""
    out = []
    for post in post_list:
        post_dict = dict(
            shardId=shard,
            archiveType=models.Post.ARCHIVE_REVERSE_MAPPING[post.archive_type],
            nickname=post.nickname,
            title=post.title,
            body=post.body,
            postTimeMs=models.datetime_to_stamp_ms(post.post_time),
            sequenceId=getattr(post, 'sequence', None),
            newTopicId=post.new_topic,
            postId=post.post_id)
        out.append(post_dict)
    return out