def get(self, query_args): q = query_args.pop("q", None) field = str(query_args.pop("field", None)) filters = build_model_filters(model=Submissions, query=q, field=field) args = query_args schema = SubmissionSchema(many=True) submissions = (Submissions.query.filter_by(**args).filter( *filters).paginate(max_per_page=100)) response = schema.dump(submissions.items) if response.errors: return {"success": False, "errors": response.errors}, 400 return { "meta": { "pagination": { "page": submissions.page, "next": submissions.next_num, "prev": submissions.prev_num, "pages": submissions.pages, "per_page": submissions.per_page, "total": submissions.total, } }, "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) fails = team.get_fails(admin=is_admin()) view = "admin" if is_admin() else "user" # We want to return the count purely for stats & graphs # but this data isn't really needed by the end user. # Only actually show fail data for admins. if is_admin(): schema = SubmissionSchema(view=view, many=True) response = schema.dump(fails) if response.errors: return {"success": False, "errors": response.errors}, 400 data = response.data else: data = [] count = len(fails) return {"success": True, "data": data, "meta": {"count": count}}
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() solves = team.get_solves( admin=is_admin() ) view = 'admin' if is_admin() else 'user' schema = SubmissionSchema(view=view, many=True) response = schema.dump(solves) 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() 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) fails = team.get_fails(admin=is_admin()) view = 'admin' if is_admin() else 'user' schema = SubmissionSchema(view=view, many=True) response = schema.dump(fails) if response.errors: return {'success': False, 'errors': response.errors}, 400 if is_admin(): data = response.data else: data = [] count = len(response.data) return {'success': True, 'data': data, 'meta': {'count': count}}
def get(self, team_id): if team_id == "me": if not authed(): abort(403) team = get_current_team() fails = team.get_fails(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) fails = team.get_fails(admin=is_admin()) view = "admin" if is_admin() else "user" schema = SubmissionSchema(view=view, many=True) response = schema.dump(fails) if response.errors: return {"success": False, "errors": response.errors}, 400 if is_admin(): data = response.data else: data = [] count = len(response.data) return {"success": True, "data": data, "meta": {"count": count}}
def get(self, submission_id): submission = Submissions.query.filter_by( id=submission_id).first_or_404() schema = SubmissionSchema() response = schema.dump(submission) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self): team = get_current_team() solves = team.get_solves(admin=True) view = "admin" if is_admin() else "user" schema = SubmissionSchema(view=view, many=True) response = schema.dump(solves) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self): args = request.args.to_dict() schema = SubmissionSchema(many=True) if args: submissions = Submissions.query.filter_by(**args).all() else: submissions = Submissions.query.all() response = schema.dump(submissions) 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) solves = team.get_solves(admin=is_admin()) view = "admin" if is_admin() else "user" schema = SubmissionSchema(view=view, many=True) response = schema.dump(solves) 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() if (user.banned or user.hidden) and is_admin() is False: abort(404) fails = user.get_fails(admin=is_admin()) view = 'user' if not is_admin() else 'admin' response = SubmissionSchema(view=view, many=True).dump(fails) if response.errors: return {'success': False, 'errors': response.errors}, 400 if is_admin(): data = response.data else: data = [] count = len(response.data) return {'success': True, 'data': data, 'meta': {'count': count}}
def get(self, user_id): if user_id == "me": if not authed(): abort(403) user = get_current_user() fails = user.get_fails(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) fails = user.get_fails(admin=is_admin()) view = "user" if not is_admin() else "admin" response = SubmissionSchema(view=view, many=True).dump(fails) if response.errors: return {"success": False, "errors": response.errors}, 400 if is_admin(): data = response.data else: data = [] count = len(response.data) return {"success": True, "data": data, "meta": {"count": count}}
def post(self): req = request.get_json() Model = Submissions.get_child(type=req.get("type")) schema = SubmissionSchema(instance=Model()) response = schema.load(req) 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 clear_standings() return {"success": True, "data": response.data}
def get(self): team = get_current_team() fails = team.get_fails(admin=True) view = "admin" if is_admin() else "user" schema = SubmissionSchema(view=view, many=True) response = schema.dump(fails) if response.errors: return {"success": False, "errors": response.errors}, 400 if is_admin(): data = response.data else: data = [] count = len(response.data) return {"success": True, "data": data, "meta": {"count": count}}
def get(self): user = get_current_user() solves = user.get_solves(admin=True) view = "user" if not is_admin() else "admin" response = SubmissionSchema(view=view, many=True).dump(solves) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self): team = get_current_team() fails = team.get_fails(admin=True) view = "admin" if is_admin() else "user" # We want to return the count purely for stats & graphs # but this data isn't really needed by the end user. # Only actually show fail data for admins. if is_admin(): schema = SubmissionSchema(view=view, many=True) response = schema.dump(fails) if response.errors: return {"success": False, "errors": response.errors}, 400 data = response.data else: data = [] count = len(fails) return {"success": True, "data": data, "meta": {"count": count}}
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) solves = user.get_solves(admin=is_admin()) view = "user" if not is_admin() else "admin" response = SubmissionSchema(view=view, many=True).dump(solves) if response.errors: return {"success": False, "errors": response.errors}, 400 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) fails = user.get_fails(admin=is_admin()) view = "user" if not is_admin() else "admin" response = SubmissionSchema(view=view, many=True).dump(fails) if response.errors: return {"success": False, "errors": response.errors}, 400 if is_admin(): data = response.data else: data = [] count = len(response.data) # return {"success": True, "data": data, "meta": {"count": count}} return {"success": True, "data": None, "meta": {"count": None}}
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() solves = user.get_solves(admin=is_admin()) for solve in solves: setattr(solve, 'value', 100) view = 'user' if not is_admin() else 'admin' response = SubmissionSchema(view=view, many=True).dump(solves) if response.errors: return {'success': False, 'errors': response.errors}, 400 return {'success': True, 'data': response.data}