|
@@ -50,9 +50,7 @@ class Project(NamedBaseModel):
|
|
lazy="dynamic",
|
|
lazy="dynamic",
|
|
passive_deletes=True)
|
|
passive_deletes=True)
|
|
|
|
|
|
- serialize_only = (
|
|
|
|
- "id",
|
|
|
|
- "name",
|
|
|
|
|
|
+ serialize_only = NamedBaseModel.serialize_only + (
|
|
"created",
|
|
"created",
|
|
"description",
|
|
"description",
|
|
"model_id",
|
|
"model_id",
|
|
@@ -66,16 +64,26 @@ class Project(NamedBaseModel):
|
|
"""
|
|
"""
|
|
get a label using its unique identifier
|
|
get a label using its unique identifier
|
|
|
|
|
|
- :param identifier: unique identifier
|
|
|
|
|
|
+ :param id: unique identifier
|
|
:return: label
|
|
:return: label
|
|
"""
|
|
"""
|
|
|
|
+
|
|
return self.labels.filter_by(id=id).one_or_none()
|
|
return self.labels.filter_by(id=id).one_or_none()
|
|
|
|
|
|
|
|
+ def label_by_reference(self, reference: str) -> T.Optional[Label]:
|
|
|
|
+ """
|
|
|
|
+ get a label using its reference string
|
|
|
|
+
|
|
|
|
+ :param reference: reference string
|
|
|
|
+ :return: label
|
|
|
|
+ """
|
|
|
|
+ return self.labels.filter_by(reference=reference).one_or_none()
|
|
|
|
+
|
|
def file(self, id: int) -> T.Optional[Label]:
|
|
def file(self, id: int) -> T.Optional[Label]:
|
|
"""
|
|
"""
|
|
get a file using its unique identifier
|
|
get a file using its unique identifier
|
|
|
|
|
|
- :param identifier: unique identifier
|
|
|
|
|
|
+ :param id: unique identifier
|
|
:return: file
|
|
:return: file
|
|
"""
|
|
"""
|
|
return self.files.filter_by(id=id).one_or_none()
|
|
return self.files.filter_by(id=id).one_or_none()
|
|
@@ -99,7 +107,7 @@ class Project(NamedBaseModel):
|
|
return self.collections.filter_by(reference=reference).one_or_none()
|
|
return self.collections.filter_by(reference=reference).one_or_none()
|
|
|
|
|
|
def create_label(self, name: str, reference: str = None,
|
|
def create_label(self, name: str, reference: str = None,
|
|
- parent_id: int = None, commit: bool = True) -> T.Tuple[T.Optional[Label], bool]:
|
|
|
|
|
|
+ parent: T.Union[Label, int, str] = None, commit: bool = True) -> T.Tuple[T.Optional[Label], bool]:
|
|
"""
|
|
"""
|
|
create a label for this project. If there is already a label with the same reference
|
|
create a label for this project. If there is already a label with the same reference
|
|
in the database its name is updated.
|
|
in the database its name is updated.
|
|
@@ -110,10 +118,16 @@ class Project(NamedBaseModel):
|
|
:return: created or edited label, insert
|
|
:return: created or edited label, insert
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
+ if isinstance(parent, str):
|
|
|
|
+ parent = self.label_by_reference(parent)
|
|
|
|
+
|
|
|
|
+ if isinstance(parent, Label):
|
|
|
|
+ parent = parent.id
|
|
|
|
+
|
|
label, is_new = Label.get_or_create(project=self, reference=reference)
|
|
label, is_new = Label.get_or_create(project=self, reference=reference)
|
|
|
|
|
|
label.name = name
|
|
label.name = name
|
|
- label.set_parent(parent_id, commit=False)
|
|
|
|
|
|
+ label.set_parent(parent, commit=False)
|
|
|
|
|
|
if commit:
|
|
if commit:
|
|
self.commit()
|
|
self.commit()
|
|
@@ -126,9 +140,20 @@ class Project(NamedBaseModel):
|
|
description: str,
|
|
description: str,
|
|
position: int,
|
|
position: int,
|
|
autoselect: bool,
|
|
autoselect: bool,
|
|
- commit: bool = True):
|
|
|
|
|
|
+ commit: bool = True) -> T.Tuple[Collection, bool]:
|
|
|
|
+ """
|
|
|
|
+ create a new collection associated with this project
|
|
|
|
+
|
|
|
|
+ :param reference: collection reference string
|
|
|
|
+ :param name: collection name
|
|
|
|
+ :param description: collection description
|
|
|
|
+ :param position: position in menus
|
|
|
|
+ :param autoselect: automatically select this collection on session load
|
|
|
|
+
|
|
|
|
+ :return: collection object, insert
|
|
|
|
+ """
|
|
|
|
|
|
- collection, is_new = Collection.get_or_create(project=self, reference=reference)
|
|
|
|
|
|
+ collection, is_new = Collection.get_or_create(project_id=self.id, reference=reference)
|
|
collection.name = name
|
|
collection.name = name
|
|
collection.description = description
|
|
collection.description = description
|
|
collection.position = position
|
|
collection.position = position
|