本文整理汇总了Python中models.dbsession.query函数的典型用法代码示例。如果您正苦于以下问题:Python query函数的具体用法?Python query怎么用?Python query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cache_actions
def cache_actions():
''' Loads all of the actions from the database into memory for the scoreboard pages'''
action_list = dbsession.query(models.Action).all()
ws_manager = WebSocketManager.Instance()
for action in action_list:
team = dbsession.query(models.User).filter_by(id=action.user_id).first()
score_update = ScoreUpdate(action.created.strftime("%d%H%M%S"), action.value, team.team_name)
ws_manager.currentUpdates.append(score_update)
示例2: by_ip_address
def by_ip_address(cls, ip_addr):
'''
Returns a box object based on an ip address, supports both ipv4
and ipv6
'''
db_ip = dbsession.query(IpAddress).filter(
or_(IpAddress.v4 == ip_addr, IpAddress.v6 == ip_addr)
).first()
if db_ip is not None:
return dbsession.query(cls).filter_by(id=db_ip.box_id).first()
else:
return None
示例3: delivered
def delivered(cls, user_id, uuid):
notify = dbsession.query(cls).filter(
and_(cls.event_uuid == uuid, cls.user_id == user_id)
).first()
notify.viewed = True
dbsession.add(notify)
dbsession.flush()
示例4: list
def list(cls):
''' Returns a list of all categories in the database '''
categories = dbsession.query(cls).all()
catlist = []
for cat in categories:
catlist.append(cat.category)
return json.dumps(catlist)
示例5: team_name
def team_name(self):
""" Return a list with all groups names the user is a member of """
if self.team_id == None:
return None
else:
team = dbsession.query(Team).filter_by(id=self.team_id).first() #@UndefinedVariable
return team.team_name
示例6: by_ip_address
def by_ip_address(cls, ip_addr):
'''
Returns a box object based on an ip address, supports both ipv4
and ipv6
'''
ip = dbsession.query(IpAddress).by_address(ip_addr).first()
return ip.box if ip is not None else None
示例7: delivered
def delivered(cls, user_id, uuid):
notify = dbsession.query(cls).filter(
and_(cls.event_uuid == uuid, cls.user_id == user_id)
).first()
if notify is not None:
notify.viewed = True
dbsession.add(notify)
dbsession.commit()
示例8: score
def score(self):
''' Returns user's current score from cache, or re-calculates if expired '''
if self.dirty:
actions = dbsession.query(Action).filter_by(user_id=self.id).all() #@UndefinedVariable
self.score_cache = sum(actions)
self.dirty = False
dbsession.add(self)
dbsession.flush()
return self.score_cache
示例9: get_monster
def get_monster(cls, user):
''' Based on the users quest and level this will choose an appropriate monster '''
quest = Quest.by_id(user.quest_level)
#If we are still on quests
if quest != None:
#Get all valid monsters
all = dbsession.query(cls).filter(cls.level<=quest.max_monster_level).filter(cls.level>=quest.min_monster_level).all()
return choice(all)
return choice(cls.get_all())
示例10: get_current_user
def get_current_user(self):
"""
Return the request's user object.
can be called using BaseHandler self.get_current_user() or
by get_current_user(request_handler_instance)
"""
# loads the cookie and query the database to compare passwords.
# if password was changed/deleted (in the server side) then treats as unauthed
auth = loads(self.get_secure_cookie('auth') or '""')
if auth:
user = dbsession.query(User).get(auth['id'])
if user and user.password[0:8] == auth['password']: return user
示例11: by_username
def by_username(cls, user_name):
""" Return the user object whose user name is 'user_name' """
return dbsession.query(cls).filter_by(username=unicode(user_name)).first()
示例12: all
def all(cls):
""" Return all non-admin user objects """
return dbsession.query(cls).all()
示例13: get_approved
def get_approved(cls):
""" Return all approved user objects """
return dbsession.query(cls).filter_by(approved=True).all()
示例14: get_unapproved
def get_unapproved(cls):
""" Return all unapproved user objects """
return dbsession.query(cls).filter_by(approved=False).all()
示例15: all
def all(cls):
''' Returns a list of all objects in the database '''
return dbsession.query(cls).all()