本文整理汇总了Python中point.core.user.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, field=None, value=None):
if isinstance(field, (int, long)):
User.__init__(self, field)
return
if field and value:
User.__init__(self, field, value)
return
sess = Session()
self.id = sess['id']
self.login = sess['login']
self.type = 'user'
self.accounts = []
self.accounts_add = []
self.accounts_del = []
self.profile = {}
self.profile_upd = {}
self.info = {}
self.info_upd = {}
self.password = None
self.redis = RedisPool(settings.storage_socket)
if self.id:
self._get_avatar()
示例2: usercss
def usercss(login):
try:
u = User('login', login)
except UserNotFound:
raise NotFound
css = u.get_profile('www.usercss')
return Response(css, mimetype='text/css')
示例3: info
def info(login):
try:
user = User('login', login)
except UserNotFound:
raise NotFound
try:
data = users.info(user)
except SubscribeError:
raise Forbidden
data['login'] = login
try:
data['created'] = timestamp(data['created'])
except (KeyError, AttributeError):
pass
try:
data['birthdate'] = timestamp(data['birthdate'])
except (KeyError, AttributeError):
pass
if env.user.id:
data['subscribed'] = user.check_subscriber(env.user)
data['rec_sub'] = user.check_rec_subscriber(env.user)
if not data['subscribed']:
data['bl'] = env.user.check_blacklist(user)
if not data['bl']:
data['wl'] = env.user.check_blacklist(user)
return Response(json.dumps(data), mimetype='application/json')
示例4: info
def info(login):
try:
user = User('login', login)
except UserNotFound:
raise NotFound
try:
data = users.info(user)
except SubscribeError:
raise Forbidden
data['id'] = user.id
data['login'] = user.login
try:
data['created'] = data['created']
except (KeyError, AttributeError):
pass
try:
data['birthdate'] = data['birthdate']
except (KeyError, AttributeError):
pass
if env.user.id:
data['subscribed'] = user.check_subscriber(env.user)
data['rec_sub'] = user.check_rec_subscriber(env.user)
if not data['subscribed']:
data['bl'] = env.user.check_blacklist(user)
if not data['bl']:
data['wl'] = env.user.check_blacklist(user)
return data
示例5: authenticate_ulogin
def authenticate_ulogin(self, network, uid):
res = db.fetchone("SELECT id FROM users.ulogin_accounts "
"WHERE network=%s AND uid=%s;", [network, uid])
if not res:
raise NotAuthorized
User.__init__(self, int(res[0]))
self.authenticate()
示例6: unsubscribe_rec
def unsubscribe_rec(login):
if isinstance(login, User):
user = login
else:
user = User('login', login)
if not user.check_subscriber(env.user):
return False
user.del_rec_subscriber(env.user)
示例7: info
def info(user):
"""Get user info
"""
if isinstance(user, (str, unicode)):
user = User('login', user)
if env.user.id != user.id and user.get_profile('private') \
and not user.check_whitelist(env.user):
raise SubscribeError
return user.get_info()
示例8: reset_password
def reset_password(code, password):
redis = RedisPool(settings.storage_socket)
key = 'reset-password:%s' % code
print key
id = redis.get(key)
if not id:
raise UserNotFound
try:
user = User(int(id))
except ValueError:
raise UserNotFound
user.set_password(password)
user.save()
redis.delete(key)
return user
示例9: recipients
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]
示例10: get_info
def get_info(self, param=None):
if self.id or self.info or self.info_upd:
return User.get_info(self, param)
if param:
return None
return {}
示例11: recommended_users
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]
示例12: subscribe_rec
def subscribe_rec(login):
"""Subscribe to user's recommendations
returns True if subscribed, and False if subscription request is sent
"""
if isinstance(login, User):
user = login
else:
user = User('login', login)
if env.user.id == user.id:
raise SubscribeError
if not user.check_subscriber(env.user):
return subscribe(user)
user.add_rec_subscriber(env.user)
return True
示例13: save
def save(self):
is_new = not self.id
if is_new and not self._url:
raise InvalidFeedUrl("Cannot save feed without URL")
if not self.login:
self.login = self._generate_login()
User.save(self)
if is_new:
db.perform("INSERT INTO users.feeds (id, url) VALUES (%s, %s);",
[self.id, self._url])
self.fetch()
for p in self.posts():
p.save()
self.update_task()
示例14: subscribe
def subscribe(login):
"""Subscribe to user
returns True if subscribed, and False if subscription request is sent
"""
if isinstance(login, User):
user = login
else:
user = User('login', login)
if env.user.id == user.id:
raise SubscribeError
if user.add_subscription_request(env.user):
publish('sub', {'to':user.id, 'a':'sub', 'from':env.user.login})
log.info('sub %d %s' % (user.id, env.user.login))
return True
else:
publish('sub', {'to':user.id, 'a':'req', 'from':env.user.login})
log.info('sub request %d %s' % (user.id, env.user.login))
return False
示例15: avatar
def avatar(login, size):
"""To avoid code duplication, parameter ``login`` can be interpreted
as a number if it is user id, and as a string if it is user login"""
size = int(size) if size else 40
try:
if login and login.isdigit():
user = User(int(login))
else:
user = User('login', login)
avatar = user.get_info('avatar')
except UserNotFound:
avatar = None
if avatar:
path = '%s%s/%s/%s' % \
(env.request.protocol, settings.avatars_root, size, avatar)
else:
path = '%s%s/av%s.png' % \
(env.request.protocol, settings.avatars_root, size)
return Response(redirect=path)