def projects_relationship_allocations(project_id: str): """ Returns Allocation resource linkages associated with a specific Project resource, specified by its Neutral ID :type project_id: str :param project_id: neutral ID of a Project resource """ try: project = Project.query.filter_by(neutral_id=project_id).one() payload = ProjectSchema(resource_linkage='allocations').dump(project) return jsonify(payload) except NoResultFound: raise NotFound() except MultipleResultsFound: raise UnprocessableEntity()
def projects_participants(project_id: str): """ Returns Participant resources associated with a specific Project resource, specified by its Neutral ID :type project_id: str :param project_id: neutral ID of a Project resource """ try: project = Project.query.filter_by(neutral_id=project_id).one() payload = ProjectSchema(related_resource='participants', many_related=True).dump(project) return jsonify(payload) except NoResultFound: raise NotFound() except MultipleResultsFound: raise UnprocessableEntity()
def projects_detail(project_id: str): """ Returns a specific Project resource, specified by its Neutral ID :type project_id: str :param project_id: neutral ID of a Project resource """ try: project = Project.query.filter_by(neutral_id=project_id).one() payload = ProjectSchema(include_data=( 'participants', 'participants.person', 'participants.person.organisation', 'allocations', 'allocations.grant', 'allocations.grant.funder', 'categorisations', 'categorisations.category', 'categorisations.category.category_scheme', 'categorisations.category.parent_category')).dump(project) return jsonify(payload) except NoResultFound: raise NotFound() except MultipleResultsFound: raise UnprocessableEntity()
def projects_list(): """ Returns all Project resources The response is paginated. """ page = request.args.get('page', type=int) if page is None: page = 1 projects = Project.query.paginate(page=page, per_page=app.config['APP_PAGE_SIZE']) payload = ProjectSchema( many=True, paginate=True, include_data=( 'participants', 'participants.person', 'participants.person.organisation', 'allocations', 'allocations.grant', 'allocations.grant.funder', 'categorisations', 'categorisations.category', 'categorisations.category.category_scheme', 'categorisations.category.parent_category')).dump(projects) return jsonify(payload)