def add_team(): team_name = request.get_json() if not Team.get_team_by_name(team_name): team = Team.add_team(team_name) team_in_json = json.dumps(team.__dict__, ensure_ascii=False) return team_in_json return ""
def team_new(): if request.method == "POST": team_name = request.form['name'] if not Team.get_team_by_name(team_name): Team.add_team(team_name) return redirect(url_for('teams_ctrl.teams')) flash('Team name already in use') return render_template("add_team_form.html", title="Add new team", mainmenu=mainmenu)
def answer_on_task(team: Team, coords: tp.Tuple[float, float], answer: str) -> Attempt: competition = Competition.objects.filter().first() if not competition: raise CompetitionHasntStarted("Competition hasn't started yet :c") if dt.datetime.utcnow() > competition.date_end: raise CompetitionIsOver("Competition time is over!") task = Task.objects.filter(coords__near=coords).first() attempt = Attempt(task=task, team=team, answer=answer) if answer == task.correct_answer: attempt.is_correct = True team.tasks_done += 1 else: team.working_time += dt.timedelta(minutes=30) team.save() attempt.save() return attempt
def get_team_by_id(): team_id = request.get_json() students = User.get_user_list_by_role("student") students_for_json = [] for student in students: students_for_json.append((student.get_id(), student.get_name())) team = Team.get_team_by_id(team_id) team_data = (students_for_json, team.get_name()) team_data_json = json.dumps(team_data) return team_data_json
def scrape(): """ Scrape team stats for the given seasons. """ for season in [2013, 2014, 2015, 2016]: print 'getting season data for {0}'.format(season) html = get_team_stats_html(season) data_by_team = scrape_team_stats(html) for team_name, data in data_by_team.iteritems(): team = Team.get_or_create(team_name) data['season'] = int(season) data['team_id'] = team.id stats = Stats(**data) Stats.add(stats)
def team_edit(team_id): if request.method == "POST": if request.form['name']: team_name = request.form['name'] Team.get_team_by_id(team_id).set_name(team_name) if request.form['student']: student_id = int(''.join( filter(lambda x: x.isdigit(), request.form['student']))) if Student.get_student_team_id(student_id): Team.get_team_by_id(team_id).relocate_member(student_id) else: Team.get_team_by_id(team_id).add_member( User.get_user_by_id(student_id)) return render_template("edit_team_form.html", team=Team.get_team_by_id(team_id), student_list=User.get_user_list_by_role('student'), mainmenu=mainmenu)
def edit_team(): team_id = request.get_json()['id'] new_team_name = request.get_json()['name'] if request.get_json()['new_member'] != '' and ( new_team_name == Team.get_team_by_id(team_id).get_name() or not Team.get_team_by_name(new_team_name)): new_member = request.get_json()['new_member'] Team.get_team_by_id(team_id).set_name(new_team_name) student_id = int(''.join(filter(lambda x: x.isdigit(), new_member))) if Student.get_student_team_id(student_id): Team.get_team_by_id(team_id).relocate_member(student_id) else: Team.get_team_by_id(team_id).add_member( User.get_user_by_id(student_id)) student_name = Student.get_user_by_id(student_id).get_name() edited_data = (new_team_name, student_name, student_id) edited_data_json = json.dumps(edited_data) return edited_data_json elif new_team_name == Team.get_team_by_id( team_id).get_name() or not Team.get_team_by_name(new_team_name): Team.get_team_by_id(team_id).set_name(new_team_name) edited_data = new_team_name edited_data_json = json.dumps(edited_data) return edited_data_json else: return ''
def team_details(team_id): return render_template("team_details.html", team=Team.get_team_by_id(team_id), mainmenu=mainmenu)
def teams(): return render_template("teams.html", teams_list=Team.get_list_teams(), mainmenu=mainmenu)
def remove_member(): team_id = request.get_json()['team_id'] student_id = request.get_json()['member_id'] Team.get_team_by_id(team_id).remove_member(User.get_user_by_id(student_id)) return ''
def team_remove_student(team_id, student_id): Team.get_team_by_id(team_id).remove_member(User.get_user_by_id(student_id)) return redirect(url_for('teams_ctrl.team_edit', team_id=team_id))
def team_by_id(team_id): team = Team.team_by_id(team_id) return jsonify({'fixtures': team})
def get_table(season, league_id): table = Team.league_table(season, league_id) # table = table_fake return jsonify(table)
def initiate_new_team(title: str, user: TeamUser) -> Team: """Creates new team by its title and auth user.""" team = Team(title=title, user=user) team.save() return team