def project_group_add_project(project_group_id, project_id): session = api_base.get_session() with session.begin(subtransactions=True): project_group = _entity_get(project_group_id, session) if project_group is None: raise exc.NotFound(_("%(name)s %(id)s not found") % {'name': "Project Group", 'id': project_group_id}) project = projects.project_get(project_id) if project is None: raise exc.NotFound(_("%(name)s %(id)s not found") % {'name': "Project", 'id': project_id}) if project_id in [p.id for p in project_group.projects]: raise ClientSideError(_("The Project %(id)d is already in " "Project Group %(group_id)d") % {'id': project_id, 'group_id': project_group_id}) project_group.projects.append(project) session.add(project_group) return project_group
def project_group_delete_project(project_group_id, project_id): session = api_base.get_session() with session.begin(subtransactions=True): project_group = _entity_get(project_group_id, session) if project_group is None: raise exc.NotFound(_("%(name)s %(id)s not found") % {'name': "Project Group", 'id': project_group_id}) project = projects.project_get(project_id) if project is None: raise exc.NotFound(_("%(name)s %(id)s not found") % {'name': "Project", 'id': project_id}) if project_id not in [p.id for p in project_group.projects]: raise ClientSideError(_("The Project %(id)d is not in " "Project Group %(group_id)d") % {'id': project_id, 'group_id': project_group_id}) project_entry = [p for p in project_group.projects if p.id == project_id][0] project_group.projects.remove(project_entry) session.add(project_group) return project_group
def project_group_delete_project(project_group_id, project_id): session = api_base.get_session() with session.begin(subtransactions=True): project_group = _entity_get(project_group_id, session) if project_group is None: raise exc.NotFound( _("%(name)s %(id)s not found") % { 'name': "Project Group", 'id': project_group_id }) project = projects.project_get(project_id) if project is None: raise exc.NotFound( _("%(name)s %(id)s not found") % { 'name': "Project", 'id': project_id }) if project_id not in [p.id for p in project_group.projects]: raise ClientSideError( _("The Project %(id)d is not in " "Project Group %(group_id)d") % { 'id': project_id, 'group_id': project_group_id }) project_entry = [ p for p in project_group.projects if p.id == project_id ][0] project_group.projects.remove(project_entry) session.add(project_group) return project_group
def project_group_add_project(project_group_id, project_id): session = api_base.get_session() with session.begin(subtransactions=True): project_group = _entity_get(project_group_id, session) if project_group is None: raise exc.NotFound( _("%(name)s %(id)s not found") % { 'name': "Project Group", 'id': project_group_id }) project = projects.project_get(project_id) if project is None: raise exc.NotFound( _("%(name)s %(id)s not found") % { 'name': "Project", 'id': project_id }) if project_id in [p.id for p in project_group.projects]: raise ClientSideError( _("The Project %(id)d is already in " "Project Group %(group_id)d") % { 'id': project_id, 'group_id': project_group_id }) project_group.projects.append(project) session.add(project_group) return project_group
def get(self, marker=None, offset=None, limit=None, name=None, description=None, project_group_id=None, subscriber_id=None, sort_field='id', sort_dir='asc'): """Retrieve a list of projects. :param marker: The resource id where the page should begin. :param offset: The offset to start the page at. :param limit: The number of projects to retrieve. :param name: A string to filter the name by. :param description: A string to filter the description by. :param project_group_id: The ID of a project group to which the projects must belong. :param subscriber_id: The ID of a subscriber to filter results by. :param sort_field: The name of the field to sort on. :param sort_dir: Sort direction for results (asc, desc). """ # Boundary check on limit. if limit is not None: limit = max(0, limit) # Resolve the marker record. marker_project = None if marker is not None: marker_project = projects_api.project_get(marker) projects = \ projects_api.project_get_all(marker=marker_project, offset=offset, limit=limit, name=name, description=description, project_group_id=project_group_id, subscriber_id=subscriber_id, sort_field=sort_field, sort_dir=sort_dir) project_count = \ projects_api.project_get_count(name=name, description=description, project_group_id=project_group_id, subscriber_id=subscriber_id) # Apply the query response headers. if limit: response.headers['X-Limit'] = str(limit) response.headers['X-Total'] = str(project_count) if marker_project: response.headers['X-Marker'] = str(marker_project.id) if offset is not None: response.headers['X-Offset'] = str(offset) return [wmodels.Project.from_db_model(p) for p in projects]
def put(self, project_group_id, project_id): """Add a project to a project_group. :param project_group_id: An ID of the project group. :param project_id: An ID of project in this project group. """ project_groups.project_group_add_project(project_group_id, project_id) return wmodels.Project.from_db_model(projects.project_get(project_id))
def put(self, project_group_id, project_id): """Add a project to a project_group. :param project_group_id: An ID of the project group. :param project_id: An ID of project in this project group. """ project_groups.project_group_add_project(project_group_id, project_id) return wmodels.Project.from_db_model(projects.project_get(project_id))
def get_one_by_id(self, project_id): """Retrieve information about the given project. :param project_id: Project ID. """ project = projects_api.project_get(project_id) if project: return wmodels.Project.from_db_model(project) else: raise exc.NotFound(_("Project %s not found") % project_id)
def get_one_by_id(self, project_id): """Retrieve information about the given project. :param project_id: Project ID. """ project = projects_api.project_get(project_id) if project: return wmodels.Project.from_db_model(project) else: raise exc.NotFound(_("Project %s not found") % project_id)
def get(self, marker=None, offset=None, limit=None, name=None, description=None, project_group_id=None, subscriber_id=None, sort_field='id', sort_dir='asc'): """Retrieve a list of projects. :param marker: The resource id where the page should begin. :param offset: The offset to start the page at. :param limit: The number of projects to retrieve. :param name: A string to filter the name by. :param description: A string to filter the description by. :param project_group_id: The ID of a project group to which the projects must belong. :param subscriber_id: The ID of a subscriber to filter results by. :param sort_field: The name of the field to sort on. :param sort_dir: Sort direction for results (asc, desc). """ # Boundary check on limit. if limit is not None: limit = max(0, limit) # Resolve the marker record. marker_project = None if marker is not None: marker_project = projects_api.project_get(marker) projects = \ projects_api.project_get_all(marker=marker_project, offset=offset, limit=limit, name=name, description=description, project_group_id=project_group_id, subscriber_id=subscriber_id, sort_field=sort_field, sort_dir=sort_dir) project_count = \ projects_api.project_get_count(name=name, description=description, project_group_id=project_group_id, subscriber_id=subscriber_id) # Apply the query response headers. if limit: response.headers['X-Limit'] = str(limit) response.headers['X-Total'] = str(project_count) if marker_project: response.headers['X-Marker'] = str(marker_project.id) if offset is not None: response.headers['X-Offset'] = str(offset) return [wmodels.Project.from_db_model(p) for p in projects]
def put(self, project_group_id, project_id): """Add a project to a project_group. This command is only available to Admin users. Example:: curl https://my.example.org/api/v1/project_groups/17/projects/17 \\ -X PUT -H 'Authorization: Bearer MY_ACCESS_TOKEN' \\ -H 'Content-Type: application/json;charset=UTF-8' \\ --data-binary '{}' :param project_group_id: An ID of the project group. :param project_id: An ID of project in this project group. """ project_groups.project_group_add_project(project_group_id, project_id) return wmodels.Project.from_db_model(projects.project_get(project_id))