本文整理汇总了Python中uliweb.utils.generic.ListView.object方法的典型用法代码示例。如果您正苦于以下问题:Python ListView.object方法的具体用法?Python ListView.object怎么用?Python ListView.object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uliweb.utils.generic.ListView
的用法示例。
在下文中一共展示了ListView.object方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: topic_view
# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import object [as 别名]
#.........这里部分代码省略.........
get_user_image = function('get_user_image')
try:
url = get_user_image(obj.posted_by)
except NotFound:
url = get_user_image()
return url
def actions(value, obj):
if not request.user:
return ''
a = []
is_manager = forum.managers.has(request.user)
if obj.floor == 1 and obj.parent == None:
#第一楼为主贴,可以允许关闭,顶置等操作
if is_manager:
a.append('<a href="#" rel="%d" class="close_thread">%s</a>' % (obj.id, self.status['close'][obj.topic.closed]))
a.append('<a href="#" rel="%d" class="hidden">%s</a>' % (obj.id, self.status['hidden'][obj.topic.hidden]))
a.append('<a href="#" rel="%d" class="top">%s</a>' % (obj.id, self.status['sticky'][obj.topic.sticky]))
a.append('<a href="#" rel="%d" class="essence">%s</a>' % (obj.id, self.status['essence'][obj.topic.essence]))
a.append('<a href="#" rel="%d" class="homepage">%s</a>' % (obj.id, self.status['homepage'][obj.topic.homepage]))
if is_manager or (obj.posted_by.id == request.user.id and obj.created_on+timedelta(days=settings.get_var('PARA/FORUM_EDIT_DELAY'))>=date.now()):
#作者或管理员且在n天之内,则可以编辑
url = url_for(ForumView.edit_topic, forum_id=forum_id, topic_id=topic_id)
a.append('<a href="%s" rel="%d" class="edit">编辑</a>' % (url, obj.id))
if is_manager:
url = url_for(ForumView.remove_topic, forum_id=forum_id, topic_id=topic_id)
a.append('<a href="%s" rel="%d" class="delete_topic">删除主题</a>' % (url, obj.id))
#处理贴子转移,管理员可以转移
if is_manager or request.user.is_superuser:
url = url_for(ForumView.move_topic, forum_id=forum_id, topic_id=topic_id)
a.append('<a href="%s" rel="%d" class="move_topic">移动主题</a>' % (url, obj.id))
if is_manager or (obj.posted_by.id == request.user.id):
if (obj.deleted and (obj.deleted_by.id == request.user.id or is_manager)) or not obj.deleted:
a.append('<a href="#" rel="%d" class="delete">%s</a>' % (obj.id, self.status['delete'][obj.deleted]))
try:
obj.posted_by
if obj.posted_by.id == request.user.id:
a.append('<a href="#" rel="%d" class="email">%s</a>' % (obj.id, self.status['email'][obj.reply_email]))
except NotFound:
obj.posted_by = None
obj.save()
a.append('<a href="/%d/%d/%d/new_reply">回复该作者</a>' % (forum_id, topic_id, obj.id))
return ' | '.join(a)
def updated(value, obj):
if obj.floor == 1 and obj.topic.updated_on and not obj.parent:
return u'<div class="updated">由 %s 于 %s 更新</div>' % (obj.topic.modified_user.username, timesince(obj.topic.updated_on))
fields = ['topic', 'id', 'username', 'userimage', 'posted_by', 'content',
'created_on', 'actions', 'floor', 'updated', 'parent',
]
fields_convert_map = {'created_on':created_on, 'content':content,
'username':username, 'userimage':userimage, 'actions':actions,
'updated':updated}
#view1 为生成一级回复,即回复主题
view1 = ListView(Post, fields=fields, condition=condition1, order_by=order_by,
rows_per_page=rows_per_page, pageno=pageno,
fields_convert_map=fields_convert_map)
#view2 为生成二级乃至多级回复
view2 = ListView(Post, fields=fields, condition=condition2, order_by=order_by,
pagination=False,
fields_convert_map=fields_convert_map)
key = '__topicvisited__:forumtopic:%s:%s:%s' % (request.remote_addr, forum_id, topic_id)
cache = function('get_cache')()
v = cache.get(key, None)
if not v:
Topic.filter(Topic.c.id==int(topic_id)).update(num_views=Topic.c.num_views+1)
cache.set(key, 1, settings.get_var('PARA/FORUM_USER_VISITED_TIMEOUT'))
slug = uuid.uuid1().hex
#处理posts和sub_posts
query = view1.query()
posts = []
sub_posts = {}
def process_sub(ids):
_ids = []
for x in Post.filter(Post.c.parent.in_(ids)).order_by(Post.c.floor):
obj = view2.object(x)
d = sub_posts.setdefault(str(x._parent_), [])
d.append(obj)
_ids.append(x.id)
if _ids:
process_sub(_ids)
ids = []
for row in query:
posts.append(view1.object(row))
ids.append(row.id)
process_sub(ids)
pagination = functions.create_pagination(request.path+'?'+request.query_string, view1.total,
pageno+1, rows_per_page)
return {'forum':forum, 'topic':topic, 'slug':slug,
'has_email':bool(request.user and request.user.email),
'page':pageno+1, 'pagination':pagination,
'posts':posts, 'sub_posts':sub_posts}
示例2: topic_view
# 需要导入模块: from uliweb.utils.generic import ListView [as 别名]
# 或者: from uliweb.utils.generic.ListView import object [as 别名]
#.........这里部分代码省略.........
if is_manager or (obj.posted_by.id == request.user.id):
if (obj.deleted and (obj.deleted_by.id == request.user.id or is_manager)) or not obj.deleted:
a.append(
'<a href="#" rel="%d" class="delete">%s</a>' % (obj.id, self.status["delete"][obj.deleted])
)
if obj.posted_by.id == request.user.id:
a.append('<a href="#" rel="%d" class="email">%s</a>' % (obj.id, self.status["email"][obj.reply_email]))
a.append('<a href="/forum/%d/%d/%d/new_reply">回复该作者</a>' % (forum_id, topic_id, obj.id))
return " | ".join(a)
def updated(value, obj):
if obj.floor == 1 and obj.topic.updated_on and not obj.parent:
return u'<div class="updated">由 %s 于 %s 更新</div>' % (
obj.topic.modified_user.username,
timesince(obj.topic.updated_on),
)
fields = [
"topic",
"id",
"username",
"userimage",
"posted_by",
"content",
"created_on",
"actions",
"floor",
"updated",
"parent",
]
fields_convert_map = {
"created_on": created_on,
"content": content,
"username": username,
"userimage": userimage,
"actions": actions,
"updated": updated,
}
# view1 为生成一级回复,即回复主题
view1 = ListView(
Post,
fields=fields,
condition=condition1,
order_by=order_by,
rows_per_page=rows_per_page,
pageno=pageno,
fields_convert_map=fields_convert_map,
)
# view2 为生成二级乃至多级回复
view2 = ListView(
Post,
fields=fields,
condition=condition2,
order_by=order_by,
pagination=False,
fields_convert_map=fields_convert_map,
)
key = "__topicvisited__:forumtopic:%s:%s:%s" % (request.remote_addr, forum_id, topic_id)
cache = function("get_cache")()
v = cache.get(key, None)
if not v:
Topic.filter(Topic.c.id == int(topic_id)).update(num_views=Topic.c.num_views + 1)
cache.set(key, 1, settings.get_var("PARA/FORUM_USER_VISITED_TIMEOUT"))
slug = uuid.uuid1().hex
topic = Topic.get(int(topic_id))
# 处理posts和sub_posts
query = view1.query()
posts = []
sub_posts = {}
def process_sub(ids):
_ids = []
for x in Post.filter(Post.c.parent.in_(ids)).order_by(Post.c.floor):
obj = view2.object(x)
d = sub_posts.setdefault(str(x._parent_), [])
d.append(obj)
_ids.append(x.id)
if _ids:
process_sub(_ids)
ids = []
for row in query:
posts.append(view1.object(row))
ids.append(row.id)
process_sub(ids)
pagination = functions.create_pagination(request.url, view1.total, pageno + 1, rows_per_page)
return {
"forum": forum,
"topic": topic,
"slug": slug,
"has_email": bool(request.user and request.user.email),
"page": pageno + 1,
"pagination": pagination,
"posts": posts,
"sub_posts": sub_posts,
}