本文整理汇总了Python中models.User.User.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_id方法的具体用法?Python User.by_id怎么用?Python User.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User.User
的用法示例。
在下文中一共展示了User.by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recover_mana
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def recover_mana(self):
""" Recover between 10-20% mana """
true_user = User.by_id(self.id)
max_mana = true_user.mana
# If there is health to gain
if self.mana < max_mana:
self.mana += min(int(max_mana * (random() % 0.2)), max_mana)
示例2: get
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def get(self):
uid = self.read_secure_cookie('user_id')
user = uid and User.by_id(int(uid))
logging.error('DB Query')
logged_username = user and user.name
if logged_username == '' or logged_username == None:
self.redirect('/')
else:
offer_added = self.request.get('offer_added')
u = loged_user(logged_username) #User.by_name(logged_username)
profile = loged_profile(logged_username)
logging.error('profile en welcome: %s' % profile)
if valid_username(logged_username):
if profile:
if offer_added:
self.render('ioffer_welcome.html', user = u, profile = profile, categories = categories, offer_added = True, last_10_offers = self.get_last_10_offers())
else:
self.render('ioffer_welcome.html', user = u, profile = profile, categories = categories, countries = countries, last_10_offers = self.get_last_10_offers(), geo_params = self.get_geo_params())
else:
self.render('ioffer_welcome.html', user = u, last_10_offers = self.get_last_10_offers(), categories = categories, geo_params = self.get_geo_params())
else:
error_username = 'There was an error with user %s' % logged_username
self.render('ioffer_welcome.html', user = u, error_username = error_username, last_10_offers = self.get_last_10_offers(), categories = categories, geo_params = self.get_geo_params())
示例3: get_current_user
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def get_current_user(self):
''' Get current user object from database '''
if self.session is not None:
if self._user is None:
self._user = User.by_id(self.session['user_id'])
return self._user
return None
示例4: recover_health
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def recover_health(self):
""" Recover between 10-20% health """
true_user = User.by_id(self.id)
max_health = true_user.health
# If there is health to gain
if self.health < max_health:
# Random number between .0 <-> .2 take that percentage of max hp and add it back in capping at your max hp
self.health += min(int(max_health * (random() % 0.1)), max_health)
示例5: post_avatar
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def post_avatar(self, *args, **kwargs):
'''
Saves avatar - Reads file header an only allows approved formats
'''
user = User.by_id(self.session['user_id'])
if 'avatar' in self.request.files:
user.avatar = self.request.files['avatar'][0]['body']
else:
self.render_page(errors=["Please provide an image"])
示例6: render
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def render(self, *args, **kwargs):
''' Renders the top menu '''
if self.handler.session is not None:
user = User.by_id(self.handler.session['user_id'])
if self.handler.session['menu'] == 'user':
return self.render_string('menu/user.html', user=user)
elif self.handler.session['menu'] == 'admin':
return self.render_string('menu/admin.html', handle=user.handle)
return self.render_string('menu/public.html')
示例7: initialize
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def initialize(self, *a, **kw):
webapp2.RequestHandler.initialize(self, *a, **kw)
uid = self.read_secure_cookie('user_id')
self.user = uid and User.by_id(int(uid))
if self.request.url.endswith('json'):
self.format = 'json'
else:
self.format = 'html'
self.client = memcache.Client()
示例8: get_current_user
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def get_current_user(self):
""" Get current user object from database """
if self.session is not None:
try:
return User.by_id(self.session['user_id'])
except KeyError:
logging.exception("Malformed session: %r" % self.session)
except:
logging.exception("Failed call to get_current_user()")
return None
示例9: render
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def render(self, *args, **kwargs):
''' Renders the top menu '''
if self.handler.session is not None:
user = User.by_id(self.handler.session['user_id'])
else:
user = None
scoreboard_visible = self.scoreboard_visible(user)
if self.handler.session is not None:
if self.handler.session['menu'] == 'user':
return self.render_string('menu/user.html', user=user, scoreboard_visible=scoreboard_visible)
elif self.handler.session['menu'] == 'admin':
return self.render_string('menu/admin.html', handle=user.handle, scoreboard_visible=scoreboard_visible)
return self.render_string('menu/public.html', scoreboard_visible=scoreboard_visible)
示例10: initialize
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def initialize(self, *a, **kw):
webapp2.RequestHandler.initialize(self, *a, **kw)
uid = self.read_secure_cookie('user_id')
self.user = uid and User.by_id(int(uid))
#Enviroment globals variables
jinja_env.globals['HOST_URL'] = self.request.host_url
jinja_env.globals['USER'] = self.user
if self.request.url.endswith('.json'):
self.format = 'json'
else:
self.format = 'html'
示例11: attack_monster
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def attack_monster(self, monster):
""" Calculates the damage toward a given monster """
true_monster = Monster.by_id(monster.id)
true_user = User.by_id(self.id)
monster_armor = ArmoryArmor.by_id(true_monster.armor_id)
weapon = true_user.equiped_weapon
if monster_armor != None and weapon != None:
hit = self.roll_hit()
if hit:
reduction = monster_armor.rating
damage = get_random_damage(weapon.damage)
damage -= int(reduction / REDUCTION_CONSTANT)
# Make sure we never return zero
return max(damage, 0)
return 0
示例12: advanced_attack_user
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def advanced_attack_user(self, user):
""" calculates damage agianst a provided user """
true_monster = Monster.by_id(self.id)
true_user = User.by_id(user.id)
user_armor = true_user.equiped_armor
weapon = ArmoryWeapon.by_id(true_monster.weapon_id)
if user_armor != None and weapon != None:
hit = self.roll_advanced_hit()
if hit:
reduction = user_armor.rating
damage = get_random_damage(weapon.damage)
damage -= int(reduction / REDUCTION_CONSTANT)
# Make sure we never return zero
return max(damage, 0) * 2
return 0
示例13: get_current_user
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def get_current_user(self):
""" Get current user object from database """
if self.session is not None:
try:
if self._user is None:
self._user = User.by_id(self.session['user_id'])
assert self._user is not None
return self._user
except KeyError:
logging.exception("Malformed session: %r", self.session)
except AssertionError:
logging.error("Failed to find user in database with id %r",
self.session['user_id'])
except:
logging.exception("Failed call to get_current_user()")
return None
示例14: check_ended
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def check_ended(self):
""" This checks wether a user or monster is dead """
valid_user = User.by_id(self.user.id)
# check is the user died
if self.monster.health <= 0:
# update the user
valid_user.experience += self.monster.experience
valid_user.gold += self.monster.gold
# Grab the quest
quest = Quest.by_id(valid_user.quest_level)
if quest != None:
# If we still have battles left in our quest
if valid_user.current_quest_battle < quest.number_of_battles:
valid_user.current_quest_battle += 1
# If not, give us the next quest
else:
valid_user.current_quest_battle = 0
valid_user.quest_level += 1
dbsession.add(valid_user)
dbsession.flush()
# set variable for the client
self.victor = self.user
self.text = self.user.name + " has defeated " + self.monster.name + " !"
self.exp = self.monster.experience
self.gold = self.monster.gold
return True
elif self.user.health <= 0:
# decrement experience
valid_user.lost_battle()
dbsession.add(valid_user)
dbsession.flush()
# set variable for the client
self.victor = self.monster
self.text = self.monster.name + " has defeated " + self.user.name + " !"
self.exp = self.user.experience - valid_user.experience
self.gold = 0
return True
# Both user and monster are alive
return False
示例15: do_user_round
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_id [as 别名]
def do_user_round(self, choice):
""" perform the users turn """
if choice == BattleMessage.ATTACK:
damage = self.user.attack_monster(self.monster)
self.monster.health -= damage
if damage > 0:
self.text = self.user.name + " hits " + self.monster.name + " for " + str(damage) + " damage!"
else:
self.text = self.user.name + " misses !"
elif choice == BattleMessage.DEFEND:
initial_health = self.user.health
initial_mana = self.user.mana
self.user.recover_health()
self.user.recover_mana()
self.text = (
self.user.name
+ " defends and recovers "
+ str(self.user.health - initial_health)
+ " health and "
+ str(self.user.mana - initial_mana)
+ " mana!"
)
elif choice == BattleMessage.ADVANCED:
true_user = User.by_id(self.user.id)
required_mana = true_user.equiped_weapon.rating
if self.user.mana > required_mana:
# Remove the mana we jsut used
self.user.mana -= required_mana
damage = self.user.advanced_attack_monster(self.monster)
self.monster.health -= damage
if damage > 0:
self.text = (
self.user.name
+ "'s Advanced attack hits "
+ self.monster.name
+ " for "
+ str(damage)
+ " damage!"
)
else:
self.text = self.user.name + "'s Advanced attack misses !"