本文整理汇总了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)
示例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)