Skip to content

Commit

Permalink
more fixes for page extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Nov 19, 2024
1 parent 1e2c5fa commit 2c86e63
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 13 additions & 0 deletions papermerge/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import os
import yaml
from pathlib import Path
from logging.config import dictConfig
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

Expand Down Expand Up @@ -46,3 +50,12 @@

if config.papermerge__search__url:
app.include_router(search_router, prefix=prefix)

logging_config_path = Path(
os.environ.get("PAPERMERGE__MAIN__LOGGING_CFG", "/etc/papermerge/logging.yaml")
)
if logging_config_path.exists() and logging_config_path.is_file():
with open(logging_config_path, "r") as stream:
config = yaml.load(stream, Loader=yaml.FullLoader)

dictConfig(config)
11 changes: 9 additions & 2 deletions papermerge/core/features/page_mngm/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,20 @@ def extract_pages(
notify_add_docs(db_session, [doc.id for doc in target_docs])
notify_generate_previews(list([str(doc.id) for doc in target_docs]))

logger.debug(
"len(old_doc_ver.pages) == moved_pages_count: "
f"{len(old_doc_ver.pages)} == {moved_pages_count}"
)
if len(old_doc_ver.pages) == moved_pages_count:
# all source pages were extracted, document should
# be deleted as its last version does not contain
# any page
db_session.execute(
delete(orm.Document).where(orm.Document.id == old_doc_ver.document.id)
delete_stmt = delete(orm.Node).where(orm.Node.id == old_doc_ver.document.id)
logger.debug(
f"DELETING source node: {delete_stmt}; document.id={old_doc_ver.document.id}"
)
db_session.execute(delete_stmt)
db_session.commit()
return [None, target_docs]

notify_generate_previews(str(source_doc.id))
Expand Down
4 changes: 4 additions & 0 deletions papermerge/core/features/page_mngm/test_page_mngm.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ def test_extract_all_pages_to_folder_each_page_in_separate_doc(
resource=ResourceFile.THREE_PAGES, user=user, parent=user.home_folder
)
dst_folder = make_folder(title="Target folder", user=user, parent=user.home_folder)
old_doc_count = db_session.execute(
select(func.count(orm.Document.id)).where(orm.Document.id == src.id)
).scalar()
assert old_doc_count == 1

src_ver = src.versions[0]
src_all_pages = db_session.execute(
Expand Down

0 comments on commit 2c86e63

Please sign in to comment.