本文整理汇总了Python中point.core.user.User.from_data方法的典型用法代码示例。如果您正苦于以下问题:Python User.from_data方法的具体用法?Python User.from_data怎么用?Python User.from_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类point.core.user.User
的用法示例。
在下文中一共展示了User.from_data方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recommended_users
# 需要导入模块: from point.core.user import User [as 别名]
# 或者: from point.core.user.User import from_data [as 别名]
def recommended_users(self):
res = db.fetchall(
"SELECT u.id, u.login FROM posts.recommendations r "
"JOIN users.logins u ON u.id=r.user_id "
"WHERE post_id=%s AND comment_id=0;",
[unb26(self.id)],
)
return [User.from_data(r[0], r[1]) for r in res]
示例2: recipients
# 需要导入模块: from point.core.user import User [as 别名]
# 或者: from point.core.user.User import from_data [as 别名]
def recipients(self):
res = db.fetchall(
"SELECT u.id, u.login FROM posts.recipients r "
"JOIN users.logins u ON u.id=r.user_id "
"WHERE r.post_id=%s;",
[unb26(self.id)],
)
return [User.from_data(r[0], r[1]) for r in res]
示例3: domain_owner
# 需要导入模块: from point.core.user import User [as 别名]
# 或者: from point.core.user.User import from_data [as 别名]
def domain_owner(domain):
if domain == settings.domain:
return User.from_data(None, None)
if domain.endswith(settings.domain):
return User("login", domain[0 : domain.find(settings.domain) - 1])
res = db.fetchone("SELECT id FROM users.domains WHERE domain=%s;", [domain]) # , _cache=600)
if res:
return User(res[0])
raise UserNotFound
示例4: __init__
# 需要导入模块: from point.core.user import User [as 别名]
# 或者: from point.core.user.User import from_data [as 别名]
def __init__(self, post, id, to_comment_id=None, author=None,
created=None, text=None, archive=False,
files=None):
if post and id:
if isinstance(post, Post):
self.post = post
elif isinstance(post, (int, long)):
self.post = Post.from_data(b26(post))
else:
self.post = Post.from_data(post)
self.id = int(id)
res = db.fetchone("SELECT c.author, u.login, i.name, i.avatar, "
"c.to_comment_id, "
"c.anon_login, "
"c.created at time zone %s AS created, "
"c.text, c.files, c.updated "
"FROM posts.comments c "
"JOIN users.logins u ON u.id=c.author "
"JOIN users.info i ON u.id=i.id "
"WHERE post_id=%s AND comment_id=%s;",
[self.post.tz, unb26(self.post.id), self.id])
if not res:
raise CommentNotFound(self.post.id, id)
if author:
self.author = author
else:
login = res['anon_login'] or res['login']
self.author = User.from_data(res['author'], login,
info={'name': res['name'] or login,
'avatar': res['avatar']})
self.to_comment_id = to_comment_id or res['to_comment_id']
self.created = created or res['created']
self.text = text or res['text']
self.recommendations = 0
self.recommended = False
self.files = res['files']
self.updated = res['updated']
self.comments = []
self.archive = archive
if isinstance(files, (list, tuple)):
self.files = files
示例5: comments
# 需要导入模块: from point.core.user import User [as 别名]
# 或者: from point.core.user.User import from_data [as 别名]
def comments(self, last=False, all=False, offset=None, limit=None,
cuser=None):
if last:
lim = " LIMIT %d" % limit if limit else ''
offset = 0
order = ' DESC'
elif all:
lim = ''
offset = 0
order = ' ASC'
else:
if not offset:
offset = 0
lim = " LIMIT %d" % limit if limit else ''
order = ' ASC'
if isinstance(cuser, User) and cuser.id:
res = db.fetchall("SELECT c.comment_id, c.to_comment_id,"
"c.author AS user_id, "
"CASE WHEN c.anon_login IS NOT NULL "
"THEN c.anon_login ELSE u1.login END AS login,"
"c.created at time zone %%s AS created, "
"c.text, c.files, "
"c.updated at time zone %%s AS updated, "
"CASE WHEN rc.comment_id IS NOT NULL "
"THEN true ELSE false END AS is_rec, "
"ur.user_id AS recommended, "
"ub.user_id AS bookmarked, "
"ui1.name, ui1.avatar "
"FROM posts.comments c "
"JOIN users.logins u1 ON c.author=u1.id "
"LEFT OUTER JOIN users.info ui1 "
"ON ui1.id=c.author "
"LEFT OUTER JOIN posts.recommendations rc "
"ON rc.post_id=c.post_id "
"AND rc.rcid=c.comment_id "
"LEFT OUTER JOIN posts.recommendations ur "
"ON ur.user_id=%%s "
"AND ur.post_id=c.post_id "
"AND ur.comment_id=c.comment_id "
"LEFT OUTER JOIN posts.bookmarks ub "
"ON ub.user_id=%%s "
"AND ub.post_id=c.post_id "
"AND ub.comment_id=c.comment_id "
"WHERE c.post_id=%%s AND c.comment_id>=%%s "
"ORDER BY c.created%s%s;" % (order, lim),
[self.tz, self.tz, cuser.id, cuser.id, unb26(self.id),
offset])
else:
res = db.fetchall("SELECT c.comment_id, c.to_comment_id,"
"c.author AS user_id, ui1.name,"
"CASE WHEN c.anon_login IS NOT NULL "
"THEN c.anon_login ELSE u1.login END AS login,"
"c.created at time zone %%s AS created, "
"c.text, c.files, "
"c.updated at time zone %%s AS updated, "
"CASE WHEN rc.comment_id IS NOT NULL "
"THEN true ELSE false END AS is_rec, "
"false AS recommended, "
"false AS bookmarked, "
"ui1.avatar "
"FROM posts.comments c "
"JOIN users.logins u1 ON c.author=u1.id "
"LEFT OUTER JOIN users.info ui1 "
"ON ui1.id=c.author "
"LEFT OUTER JOIN posts.recommendations rc "
"ON rc.post_id=c.post_id "
"AND rc.rcid=c.comment_id "
"WHERE c.post_id=%%s AND c.comment_id>=%%s "
"ORDER BY c.created%s%s;" % (order, lim),
[self.tz, self.tz, unb26(self.id), offset])
if last:
res.reverse()
if cuser:
unr = db.fetchall("SELECT comment_id FROM posts.unread_comments "
"WHERE user_id=%s AND post_id=%s;",
[cuser.id, unb26(self.id)])
unread = { r['comment_id']: 1 for r in unr }
else:
unread = {}
comments = []
for c in res:
author = User.from_data(c['user_id'], c['login'],
info={'name': c['name'], 'avatar': c['avatar']})
unr = True if c['comment_id'] in unread else False
comment = Comment.from_data(self, id=c['comment_id'],
to_comment_id=c['to_comment_id'],
author=author,
created=c['created'],
text=c['text'],
recommended=c['recommended'],
bookmarked=c['bookmarked'],
is_rec=c['is_rec'],
files=c['files'],
updated=c['updated'],
unread=unr)
comments.append(comment)
#.........这里部分代码省略.........