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)
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
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
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)
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()
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()
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
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()
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
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())
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
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()
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()
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()
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()
def by_uuid(cls, _uuid): """ Return and object based on a uuid """ return dbsession.query(cls).filter_by(uuid=str(_uuid)).first()
def by_name(cls, name): """ Return the box object whose name is "name" """ return dbsession.query(cls).filter_by(_name=str(name)).first()
def ranks(cls): ''' Returns a list of all objects in the database ''' return sorted(dbsession.query(cls).all())
def by_uuid(cls, uuid): ''' Return and object based on a uuid ''' return dbsession.query(cls).filter_by(uuid=unicode(uuid)).first()
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()
def last_level(cls, number): ''' Returns the prior level ''' return dbsession.query(cls).filter_by( next_level_id=int(number)).first()
def by_number(cls, number): ''' Returns a the object with number of number ''' return dbsession.query(cls).filter_by(_number=abs(int(number))).first()
def by_id(cls, _id): ''' Returns a the object with id of _id ''' return dbsession.query(cls).filter_by(id=_id).first()
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()
def by_name(cls, name): ''' Return the team object based on "team_name" ''' return dbsession.query(cls).filter_by(_name=unicode(name)).first()
def all(cls): ''' Returns a list of all objects in the database ''' return dbsession.query(cls).order_by(asc(cls._number)).all()
def all(cls): ''' Returns a list of all objects in the database ''' return dbsession.query(cls).all()
def get_all(cls): """ Return all non-admin user objects """ return dbsession.query(cls).filter(cls.user_name != 'admin').all()
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()
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()
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()
def by_garbage(cls, _garbage): return dbsession.query(cls).filter_by(garbage=_garbage).first()
def count(cls): return dbsession.query(cls).count()
def name(self): return dbsession.query(Team._name).filter_by( id=self.team_id ).first()[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)
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()
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()
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()
def by_box_id(cls, bid): return dbsession.query(cls).filter_by(box_id=bid).first()
def by_uuid(cls, _uuid): ''' Return and object based on a uuid ''' return dbsession.query(cls).filter_by(uuid=_uuid).first()
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()
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()
def by_id(cls, identifier): ''' Returns a the object with id of identifier ''' return dbsession.query(cls).filter_by(id=identifier).first()
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()