当前位置: 首页>>代码示例>>Python>>正文


Python Topic.get_all方法代码示例

本文整理汇总了Python中models.Topic.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.get_all方法的具体用法?Python Topic.get_all怎么用?Python Topic.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Topic的用法示例。


在下文中一共展示了Topic.get_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GET

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_all [as 别名]
    def GET(self, pk=None):
        if pk:
            topic = Topic.get_by_id(pk)
            return json.dumps(topic)

        topics = Topic.get_all()
        result = []
        for t in topics:
            topic = dict(t)
            try:
                user = CACHE_USER[t.owner_id]
            except KeyError:
                user = User.get_by_id(t.owner_id)
                CACHE_USER[t.owner_id] = user
            topic['owner_name'] = user.username
            result.append(topic)
        return json.dumps(result)
开发者ID:fatfan,项目名称:mychat,代码行数:19,代码来源:handlers.py

示例2: GET

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_all [as 别名]
    def GET(self, pk=None):
        if pk:
            topic = Topic.get_by_id(pk)
            topic['created_time'] = display_time(topic['created_time'])
            return json.dumps(topic)

        topics = Topic.get_all()
        result = []
        for t in topics:
            topic = dict(t)
            if 'tags' not in topic:
                topic['tags'] = ''

            try:
                user = CACHE_USER[t.owner_id]
            except KeyError:
                user = User.get_by_id(t.owner_id)
                CACHE_USER[t.owner_id] = user
            topic['owner_name'] = user.username
            topic['created_time'] = display_time(topic['created_time'])

            message = Message.get_latest_by_topic(str(t.id))
            message_count = Message.topic_count(str(t.id))
            if message:
                # 最新回复
                try:
                    user = CACHE_USER[message.user_id]
                except KeyError:
                    user = User.get_by_id(message.user_id)
                    CACHE_USER[message.user_id] = user
                message.user_name = user.username
                message.created_time = pass_time(message.created_time)
            topic['new_comment'] = message
            topic['message_count'] = message_count
            result.append(topic)
        return json.dumps(result)
开发者ID:bb-js,项目名称:bb-js.org,代码行数:38,代码来源:topic.py


注:本文中的models.Topic.get_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。