Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Pycaprio uses the `Project` object to model INCEpTION's projects, and has these

* `project_id`: Id of the project (integer).
* `project_name`: Project name (string).

* `project_title`: Project title (string).

### List projects
Lists all the projects that are in INCEpTION.
Expand All @@ -28,7 +28,7 @@ print(project) # <Project #1: Project name>
```

### Create project
Creates a project in INCEpTION. It requires the project's name and optionally the creator's username.
Creates a project in INCEpTION. It requires the project's name and optionally the project's title and the creator's username.
If no `creator_name` is provided, pycaprio will use the one of the user that is currently logged in to the API.

Example:
Expand Down
9 changes: 7 additions & 2 deletions pycaprio/core/adapters/http_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ def annotation(
)
return response.content

def create_project(self, project_name: str, creator_name: Optional[str] = None) -> Project:
def create_project(
self, project_name: str, project_title: Optional[str] = None, creator_name: Optional[str] = None
) -> Project:
creator_name = creator_name or self.default_username
response = self.client.post("/projects", data={"creator": creator_name, "name": project_name})
project_title = project_title or project_name
response = self.client.post(
"/projects", data={"creator": creator_name, "name": project_name, "title": project_title}
)
return ProjectSchema().load(response.json()["body"])

def create_document(
Expand Down
8 changes: 7 additions & 1 deletion pycaprio/core/objects/project.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from typing import Optional


class Project:
"""
INCEpTION's Project object
"""

def __init__(self, project_id: int, project_name: str):
def __init__(self, project_id: int, project_name: str, project_title: Optional[str] = None):
self.project_id = project_id
self.project_name = project_name
if project_title is None:
project_title = project_name
self.project_title = project_title

def __eq__(self, other):
return (
Expand Down
4 changes: 2 additions & 2 deletions pycaprio/core/schemas/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ProjectSchema(BaseInceptionSchema):
def load(self, project_dict: serialized_type, many: bool = False) -> deserialized_type:
if many:
return [self.load(project, many=False) for project in project_dict]
return Project(project_dict["id"], project_dict["name"])
return Project(project_dict["id"], project_dict["name"], project_dict["title"])

def dump(self, project: deserialized_type, many: bool = False) -> serialized_type:
if many:
return [self.dump(p, many=False) for p in project]
return {"id": project.project_id, "name": project.project_name}
return {"id": project.project_id, "name": project.project_name, "title": project.project_title}
2 changes: 1 addition & 1 deletion tests/unit_tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def deserialized_project(mock_project_name: str, mock_project_id: int):

@pytest.fixture
def serialized_project(mock_project_name: str, mock_project_id: int):
return {"id": mock_project_id, "name": mock_project_name}
return {"id": mock_project_id, "name": mock_project_name, "title": mock_project_name}


# Fixtures for document
Expand Down