def event_individual(event_id): # Redirect to normal event (which shows individual leaderboard) when event has no teams if not event.get_event(event_id).has_teams(): return flask.redirect('/event/' + str(event_id), code=302) e = event.get_event(event_id) title = e.name + ' Individual Leaderboard' return flask.render_template('leaderboard.html', title=title, heading=title, users=e.get_leaderboard(), num_flags=e.get_num_flags())
def get_flag(flag_str): flag = unwrap(flag_str) f = db.query_db('SELECT * FROM flags WHERE flag = ?', [flag], one=True) if f is None: return None else: if f['event_id']: return Flag(f['flag'], f['value'], event.get_event(f['event_id']), f['notes']) return Flag(f['flag'], f['value'], notes=f['notes'])
def event_team(event_id): if not flask_login.current_user.is_authenticated: flask.abort( 404 ) # User not logged in so has no team nor can create/join a team t = event.get_event(event_id).get_users_team( flask_login.current_user.username) if t is None: flask.abort(404) return flask.redirect('/event/' + str(event_id) + '/team/' + t.get_slug(), code=302)
def event_inter_team(event_id, team_slug): e = event.get_event(event_id) if e is None: flask.abort(404) t = e.get_team(team_slug) if (not e.has_teams()) or t is None: flask.abort(404) title = t.name + ' Leaderboard' return flask.render_template('leaderboard.html', title=title, heading=title, users=t.get_leaderboard())
def get_all(user=None): if user is None: res = db.query_db('SELECT * FROM flags') else: res = db.query_db('SELECT * FROM flags WHERE user = ?', [user.get_id()]) flags = [] if res is not None: for f in res: flags.append( Flag(f['flag'], f['value'], event.get_event(f['event_id']), f['notes'])) return flags
def get_flags(self): import tracker.event as event import tracker.flag as flag res = db.query_db( ''' SELECT f.flag, f.value, f.event_id, f.notes FROM flags f LEFT JOIN flagsfound ff ON f.flag = ff.flag_id WHERE ff.user_id = ? ''', [self.username]) flags = [] for f in res: flags.append( flag.Flag(f['flag'], f['value'], event=event.get_event(f['event_id']), notes=f['notes'])) return flags
def check_line(line): # Check we have all the data if line.count(',') < 3: raise ValueError('Line is missing a comma.') parts = line.split(',') # Check flag value try: value = int(parts[1]) if value < 0 or value > 50: raise ValueError() except ValueError: raise ValueError('Flag value must be an integer between 0 and 50.') # Check event ID if parts[2] == '': # Handle flags not tied to an event event_id = None else: try: event_id = int(parts[2]) if event.get_event(event_id) == None: raise ValueError() except ValueError: raise ValueError( 'Event must correspond to an existing event ID.') return parts[0], value, event_id, ''.join(parts[3:]).strip()
def get_event(event_id): e = event.get_event(event_id) if e is None: flask.abort(404) indiv_lb = e.get_leaderboard(limit=6) # Individual leaderboard team_lb = e.get_team_leaderboard(limit=6) # Team leaderboard if flask.request.method == 'POST': if not flask_login.current_user.is_authenticated: # Check user is logged in flask.abort(405) if e.get_users_team( flask_login.current_user.username ) is not None: # Check user is not already in a team flask.abort(405) team_form = forms.TeamForm() if team_form.validate_on_submit(): # Check form completed properly if team_form.create.data: # Create a team (Create button pressed) if team.create_team(team_form.team.data, event_id): # Team created okay flask.flash( 'Created team {} successfully!'.format( team_form.team.data), 'success') else: # Unable to create team team_form.team.errors.append( 'Unable to create team {}, it may already exist in this event.' .format(team_form.team.data)) return flask.render_template('event_teams.html', title=e.name, event=e, user=flask_login.current_user, form=team_form, team_lb=team_lb, indiv_lb=indiv_lb) # Add user to team if just created or if Join button pressed if e.add_user_to_team( flask_login.current_user.username, team.generate_slug( team_form.team.data)): # Team joined okay flask.flash( 'Joined team {} successfully!'.format(team_form.team.data), 'success') return flask.redirect('/event/' + str(event_id), code=302) else: # Unable to join team team_form.team.errors.append( 'Unable to join team {}, it may not exist in this event.'. format(team_form.team.data)) return flask.render_template('event_teams.html', title=e.name, event=e, user=flask_login.current_user, form=team_form, team_lb=team_lb, indiv_lb=indiv_lb) return flask.render_template('event_teams.html', title=e.name, event=e, user=flask_login.current_user, form=team_form, team_lb=team_lb, indiv_lb=indiv_lb) if e.has_teams(): if flask_login.current_user.is_authenticated: t = e.get_users_team(flask_login.current_user.username) if t is None: return flask.render_template('event_teams.html', title=e.name, event=e, user=flask_login.current_user, form=forms.TeamForm(), team_lb=team_lb, indiv_lb=indiv_lb) else: return flask.render_template('event_teams.html', title=e.name, event=e, user=flask_login.current_user, team=t, team_lb=team_lb, indiv_lb=indiv_lb) else: return flask.render_template('event_teams.html', title=e.name, event=e, team_lb=team_lb, indiv_lb=indiv_lb) else: title = e.name + ' Leaderboard' return flask.render_template('leaderboard.html', title=title, heading=title, users=e.get_leaderboard(), num_flags=e.get_num_flags())