Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project_title in Project and create_project #21

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions pycaprio/core/adapters/http_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def annotation(self, project: Union[Project, int], document: Union[Document, int
params={'format': annotation_format})
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(self, project: Union[Project, int], document_name: str, content: IO,
Expand Down
7 changes: 6 additions & 1 deletion pycaprio/core/objects/project.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
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 isinstance(other, Project) and \
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 @@ -42,7 +42,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
Loading