当前位置: 首页>>代码示例>>Python>>正文


Python User.by_id方法代码示例

本文整理汇总了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)
开发者ID:hathcox,项目名称:Arthur,代码行数:9,代码来源:Battle.py

示例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())
开发者ID:japavi,项目名称:ioffer,代码行数:35,代码来源:main.py

示例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
开发者ID:fun-alex-alex2006hw,项目名称:Sonar-Server,代码行数:9,代码来源:BaseHandlers.py

示例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)
开发者ID:hathcox,项目名称:Arthur,代码行数:10,代码来源:Battle.py

示例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"])
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:11,代码来源:UserHandlers.py

示例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')
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:11,代码来源:Menu.py

示例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()
开发者ID:jhu104,项目名称:Web_dev,代码行数:12,代码来源:BaseHandler.py

示例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
开发者ID:lunarca,项目名称:blades-player,代码行数:12,代码来源:BaseHandlers.py

示例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)
开发者ID:moloch--,项目名称:RootTheBox,代码行数:15,代码来源:Menu.py

示例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'
开发者ID:joapaspe,项目名称:udacity-web,代码行数:16,代码来源:BaseHandler.py

示例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
开发者ID:hathcox,项目名称:Arthur,代码行数:17,代码来源:Battle.py

示例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
开发者ID:hathcox,项目名称:Arthur,代码行数:17,代码来源:Battle.py

示例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
开发者ID:moloch--,项目名称:TornadoAppTemplate,代码行数:18,代码来源:BaseHandlers.py

示例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
开发者ID:hathcox,项目名称:Arthur,代码行数:46,代码来源:Battle.py

示例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 !"
开发者ID:hathcox,项目名称:Arthur,代码行数:43,代码来源:Battle.py


注:本文中的models.User.User.by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。