本文整理汇总了Python中db.User.region方法的典型用法代码示例。如果您正苦于以下问题:Python User.region方法的具体用法?Python User.region怎么用?Python User.region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.User
的用法示例。
在下文中一共展示了User.region方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import region [as 别名]
def create_user(self, name, team):
newbie = User(name=name, team=team, loyalists=100, leader=True)
self.sess.add(newbie)
cap = Region.capital_for(team, self.sess)
newbie.region = cap
self.sess.commit()
return newbie
示例2: recruit_from_comment
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import region [as 别名]
def recruit_from_comment(self, comment):
session = self.session
if not comment.author: # Deleted comments don't have an author
return
name = comment.author.name.lower()
if name == self.config.username.lower():
return
# Is this author already one of us?
found = session.query(User).filter_by(
name=name).first()
if not found:
# Getting the author ID triggers a lookup on the userpage. In the
# case of banned users, this will 404. @failable would normally
# catch that just fine, but I want to check it here so that in the
# future, I can do things like e.g. add to an 'ignored' list and
# save myself the lookup
try:
author_id = comment.author.id
except NotFound:
logging.warn("Ignored banned user %s" % name)
return
team = 0
assignment = self.config['game']['assignment']
if assignment == 'uid':
base10_id = base36decode(author_id)
team = base10_id % 2
elif assignment == "random":
team = random.randint(0, 1)
is_leader = name in self.config["game"]["leaders"]
newbie = User(name=name,
team=team,
loyalists=100,
leader=is_leader)
session.add(newbie)
cap = Region.capital_for(newbie.team, session)
if not cap:
logging.fatal("Could not find capital for %d" %
newbie.team)
newbie.region = cap
session.commit()
logging.info("Created combatant %s", newbie)
reply = ("Welcome to Chroma! You are now a %s "
"in the %s army, commanding a force of loyalists "
"%d people strong. You are currently encamped at %s"
) % (newbie.rank,
num_to_team(newbie.team, self.config),
newbie.loyalists,
cap.markdown())
comment.reply(reply)
else:
#logging.info("Already registered %s", comment.author.name)
pass
示例3: recruit_from_post
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import region [as 别名]
def recruit_from_post(self, post):
post.replace_more_comments(threshold=0)
flat_comments = praw.helpers.flatten_tree(post.comments)
session = self.session
for comment in flat_comments:
if not comment.author: # Deleted comments don't have an author
continue
name = comment.author.name.lower()
if name == self.config.username.lower():
continue
# Is this author already one of us?
found = session.query(User).filter_by(name=name).first()
if not found:
team = 0
assignment = self.config["game"]["assignment"]
if assignment == "uid":
base10_id = base36decode(comment.author.id)
team = base10_id % 2
elif assignment == "random":
team = random.randint(0, 1)
is_leader = name in self.config["game"]["leaders"]
newbie = User(name=name, team=team, loyalists=100, leader=is_leader)
session.add(newbie)
cap = Region.capital_for(newbie.team, session)
if not cap:
logging.fatal("Could not find capital for %d" % newbie.team)
newbie.region = cap
session.commit()
logging.info("Created combatant %s", newbie)
reply = (
"Welcome to Chroma! You are now a %s "
"in the %s army, commanding a force of loyalists "
"%d people strong. You are currently encamped at %s"
) % (newbie.rank, num_to_team(newbie.team, self.config), newbie.loyalists, cap.markdown())
comment.reply(reply)
else:
# logging.info("Already registered %s", comment.author.name)
pass