本文整理汇总了Python中r2.models.account.Account类的典型用法代码示例。如果您正苦于以下问题:Python Account类的具体用法?Python Account怎么用?Python Account使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Account类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
a = Account()
a._commit()
sr = Subreddit(name = 'subreddit_name_%s' % (self.seconds_since_epoc(),),
title = 'subreddit_title_%s' % (self.seconds_since_epoc(),),)
sr._commit()
self.rel = SRMember(sr, a, 'test')
示例2: get_editor_accounts
def get_editor_accounts(self):
editors = self.get_editors()
accounts = [Account._byID36(editor, data=True)
for editor in self.get_editors()]
accounts = [account for account in accounts
if not account._deleted]
return accounts
示例3: get_author_name
def get_author_name(author_name):
if not author_name:
return "[unknown]"
try:
return Account._by_name(author_name).name
except NotFound:
return "[deleted]"
示例4: check_valid
def check_valid(self):
"""Returns boolean indicating whether or not this access token is still valid."""
# Has the token been revoked?
if getattr(self, 'revoked', False):
return False
# Is the OAuth2Client still valid?
try:
client = OAuth2Client._byID(self.client_id)
if getattr(client, 'deleted', False):
raise NotFound
except NotFound:
return False
# Is the user account still valid?
if self.user_id:
try:
account = Account._byID36(self.user_id)
if account._deleted:
raise NotFound
except NotFound:
return False
return True
示例5: revoke
def revoke(self):
super(OAuth2RefreshToken, self).revoke()
account = Account._byID36(self.user_id)
access_tokens = OAuth2AccessToken._by_user(account)
for token in access_tokens:
if token.refresh_token == self._id:
token.revoke()
示例6: _copy_multi
def _copy_multi(self, from_multi, to_path_info):
self._check_new_multi_path(to_path_info)
to_owner = Account._by_name(to_path_info["username"])
try:
LabeledMulti._byID(to_path_info["path"])
except tdb_cassandra.NotFound:
to_multi = LabeledMulti.copy(to_path_info["path"], from_multi, owner=to_owner)
else:
raise RedditError("MULTI_EXISTS", code=409, fields="multipath")
return to_multi
示例7: get_participant_account
def get_participant_account(self):
if self.is_internal:
return None
try:
convo_participant = ModmailConversationParticipant.get_participant(
self.id)
participant = Account._byID(convo_participant.account_id)
except NotFound:
if not self.is_auto:
raise
return None
if participant._deleted:
raise NotFound
return participant
示例8: top_promoters
def top_promoters(cls, start_date, end_date = None):
end_date = end_date or datetime.datetime.now(g.tz)
q = cls.for_date_range(start_date, end_date)
d = start_date
res = []
accounts = Account._byID([i.account_id for i in q],
return_dict = True, data = True)
res = {}
for i in q:
if i.bid is not None and i.actual_start is not None:
r = res.setdefault(i.account_id, [0, 0, set()])
r[0] += i.bid
r[1] += i.refund
r[2].add(i.thing_name)
res = [ ([accounts[k]] + v) for (k, v) in res.iteritems() ]
res.sort(key = lambda x: x[1] - x[2], reverse = True)
return res
示例9: check_valid
def check_valid(self):
if getattr(self, 'revoked', False):
return False
try:
client = OAuth2Client._byID(self.client_id)
if getattr(client, 'deleted', False):
raise NotFound
except AttributeError:
g.log.error("bad token %s: %s", self, self._t)
raise
except NotFound:
return False
if self.user_id:
try:
account = Account._byID36(self.user_id)
if account._deleted:
raise NotFound
except NotFound:
return False
return True
示例10: to_serializable
def to_serializable(self, author=None):
if not author:
from r2.models import Account
author = Account._byID(self.account_id)
name = author.name
author_id = author._id
if author._deleted:
name = '[deleted]'
author_id = None
return {
'id': to36(self.id),
'author': {
'id': author_id,
'name': name,
'isAdmin': author.employee,
'isMod': True,
'isHidden': False,
'isDeleted': author._deleted
},
'actionTypeId': self.action_type_id,
'date': self.date.isoformat(),
}
示例11: update_sr_mods_modmail_icon
def update_sr_mods_modmail_icon(sr):
"""Helper method to set the modmail icon for mods with mail permissions
for the passed sr.
Method will lookup all moderators for the passed sr and query whether they
have unread conversations that exist. If the user has unreads the modmail
icon will be lit up, if they do not it will be disabled.
Args:
sr -- Subreddit object to fetch mods with mail perms from
"""
mods_with_perms = sr.moderators_with_perms()
modmail_user_ids = [mod_id for mod_id, perms in mods_with_perms.iteritems()
if 'mail' in perms or 'all' in perms]
mod_accounts = Account._byID(modmail_user_ids, ignore_missing=True,
return_dict=False)
mail_exists_by_user = (ModmailConversationUnreadState
.users_unreads_exist(mod_accounts))
for mod in mod_accounts:
set_modmail_icon(mod, bool(mail_exists_by_user.get(mod._id)))
示例12: _developers
def _developers(self):
"""Returns a list of users who are developers of this client."""
devs = Account._byID(list(self._developer_ids))
return [dev for dev in devs.itervalues()
if not (dev._deleted or dev._spam)]
示例13: setUp
def setUp(self):
a = Account()
a._id = 1
sr = Subreddit()
sr._id = 2
self.rel = SRMember(sr, a, 'test')
示例14: valid_for_credentials
def valid_for_credentials(self, email, password):
user = Account._by_fullname(self.user_id)
return (self.email_address.lower() == email.lower() and
valid_password(user, password, self.password))
示例15: is_first_party
def is_first_party(self):
return self.has_developer(Account.system_user())