def get(self, challenge_id): hints = Hints.query.filter_by(challenge_id=challenge_id).all() schema = HintSchema(many=True) response = schema.dump(hints) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def post(self): req = request.get_json() schema = HintSchema('admin') 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) return {'success': True, 'data': response.data}
def post(self): req = request.get_json() schema = HintSchema(view="admin") 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) return {"success": True, "data": response.data}
def patch(self, hint_id): hint = Hints.query.filter_by(id=hint_id).first_or_404() req = request.get_json() schema = HintSchema(view="admin") response = schema.load(req, instance=hint, partial=True, 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) return {"success": True, "data": response.data}
def get(self, hint_id): user = get_current_user() hint = Hints.query.filter_by(id=hint_id).first_or_404() view = "unlocked" if hint.cost: view = "locked" unlocked = HintUnlocks.query.filter_by(account_id=user.account_id, target=hint.id).first() if unlocked: view = "unlocked" solved = Solves.query.filter_by( account_id=user.account_id, challenge_id=hint.challenge_id).first() is not None if solved: view = "unlocked" if is_admin(): if request.args.get("preview", False): view = "admin" response = HintSchema(view=view).dump(hint) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self, hint_id): user = get_current_user() hint = Hints.query.filter_by(id=hint_id).first_or_404() view = 'unlocked' if hint.cost: view = 'locked' unlocked = HintUnlocks.query.filter_by( account_id=user.account_id, target=hint.id ).first() if unlocked: view = 'unlocked' if is_admin(): if request.args.get('preview', False): view = 'admin' response = HintSchema(view=view).dump(hint) if response.errors: return { 'success': False, 'errors': response.errors }, 400 return { 'success': True, 'data': response.data }
def get(self): hints = Hints.query.all() response = HintSchema(many=True).dump(hints) if response.errors: return {'success': False, 'errors': response.errors}, 400 return {'success': True, 'data': response.data}
def get(self): hints = Hints.query.all() response = HintSchema(many=True).dump(hints) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}
def get(self, hint_id): user = get_current_user() hint = Hints.query.filter_by(id=hint_id).first_or_404() if hint.requirements: requirements = hint.requirements.get("prerequisites", []) # Get the IDs of all hints that the user has unlocked all_unlocks = HintUnlocks.query.filter_by(account_id=user.account_id).all() unlock_ids = {unlock.target for unlock in all_unlocks} # Get the IDs of all free hints free_hints = Hints.query.filter_by(cost=0).all() free_ids = {h.id for h in free_hints} # Add free hints to unlocked IDs unlock_ids.update(free_ids) # Filter out hint IDs that don't exist all_hint_ids = {h.id for h in Hints.query.with_entities(Hints.id).all()} prereqs = set(requirements).intersection(all_hint_ids) # If the user has the necessary unlocks or is admin we should allow them to view if unlock_ids >= prereqs or is_admin(): pass else: return ( { "success": False, "errors": { "requirements": [ "You must unlock other hints before accessing this hint" ] }, }, 403, ) view = "unlocked" if hint.cost: view = "locked" unlocked = HintUnlocks.query.filter_by( account_id=user.account_id, target=hint.id ).first() if unlocked: view = "unlocked" if is_admin(): if request.args.get("preview", False): view = "admin" response = HintSchema(view=view).dump(hint) 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=Hints, query=q, field=field) hints = Hints.query.filter_by(**query_args).filter(*filters).all() response = HintSchema(many=True, view="locked").dump(hints) if response.errors: return {"success": False, "errors": response.errors}, 400 return {"success": True, "data": response.data}