|
@@ -134,27 +134,37 @@ class File(NamedBaseModel):
|
|
|
collection = Collection.query.filter_by(reference=collection_reference).one()
|
|
|
self.collection_id = collection.id
|
|
|
|
|
|
- def _get_another_file(self, *query) -> T.Optional[File]:
|
|
|
+ def _get_another_file(self, *query, with_annotations=None) -> T.Optional[File]:
|
|
|
"""
|
|
|
get the first file matching the query ordered by descending id
|
|
|
|
|
|
:return: another file or None
|
|
|
"""
|
|
|
- return File.query.filter(File.project_id == self.project_id, *query)
|
|
|
+ result = File.query.filter(File.project_id == self.project_id, *query)
|
|
|
|
|
|
- def next(self) -> T.Optional[File]:
|
|
|
+ if with_annotations is None:
|
|
|
+ return result
|
|
|
+
|
|
|
+ annot_query = File.results.any()
|
|
|
+
|
|
|
+ if with_annotations == False:
|
|
|
+ annot_query = ~annot_query
|
|
|
+
|
|
|
+ return result.filter(annot_query)
|
|
|
+
|
|
|
+ def next(self, **kwargs) -> T.Optional[File]:
|
|
|
"""
|
|
|
get the successor of this file
|
|
|
|
|
|
:return: another file or None
|
|
|
"""
|
|
|
|
|
|
- res = self._get_another_file(File.path > self.path)\
|
|
|
+ res = self._get_another_file(File.path > self.path, **kwargs)\
|
|
|
.order_by(File.path)
|
|
|
return res.first()
|
|
|
|
|
|
|
|
|
- def previous(self) -> T.Optional[File]:
|
|
|
+ def previous(self, **kwargs) -> T.Optional[File]:
|
|
|
"""
|
|
|
get the predecessor of this file
|
|
|
|
|
@@ -162,23 +172,23 @@ class File(NamedBaseModel):
|
|
|
"""
|
|
|
|
|
|
# pylint: disable=no-member
|
|
|
- res = self._get_another_file(File.path < self.path)\
|
|
|
+ res = self._get_another_file(File.path < self.path, **kwargs)\
|
|
|
.order_by(File.path.desc())
|
|
|
return res.first()
|
|
|
|
|
|
|
|
|
- def next_in_collection(self) -> T.Optional[File]:
|
|
|
+ def next_in_collection(self, **kwargs) -> T.Optional[File]:
|
|
|
"""
|
|
|
get the predecessor of this file
|
|
|
|
|
|
:return: another file or None
|
|
|
"""
|
|
|
return self._get_another_file(
|
|
|
- File.path > self.path, File.collection_id == self.collection_id)\
|
|
|
+ File.path > self.path, File.collection_id == self.collection_id, **kwargs)\
|
|
|
.order_by(File.path).first()
|
|
|
|
|
|
|
|
|
- def previous_in_collection(self) -> T.Optional[File]:
|
|
|
+ def previous_in_collection(self, **kwargs) -> T.Optional[File]:
|
|
|
"""
|
|
|
get the predecessor of this file
|
|
|
|
|
@@ -187,7 +197,7 @@ class File(NamedBaseModel):
|
|
|
|
|
|
# pylint: disable=no-member
|
|
|
return self._get_another_file(
|
|
|
- File.path < self.path, File.collection_id == self.collection_id)\
|
|
|
+ File.path < self.path, File.collection_id == self.collection_id, **kwargs)\
|
|
|
.order_by(File.path.desc()).first()
|
|
|
|
|
|
|