Example #1
0
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)
Example #2
0
 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
Example #3
0
 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
Example #4
0
 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)
Example #5
0
 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()
Example #6
0
 def by_datetime(cls, input_datetime):
     ''' Returns all events for the day depicted by input_datetime '''
     day = input_datetime.date()
     next_day = day + datetime.timedelta(days=1)
     return dbsession.query(cls).filter(
         and_(cls.start_time >= day, cls.start_time < next_day)
     ).all()
Example #7
0
 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
Example #8
0
 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()
Example #9
0
 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
Example #10
0
 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())
Example #11
0
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
Example #12
0
 def by_uuid(cls, _uuid):
     ''' Return and object based on a _uuid '''
     return dbsession.query(cls).filter_by(uuid=_uuid).first()
 def by_ip_address(cls, weapon_ip_address):
     ''' Return the WeaponSystem object whose ip_address is 'weapon_ip_address' '''
     return dbsession.query(cls).filter_by(
         ip_address=unicode(weapon_ip_address)).first()
Example #14
0
 def by_event_uuid(cls, uuid):
     ''' Always returns anonymous notification '''
     return dbsession.query(cls).filter_by(event_uuid=uuid).filter_by(
         user_id=None).first()
Example #15
0
 def name(self):
     return dbsession.query(
         Team._name).filter_by(id=self.team_id).first()[0]
 def by_hexdigest(cls, hexvalue, jid):
     ''' Return the digest based on valud and job_id '''
     return dbsession.query(cls).filter(
         and_(cls.hexdigest == hexvalue, cls.job_id == jid)
     ).first()
Example #17
0
 def by_team_id(cls, team_id):
     ''' Return all paste objects for a given team '''
     return dbsession.query(cls).filter_by(team_id=team_id).order_by(desc(cls.created)).all()
Example #18
0
 def by_uuid(cls, _uuid):
     """ Return and object based on a uuid """
     return dbsession.query(cls).filter_by(uuid=str(_uuid)).first()
Example #19
0
 def by_name(cls, name):
     """ Return the box object whose name is "name" """
     return dbsession.query(cls).filter_by(_name=str(name)).first()
Example #20
0
 def ranks(cls):
     ''' Returns a list of all objects in the database '''
     return sorted(dbsession.query(cls).all())
Example #21
0
 def by_uuid(cls, uuid):
     ''' Return and object based on a uuid '''
     return dbsession.query(cls).filter_by(uuid=unicode(uuid)).first()
Example #22
0
 def by_name(cls, team_name):
     ''' Return the team object based on "team_name" '''
     return dbsession.query(cls).filter_by(name=unicode(team_name)).first()
Example #23
0
 def last_level(cls, number):
     ''' Returns the prior level '''
     return dbsession.query(cls).filter_by(
         next_level_id=int(number)).first()
Example #24
0
 def by_number(cls, number):
     ''' Returns a the object with number of number '''
     return dbsession.query(cls).filter_by(_number=abs(int(number))).first()
Example #25
0
 def by_id(cls, _id):
     ''' Returns a the object with id of _id '''
     return dbsession.query(cls).filter_by(id=_id).first()
Example #26
0
 def by_category(cls, _cat_id):
     """ Return the box object whose category is "_cat_id" """
     return dbsession.query(cls).filter_by(category_id=int(_cat_id)).all()
Example #27
0
 def by_name(cls, name):
     ''' Return the team object based on "team_name" '''
     return dbsession.query(cls).filter_by(_name=unicode(name)).first()
Example #28
0
 def all(cls):
     ''' Returns a list of all objects in the database '''
     return dbsession.query(cls).order_by(asc(cls._number)).all()
Example #29
0
 def all(cls):
     ''' Returns a list of all objects in the database '''
     return dbsession.query(cls).all()
Example #30
0
 def get_all(cls):
     """ Return all non-admin user objects """
     return dbsession.query(cls).filter(cls.user_name != 'admin').all() 
Example #31
0
 def new_messages(cls, user_id):
     ''' Return all notification which have not been viewed '''
     return dbsession.query(cls).filter(
         and_(cls.user_id == user_id, cls.viewed == False)).all()
 def by_id(cls, user_id):
     """ Return the user object whose user id is user_id """
     return dbsession.query(cls).filter_by(id=user_id).first()
Example #33
0
 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.commit()
 def get_unapproved(cls):
     """ Return all unapproved user objects """
     return dbsession.query(cls).filter_by(approved=False).all()
Example #35
0
 def by_uuid(cls, paste_uuid):
     ''' Get a paste object by uuid '''
     return dbsession.query(cls).filter_by(uuid=paste_uuid).first()
 def all(cls):
     """ Return all non-admin user objects """
     return dbsession.query(cls).all()
 def by_name(cls, weapon_name):
     ''' Return the WeaponSystem object whose name is 'weapon_name' '''
     return dbsession.query(cls).filter_by(
         name=unicode(weapon_name)).first()
Example #38
0
 def ranks(cls):
     ''' Returns a list of all objects in the database '''
     return sorted(dbsession.query(cls).all())
Example #39
0
 def by_garbage(cls, _garbage):
     return dbsession.query(cls).filter_by(garbage=_garbage).first()
Example #40
0
 def count(cls):
     return dbsession.query(cls).count()
Example #41
0
 def name(self):
     return dbsession.query(Team._name).filter_by(
         id=self.team_id
     ).first()[0]
Example #42
0
 def all(cls):
     """ Returns a list of all objects in the database """
     return dbsession.query(cls).all()
 def permissions(self):
     """ Return a list with all permissions granted to the user """
     return dbsession.query(Permission).filter_by(user_id=self.id)
Example #44
0
 def by_uuid(cls, _uuid):
     """ Get a paste object by uuid """
     return dbsession.query(cls).filter_by(uuid=_uuid).first()
 def by_uuid(cls, user_uuid):
     """ Return the user object whose user uuid is user_uuid """
     return dbsession.query(cls).filter_by(uuid=unicode(user_uuid)).first()
Example #46
0
 def team(self):
     ''' Pull box object from persistant db '''
     return dbsession.query(Box).by_uuid(self.box_uuid)
 def get_approved(cls):
     """ Return all approved user objects """
     return dbsession.query(cls).filter_by(approved=True).all()
Example #48
0
 def by_uuid(cls, uuid):
     ''' Returns a the object with a given uuid '''
     return dbsession.query(cls).filter_by(uuid=unicode(uuid)).first()
 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()
Example #50
0
 def by_box_id(cls, bid):
     return dbsession.query(cls).filter_by(box_id=bid).first()
Example #51
0
 def count(cls):
     return dbsession.query(cls).count()
Example #52
0
 def all(cls):
     ''' Returns a list of all objects in the database '''
     return dbsession.query(cls).all()
Example #53
0
 def by_uuid(cls, _uuid):
     ''' Return and object based on a uuid '''
     return dbsession.query(cls).filter_by(uuid=_uuid).first()
Example #54
0
 def by_id(cls, ident):
     ''' Returns a the object with id of ident '''
     return dbsession.query(cls).filter_by(id=ident).first()
 def by_id(cls, hash_id):
     ''' Return the PasswordHash object whose user id is 'hash_id' '''
     return dbsession.query(cls).filter_by(id=hash_id).first()
Example #56
0
 def all(cls):
     ''' Returns a list of all objects in the database '''
     return dbsession.query(cls).filter_by(user_id=None).all()
 def by_algorithm(cls, algo):
     ''' Return all passwords objects of a given algorithm id '''
     if isinstance(algo, int):
         return dbsession.query(cls).filter_by(algorithm_id=algo).all()
     else:
         return dbsession.query(cls).filter_by(algorithm_id=algo.id).all()
Example #58
0
 def by_id(cls, _id):
     ''' Returns a the object with id of _id '''
     return dbsession.query(cls).filter_by(id=_id).first()
Example #59
0
 def by_id(cls, identifier):
     ''' Returns a the object with id of identifier '''
     return dbsession.query(cls).filter_by(id=identifier).first()
Example #60
0
 def by_user_id(cls, _id):
     ''' Return notifications for a single user '''
     return dbsession.query(cls).filter_by(user_id=_id).order_by(
         desc(cls.created)).all()