def get(self, team_id): if team_id == 'me': if not authed(): abort(403) team = get_current_team() else: if accounts_visible() is False or scores_visible() is False: abort(404) team = Teams.query.filter_by(id=team_id).first_or_404() awards = team.get_awards( admin=is_admin() ) schema = AwardSchema(many=True) response = schema.dump(awards) if response.errors: return { 'success': False, 'errors': response.errors }, 400 return { 'success': True, 'data': response.data }
def post(self): req = request.get_json() user = get_current_user() req["user_id"] = user.id req["team_id"] = user.team_id Model = get_class_by_tablename(req["type"]) target = Model.query.filter_by(id=req["target"]).first_or_404() if target.cost > user.score: return ( { "success": False, "errors": { "score": "У вас недостаточно очков, чтобы разблокировать эту подсказку" }, }, 400, ) schema = UnlockSchema() response = schema.load(req, session=db.session) if response.errors: return {"success": False, "errors": response.errors}, 400 existing = Unlocks.query.filter_by(**req).first() if existing: return ( { "success": False, "errors": { "target": "Вы уже разблокировали это" }, }, 400, ) db.session.add(response.data) award_schema = AwardSchema() award = { "user_id": user.id, "team_id": user.team_id, "name": target.name, "description": target.description, "value": (-target.cost), "category": target.category, } award = award_schema.load(award) db.session.add(award.data) db.session.commit() clear_standings() response = schema.dump(response.data) return {"success": True, "data": response.data}
def post(self): req = request.get_json() user = get_current_user() req["user_id"] = user.id req["team_id"] = user.team_id Model = get_class_by_tablename(req["type"]) target = Model.query.filter_by(id=req["target"]).first_or_404() if target.cost > user.score: return ( { "success": False, "errors": { "score": "You do not have enough points to unlock this hint" }, }, 400, ) schema = UnlockSchema() response = schema.load(req, session=db.session) if response.errors: return {"success": False, "errors": response.errors}, 400 existing = Unlocks.query.filter_by(**req).first() if existing: return ( { "success": False, "errors": { "target": "You've already unlocked this this target" }, }, 400, ) db.session.add(response.data) award_schema = AwardSchema() award = { "user_id": user.id, "team_id": user.team_id, "name": target.name, "description": target.description, "value": (-target.cost), "category": target.category, } award = award_schema.load(award) db.session.add(award.data) db.session.commit() clear_standings() response = schema.dump(response.data) return {"success": True, "data": response.data}
def get(self): team = get_current_team() awards = team.get_awards(admin=True) schema = AwardSchema(many=True) response = schema.dump(awards) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self, query_args): q = query_args.pop("q", None) field = str(query_args.pop("field", None)) filters = build_model_filters(model=Awards, query=q, field=field) awards = Awards.query.filter_by(**query_args).filter(*filters).all() schema = AwardSchema(many=True) response = schema.dump(awards) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self, team_id): team = Teams.query.filter_by(id=team_id).first_or_404() if (team.banned or team.hidden) and is_admin() is False: abort(404) awards = team.get_awards(admin=is_admin()) schema = AwardSchema(many=True) response = schema.dump(awards) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def post(self): req = request.get_json() user = get_current_user() req['user_id'] = user.id req['team_id'] = user.team_id Model = get_class_by_tablename(req['type']) target = Model.query.filter_by(id=req['target']).first_or_404() if target.cost > user.score: return { 'success': False, 'errors': { 'score': 'You do not have enough points to unlock this hint' } }, 400 schema = UnlockSchema() response = schema.load(req, session=db.session) if response.errors: return { 'success': False, 'errors': response.errors }, 400 db.session.add(response.data) award_schema = AwardSchema() award = { 'user_id': user.id, 'team_id': user.team_id, 'name': target.name, 'description': target.description, 'value': (-target.cost), 'category': target.category } award = award_schema.load(award) db.session.add(award.data) db.session.commit() response = schema.dump(response.data) return { 'success': True, 'data': response.data }
def post(self): req = request.get_json() schema = AwardSchema() response = schema.load(req, session=db.session) if response.errors: return {"success": False, "errors": response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() return {"success": True, "data": response.data}
def get(self, award_id): award = Awards.query.filter_by(id=award_id).first_or_404() response = AwardSchema().dump(award) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def post(self): req = request.get_json() schema = AwardSchema() response = schema.load(req, session=db.session) if response.errors: return {"success": False, "errors": response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() # Delete standings cache because awards can change scores clear_standings() return {"success": True, "data": response.data}
def get(self): user = get_current_user() awards = user.get_awards(admin=True) view = "user" if not is_admin() else "admin" response = AwardSchema(view=view, many=True).dump(awards) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self, team_id): if team_id == "me": if not authed(): abort(403) team = get_current_team() awards = team.get_awards(admin=True) else: if accounts_visible() is False or scores_visible() is False: abort(404) team = Teams.query.filter_by(id=team_id).first_or_404() if (team.banned or team.hidden) and is_admin() is False: abort(404) awards = team.get_awards(admin=is_admin()) schema = AwardSchema(many=True) response = schema.dump(awards) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def post(self): req = request.get_json() # Force a team_id if in team mode and unspecified if is_teams_mode(): team_id = req.get("team_id") if team_id is None: user = Users.query.filter_by(id=req["user_id"]).first() if user.team_id is None: return ( { "success": False, "errors": { "team_id": [ "User doesn't have a team to associate award with" ] }, }, 400, ) req["team_id"] = user.team_id schema = AwardSchema() response = schema.load(req, session=db.session) if response.errors: return {"success": False, "errors": response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() # Delete standings cache because awards can change scores clear_standings() return {"success": True, "data": response.data}
def get(self, user_id): user = Users.query.filter_by(id=user_id).first_or_404() if (user.banned or user.hidden) and is_admin() is False: abort(404) awards = user.get_awards(admin=is_admin()) view = "user" if not is_admin() else "admin" response = AwardSchema(view=view, many=True).dump(awards) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self, user_id): if user_id == 'me': if not authed(): abort(403) user = get_current_user() else: if accounts_visible() is False or scores_visible() is False: abort(404) user = Users.query.filter_by(id=user_id).first_or_404() awards = user.get_awards(admin=is_admin()) view = 'user' if not is_admin() else 'admin' response = AwardSchema(view=view, many=True).dump(awards) if response.errors: return {'success': False, 'errors': response.errors}, 400 return {'success': True, 'data': response.data}
def get(self, user_id): if user_id == "me": if not authed(): abort(403) user = get_current_user() awards = user.get_awards(admin=True) else: if accounts_visible() is False or scores_visible() is False: abort(404) user = Users.query.filter_by(id=user_id).first_or_404() if (user.banned or user.hidden) and is_admin() is False: abort(404) awards = user.get_awards(admin=is_admin()) view = "user" if not is_admin() else "admin" response = AwardSchema(view=view, many=True).dump(awards) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def post(self): req = request.get_json() user = get_current_user() req["user_id"] = user.id req["team_id"] = user.team_id Model = get_class_by_tablename(req["type"]) target = Model.query.filter_by(id=req["target"]).first_or_404() # We should use the team's score if in teams mode if is_teams_mode(): team = get_current_team() score = team.score else: score = user.score if target.cost > score: return ( { "success": False, "errors": { "score": "You do not have enough points to unlock this hint" }, }, 400, ) schema = UnlockSchema() response = schema.load(req, session=db.session) if response.errors: return {"success": False, "errors": response.errors}, 400 # Search for an existing unlock that matches the target and type # And matches either the requesting user id or the requesting team id existing = Unlocks.query.filter( Unlocks.target == req["target"], Unlocks.type == req["type"], (Unlocks.user_id == req["user_id"]) | (Unlocks.team_id == req["team_id"]), ).first() if existing: return ( { "success": False, "errors": {"target": "You've already unlocked this this target"}, }, 400, ) db.session.add(response.data) award_schema = AwardSchema() award = { "user_id": user.id, "team_id": user.team_id, "name": target.name, "description": target.description, "value": (-target.cost), "category": target.category, } award = award_schema.load(award) db.session.add(award.data) db.session.commit() clear_standings() response = schema.dump(response.data) return {"success": True, "data": response.data}