from argos.web.search import search from argos.web.api import api, fields from argos.web.api.errors import not_found from argos.web.api.resources import page_parser, collection, PER_PAGE from flask.ext.restful import Resource, reqparse search_parser = reqparse.RequestParser() search_parser.add_argument('types', type=str) class Search(Resource): @collection(fields.search) def get(self, raw_query): args = search_parser.parse_args() page = page_parser.parse_args().get('page') raw_types = args.get('types') or 'event,story,concept' types = raw_types.split(',') if raw_query: results, total_count = search(raw_query, page, PER_PAGE, types=types) return results, total_count return not_found() api.add_resource(Search, '/search/<string:raw_query>')
@marshal_with(fields.event) def get(self, id): result = models.Event.query.get(id) return result or not_found() class Events(Resource): @collection(fields.event) def get(self): page = page_parser.parse_args().get('page') results = models.Event.query.paginate(page, per_page=PER_PAGE).items count = models.Event.query.count() return results, count or not_found() api.add_resource(Event, '/events/<int:id>') api.add_resource(Events, '/events') class Latest(Resource): @collection(fields.event) def get(self): page = page_parser.parse_args().get('page') feed_args = feed_parser.parse_args() from_date = feed_args.get('from', None) to_date = feed_args.get('to', None) if from_date and to_date: results = models.Event.query.filter( models.Event.created_at.between(from_date, to_date)).paginate(
class CurrentUser(Resource): @oauth.require_oauth('userinfo') @marshal_with(fields.user) def get(self): return request.oauth.user @oauth.require_oauth('userinfo') @marshal_with(fields.user) def patch(self): current_user = request.oauth.user for key, val in parser.parse_args().items(): setattr(current_user, key, val) db.session.commit() return '', 204 api.add_resource(CurrentUser, '/user') class CurrentUserWatching(Resource): @oauth.require_oauth('userinfo') @marshal_with(fields.story) def get(self): current_user = request.oauth.user return current_user.watching @oauth.require_oauth('userinfo') def post(self): current_user = request.oauth.user id = watching_parser.parse_args()['story_id'] story = models.Story.query.get(id) if not story: return not_found() current_user.watching.append(story)
return decorated return decorator class Event(Resource): @marshal_with(fields.event) def get(self, id): result = models.Event.query.get(id) return result or not_found() class Events(Resource): @collection(fields.event) def get(self): page = page_parser.parse_args().get('page') results = models.Event.query.paginate(page, per_page=PER_PAGE).items count = models.Event.query.count() return results, count or not_found() api.add_resource(Event, '/events/<int:id>') api.add_resource(Events, '/events') class Latest(Resource): @collection(fields.event) def get(self): page = page_parser.parse_args().get('page') feed_args = feed_parser.parse_args() from_date = feed_args.get('from', None) to_date = feed_args.get('to', None) if from_date and to_date: results = models.Event.query.filter(models.Event.created_at.between(from_date, to_date)).paginate(page, per_page=PER_PAGE).items elif from_date: results = models.Event.query.filter(models.Event.created_at >= from_date).paginate(page, per_page=PER_PAGE).items
@oauth.require_oauth('userinfo') @marshal_with(fields.user) def get(self): return request.oauth.user @oauth.require_oauth('userinfo') @marshal_with(fields.user) def patch(self): current_user = request.oauth.user for key, val in parser.parse_args().items(): setattr(current_user, key, val) db.session.commit() return '', 204 api.add_resource(CurrentUser, '/user') class CurrentUserWatching(Resource): @oauth.require_oauth('userinfo') @marshal_with(fields.story) def get(self): current_user = request.oauth.user return current_user.watching @oauth.require_oauth('userinfo') def post(self): current_user = request.oauth.user id = watching_parser.parse_args()['story_id'] story = models.Story.query.get(id) if not story: