Skip to content

Commit d1a6f84

Browse files
committed
finishing image pipeline
1 parent 5932784 commit d1a6f84

31 files changed

+483
-271
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
hooks:
2222
- id: pyright
2323
name: "Pyright"
24-
entry: bash -c 'ENV_NAME=dats source backend/_activate_current_env.sh && pyright'
24+
entry: bash -c 'PYRIGHT_PYTHON_PYLANCE_VERSION=2024.10.1 ENV_NAME=dats source backend/_activate_current_env.sh && pyright'
2525
language: system
2626
- repo: https://github.com/pre-commit/mirrors-eslint
2727
rev: v9.11.0

backend/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ JWT_SECRET=
1616

1717
# Where to store uploaded files.
1818
# <path_to_dats_repo>/docker/backend_repo
19-
REPO_ROOT=/insert_path_to_dats_repo/docker/backend_repo
19+
SHARED_REPO_ROOT=/insert_path_to_dats_repo/docker/backend_repo
2020

2121
# The system user is automatically created and owns automatically generated data.
2222
SYSTEM_USER_EMAIL="[email protected]"

backend/src/api/endpoints/import_.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def start_import_codes_job(
5353
)
5454
user_id = authz_user.user.id
5555
filename = f"import_user_code_{user_id}_{proj_id}.csv"
56-
filepath = repo._get_dst_path_for_temp_file(filename)
56+
filepath = repo.get_dst_path_for_temp_file(filename)
5757
filepath = repo.store_uploaded_file(
5858
uploaded_file=uploaded_file, filepath=filepath, fn=filename
5959
)
@@ -90,7 +90,7 @@ def start_import_tags_job(
9090
)
9191
user_id = authz_user.user.id
9292
filename = f"import_tags_{user_id}_{proj_id}.csv"
93-
filepath = repo._get_dst_path_for_temp_file(filename)
93+
filepath = repo.get_dst_path_for_temp_file(filename)
9494
filepath = repo.store_uploaded_file(
9595
uploaded_file=uploaded_file, filepath=filepath, fn=filename
9696
)
@@ -129,7 +129,7 @@ def start_import_project_project_metadata_job(
129129
)
130130
user_id = authz_user.user.id
131131
filename = f"import_project_project_metadata_{proj_id}.csv"
132-
filepath = repo._get_dst_path_for_temp_file(filename)
132+
filepath = repo.get_dst_path_for_temp_file(filename)
133133
filepath = repo.store_uploaded_file(
134134
uploaded_file=uploaded_file, filepath=filepath, fn=filename
135135
)
@@ -166,7 +166,7 @@ def start_import_project_metadata_job(
166166
user_id = current_user.id
167167
random_temp_project_name = str(uuid.uuid4())
168168
filename = f"import_project_{random_temp_project_name}_for_user_{user_id}.json"
169-
filepath = repo._get_dst_path_for_temp_file(filename)
169+
filepath = repo.get_dst_path_for_temp_file(filename)
170170
filepath = repo.store_uploaded_file(
171171
uploaded_file=uploaded_file, filepath=filepath, fn=filename
172172
)
@@ -206,7 +206,7 @@ def start_import_project_job(
206206
user_id = current_user.id
207207
random_temp_project_name = str(uuid.uuid4())
208208
filename = f"import_project_{random_temp_project_name}_for_user_{user_id}.zip"
209-
filepath = repo._get_dst_path_for_temp_file(filename)
209+
filepath = repo.get_dst_path_for_temp_file(filename)
210210
filepath = repo.store_uploaded_file(
211211
uploaded_file=uploaded_file, filepath=filepath, fn=filename
212212
)

backend/src/app/core/data/dto/code.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@ class CodeRead(CodeBaseDTO):
4141
updated: datetime = Field(description="Updated timestamp of the Code")
4242
is_system: bool = Field(description="Is the Code a system code")
4343
model_config = ConfigDict(from_attributes=True)
44+
45+
46+
# Properties for importing Codes
47+
class CodeImport(BaseModel):
48+
name: str = Field(description="Name of the Code")
49+
color: str = Field(description="Color of the Code")
50+
description: str = Field(description="Description of the Code")
51+
parent_name: Optional[str] = Field(
52+
description="Name of the Parent Code", default=None
53+
)
54+
created: datetime = Field(description="Created timestamp of the Code")

backend/src/app/core/data/export/export_service.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,26 @@ def __get_sdocs_metadata_for_export(
201201
sdoc_ids: Optional[List[int]] = None,
202202
sdocs: Optional[List[SourceDocumentRead]] = None,
203203
) -> List[Dict[str, Any]]:
204-
# TODO Flo: paging for too many docs
205-
if sdocs is None:
206-
if sdoc_ids is None:
204+
if sdoc_ids is None:
205+
if sdocs is None:
207206
raise ValueError("Either IDs or DTOs must be not None")
208-
sdocs = [
209-
SourceDocumentRead.model_validate(sdoc)
210-
for sdoc in crud_sdoc.read_by_ids(db=db, ids=sdoc_ids)
211-
]
207+
sdoc_ids = list(map(lambda sdoc: sdoc.id, sdocs))
208+
209+
sdoc_orms = crud_sdoc.read_by_ids(db=db, ids=sdoc_ids)
210+
211+
if sdocs is None:
212+
sdocs = [SourceDocumentRead.model_validate(sdoc) for sdoc in sdoc_orms]
213+
214+
sdoc_tags: Dict[int, List[DocumentTagORM]] = {sdoc.id: [] for sdoc in sdocs}
215+
for sdoc_orm in sdoc_orms:
216+
for tag in sdoc_orm.document_tags:
217+
sdoc_tags[sdoc_orm.id].append(tag)
218+
212219
exported_sdocs_metadata = []
220+
213221
for sdoc in sdocs:
214222
sdoc_metadatas = crud_sdoc_meta.read_by_sdoc(db=db, sdoc_id=sdoc.id)
215-
sdoc_tags = crud_project.read(db=db, id=sdoc.project_id).document_tags
223+
logger.info(f"export sdoc tags: {sdoc_tags[sdoc.id]} for {sdoc.filename}")
216224
sdoc_metadata_dtos = [
217225
SourceDocumentMetadataReadResolved.model_validate(sdoc_metadata)
218226
for sdoc_metadata in sdoc_metadatas
@@ -228,7 +236,7 @@ def __get_sdocs_metadata_for_export(
228236
"filename": sdoc.filename,
229237
"doctype": sdoc.doctype,
230238
"metadata": metadata_dict,
231-
"tags": [tag.name for tag in sdoc_tags],
239+
"tags": [tag.name for tag in sdoc_tags[sdoc.id]],
232240
}
233241
)
234242

0 commit comments

Comments
 (0)