def get(self): if not is_auth(): return_bad_status('Вы не авторизованы!') time = datetime.now() tournaments_ = db.session.query(Tournament).filter(and_(Tournament.time_to_live > time, Tournament.private == 0)).all() tournaments = TournamentSchema(many=True).dump(tournaments_).data return return_ok_status(tournaments)
def process(self, form: FlaskForm, tournament_id): if not is_auth(): return return_bad_status("Вы не авторизованы!") message = (form.text.data, form.tournament.data) message.creator_id = session['username'] message.save() return return_ok_status('Сообщение отправлено!')
def post(self, id): creator = db.session.query(Tournament.creator).filter(Tournament.id == id) if session['username'] != creator: return_bad_status('Вы не создатель турнира!') if not is_auth(): return_bad_status('Вы не авторизованы!') Tournament.query.filter(Tournament.id == id).delete() db.session.commit() return return_ok_status('Турнир успешно удален!')
def post(self, tournament_id, task_id): task = Task.get_by_id(task_id) tournament = task.tournament creator_id = tournament.creator_id if session['id'] != creator_id: return return_bad_status('Вы не создатель турнира!') if not is_auth(): return return_bad_status('Вы не авторизованы!') Task.query.filter(Task.id == task_id).delete() db.session.commit() return return_ok_status('Задача успешно удалена!')
def process(self, form: FlaskForm, tournament_id): if not is_auth(): return return_bad_status("Вы не авторизованы!") Tournament.update_by_id(tournament_id, 'name', form.name.data) Tournament.update_by_id(tournament_id, 'description', form.description.data) Tournament.update_by_id(tournament_id, 'private', bool(int(form.private.data))) Tournament.update_by_id(tournament_id, 'platform', bool(int(form.platform.data))) Tournament.update_by_id(tournament_id, 'time', form.time.data) Tournament.update_by_id(tournament_id, 'time_to_live', form.time_to_live.data) Tournament.update_by_id(tournament_id, 'place', form.place.data) Tournament.update_by_id(tournament_id, 'online', bool(int(form.online.data))) Tournament.update_by_id(tournament_id, 'for_team_allowed', bool(int(form.for_team_allowed.data))) return return_ok_status('Все изменено.')
def process(self, form: FlaskForm): if not is_auth(): return return_bad_status("Вы не авторизованы!") user_id = session['id'] user = User.get_user_by_id(user_id) time = form.time.data time_to_live = form.time_to_live.data link = ''.join( random.choice(string.ascii_lowercase + string.digits) for _ in range(32)) tour = Tournament(form.name.data, form.description.data, user, time, time_to_live, form.place.data, link, bool(int(form.private.data)), bool(int(form.platform.data)), bool(int(form.online.data)), bool(int(form.for_team_allowed.data))) last = tour.add() return return_ok_status(last)
def decorator(*args, **kwargs): if not is_auth(): abort(401) return f(*args, **kwargs)