mirror of https://github.com/papermerge/mglib
Compare commits
4 Commits
94a72760ca
...
1e6d1a10ec
Author | SHA1 | Date |
---|---|---|
Eugen Ciur | 1e6d1a10ec | |
Eugen Ciur | 535af7df83 | |
Eugen Ciur | e341100e69 | |
Eugen Ciur | faba619024 |
20
changelog.md
20
changelog.md
|
@ -1,6 +1,26 @@
|
|||
|
||||
# Changelog
|
||||
|
||||
## [1.3.5] - 14 December 2020
|
||||
|
||||
### Changed
|
||||
|
||||
- bug fixing of get_versions method
|
||||
|
||||
|
||||
## [1.3.4] - 14 December 2020
|
||||
|
||||
### Changed
|
||||
|
||||
- mglib.storage.get_versions(self, doc_path) method added
|
||||
|
||||
## [1.3.3] - 14 December 2020
|
||||
|
||||
### Changed
|
||||
|
||||
- mglib.path module adjusted to accept version argument. Supports
|
||||
getting/setting path to versioned documents.
|
||||
|
||||
## [1.3.2] - 1 December 2020
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -35,6 +35,39 @@ class Storage:
|
|||
exist_ok=True
|
||||
)
|
||||
|
||||
def get_versions(self, doc_path):
|
||||
"""
|
||||
Returns a list of (all) ordered versions
|
||||
of specific doc_path. Versions
|
||||
start with 0. Examples of return values:
|
||||
|
||||
- [0, 1, 2, 3] = 4 versions of the document
|
||||
- [ 0 ] = only one version (original)
|
||||
|
||||
To count versions it just counts number of subfolders
|
||||
in specific document folder. Versions are
|
||||
stored in subfolders named v1, v2, v3, ...
|
||||
"""
|
||||
abs_dirname_docs = self.path(
|
||||
doc_path.dirname_docs
|
||||
)
|
||||
try:
|
||||
only_dirs = [
|
||||
fi for fi in listdir(abs_dirname_docs) if isdir(
|
||||
join(abs_dirname_docs, fi)
|
||||
)
|
||||
]
|
||||
except FileNotFoundError:
|
||||
# in tests, document folders are not always created.
|
||||
# If no document folder is found, just return [ 0 ]
|
||||
# i.e that document has only one single version and it
|
||||
# is the latest one.
|
||||
return [0]
|
||||
|
||||
dirs_count = len(only_dirs)
|
||||
|
||||
return list(range(0, dirs_count + 1))
|
||||
|
||||
def get_pagecount(self, doc_path):
|
||||
"""
|
||||
Returns total number of pages for this doc_path.
|
||||
|
|
2
setup.py
2
setup.py
|
@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
|
|||
|
||||
setup(
|
||||
name="mglib",
|
||||
version="1.3.2",
|
||||
version="1.3.5",
|
||||
author="Eugen Ciur",
|
||||
author_email="eugen@papermerge.com",
|
||||
url="https://github.com/papermerge/mglib",
|
||||
|
|
|
@ -41,3 +41,49 @@ class TestStorage(unittest.TestCase):
|
|||
f1.exists()
|
||||
)
|
||||
|
||||
def test_get_versions_1(self):
|
||||
storage = FileSystemStorage(location=MEDIA_ROOT)
|
||||
|
||||
with TemporaryNode(MEDIA_ROOT) as media_root:
|
||||
docs = media_root.add_folder("docs")
|
||||
res = media_root.add_folder("results")
|
||||
f1 = docs.add_folder("user_1/document_2")
|
||||
f1.add_file("doku.pdf")
|
||||
# simulate 2 versions of the document.
|
||||
f1.add_folder("v1")
|
||||
f1.add_folder("v2")
|
||||
res.add_folder("user_1/document_2/pages")
|
||||
|
||||
doc_path = DocumentPath(
|
||||
user_id=1,
|
||||
document_id=2,
|
||||
file_name='doku.pdf',
|
||||
version=2
|
||||
)
|
||||
versions = storage.get_versions(doc_path)
|
||||
|
||||
self.assertEqual(
|
||||
versions, [0, 1, 2]
|
||||
)
|
||||
|
||||
def test_get_versions_2(self):
|
||||
storage = FileSystemStorage(location=MEDIA_ROOT)
|
||||
|
||||
with TemporaryNode(MEDIA_ROOT) as media_root:
|
||||
docs = media_root.add_folder("docs")
|
||||
f1 = docs.add_folder("user_1/document_2")
|
||||
f1.add_file("doku.pdf")
|
||||
|
||||
doc_path = DocumentPath(
|
||||
user_id=1,
|
||||
document_id=2,
|
||||
file_name='doku.pdf',
|
||||
version=2
|
||||
)
|
||||
versions = storage.get_versions(doc_path)
|
||||
|
||||
# document has only one version - the latest
|
||||
self.assertEqual(
|
||||
versions, [0]
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue