def post(self, request): if not request.session.get('is_admin', False): return redirect(self.not_admin_url) arena_form = ArenaForm(request.POST) if not arena_form.is_valid(): cursor.close() conn.close() return render(request, self.template_name, {"form": arena_form}) conn = cx_Oracle.connect(dbset.URL) cursor = conn.cursor() county = arena_form.cleaned_data['country'] name = arena_form.cleaned_data['arena_name'] city = arena_form.cleaned_data['city'] cursor.execute("BEGIN api.add_arena('{}', '{}', '{}'); END;".format( name, city, county)) log(conn, request.session['user_id'], "Add arena {}".format(name)) cursor.close() conn.commit() conn.close() return redirect(self.success_url)
def post(self, request, id): if not request.session.get('is_admin', False): return redirect(self.not_admin_url) conn = cx_Oracle.connect(dbset.URL) cursor = conn.cursor() cursor.execute("SELECT COUNT(*) FROM players WHERE id = {}".format(id)) if not cursor.fetchone()[0]: cursor.close() conn.close() raise Http404 cursor.execute('SELECT id, name FROM teams') teams = cursor.fetchall() + [(0, "None")] cursor.execute('SELECT id, name FROM team_roles') roles = cursor.fetchall() self.player_form = PlayerForm(teams, roles, request.POST) if not self.player_form.is_valid(): cursor.close() conn.close() return render(request, self.template_name, {"form": self.player_form}) first_name = self.player_form.cleaned_data['first_name'] last_name = self.player_form.cleaned_data['last_name'] date = self.player_form.cleaned_data['date'].isoformat() team = self.player_form.cleaned_data['team'] role = self.player_form.cleaned_data['role'] number = self.player_form.cleaned_data['number'] if team == "0": team = "NULL" cursor.execute( "alter SESSION set NLS_DATE_FORMAT = 'yyyy-mm-dd hh24:mi:ss'") cursor.execute( """BEGIN api.edit_player({}, '{}', '{}', '{}', {}, {}, {}); END;""" .format(id, first_name, last_name, date, team, role, number)) log(conn, request.session['user_id'], "change player {} {}".format(first_name, last_name)) cursor.close() conn.commit() conn.close() return redirect(self.success_url)
def post(self, request, match): if not request.session.get('is_admin', False): return redirect(self.not_admin_url) conn = cx_Oracle.connect(dbset.URL) cursor = conn.cursor() cursor.execute( " SELECT COUNT(*) FROM matchs WHERE id = {} ".format(match)) if not cursor.fetchall(): cursor.close() conn.close() raise Http404 cursor.execute( "SELECT * FROM TABLE(api.get_match_info({}))".format(match)) players = cursor.fetchall() cursor.execute("""SELECT id, color FROM card_types""") colors = cursor.fetchall() foul_form = FoulForm(colors, players, request.POST) if not foul_form.is_valid(): cursor.close() conn.close() return render(request, self.template_name, {"form": foul_form}) card = foul_form.cleaned_data['card'] player = foul_form.cleaned_data['player'] minute = foul_form.cleaned_data['minute'] cursor.execute("alter SESSION set NLS_TIMESTAMP_FORMAT = 'hh24:mi:ss'") cursor.execute( "BEGIN api.add_foul({}, {}, '{}:{}:0', {}); END;".format( card, match, minute // 60, minute % 60, player)) log(conn, request.session['user_id'], "Add foul at {} minute to match {}".format(minute, match)) cursor.close() conn.commit() conn.close() return redirect(reverse('match_info', args=(match, )))
def post(self, request, match): if not request.session.get('is_admin', False): return redirect(self.not_admin_url) conn = cx_Oracle.connect(dbset.URL) cursor = conn.cursor() cursor.execute( "SELECT * FROM TABLE(api.get_match_info({}))".format(match)) if not cursor.fetchall(): cursor.close() conn.close() raise Http404 cursor.execute( "SELECT id, first_name FROM TABLE(api.get_match_players({}))". format(match)) players = cursor.fetchall() goal_form = GoalForm(players, request.POST) if not goal_form.is_valid(): cursor.close() conn.close() return render(request, self.template_name, {"form": goal_form}) minutes = goal_form.cleaned_data['minute'] player = goal_form.cleaned_data['player'] cursor.execute("alter SESSION set NLS_TIMESTAMP_FORMAT = 'hh24:mi:ss'") cursor.execute( """BEGIN api.add_goal({}, '{}:{}:0', {}); END;""".format( match, minutes // 60, minutes % 60, player)) log(conn, request.session['user_id'], "Add goal at {} minute to match {}".format(minutes, match)) cursor.close() conn.commit() conn.close() return redirect(reverse('match_info', args=(match, )))
def post(self, request): if not request.session.get('is_admin', False): return redirect(self.not_admin_url) conn = cx_Oracle.connect(dbset.URL) cursor = conn.cursor() cursor.execute('SELECT id, name FROM teams') teams = cursor.fetchall() cursor.execute('SELECT id, name FROM team_roles') roles = cursor.fetchall() self.player_form = PlayerForm(teams, roles, request.POST) if not self.player_form.is_valid(): cursor.close() conn.close() return render(request, self.template_name, {"form": self.player_form}) first_name = self.player_form.cleaned_data['first_name'] last_name = self.player_form.cleaned_data['last_name'] date = self.player_form.cleaned_data['date'].isoformat() team = self.player_form.cleaned_data['team'] role = self.player_form.cleaned_data['role'] number = self.player_form.cleaned_data['number'] cursor.execute( "alter SESSION set NLS_DATE_FORMAT = 'yyyy-mm-dd hh24:mi:ss'") cursor.execute( """BEGIN api.add_player('{}', '{}', '{}', {}, {}, {}); END;""". format(first_name, last_name, date, team, role, number)) log(conn, request.session['user_id'], "Add foul at {}".format(minute)) cursor.close() conn.commit() conn.close() return redirect(AddPlayer.success_url)
def post(self, request): if not request.session.get('is_admin', False): return redirect(self.not_admin_url) team_form = TeamForm(request.POST, request.FILES) conn = cx_Oracle.connect(dbset.URL) cursor = conn.cursor() if not team_form.is_valid(): cursor.close() conn.close() return render(request, self.template_name, {"form": team_form}) files = os.listdir('static/emblems') pid = max([int(f.split('.')[0]) for f in files] + [0]) + 1 pname = 'emblems/{}.png'.format(pid) full_pname = '{}/{}'.format(self.static_path, pname) image = Image.open(io.BytesIO(team_form.cleaned_data['emblem'].read())) name = team_form.cleaned_data['team_name'] county = team_form.cleaned_data['country'] city = team_form.cleaned_data['city'] cursor.execute( """BEGIN api.add_team('{}', '{}', '{}', '{}'); END;""".format( name, city, county, pname)) log(conn, request.session['user_id'], "Add team {}".format(name)) cursor.close() conn.commit() conn.close() image.save(full_pname) return redirect(self.success_url)