Skip to content

Commit

Permalink
chore(API): refactor template upload
Browse files Browse the repository at this point in the history
Since the refactoring of the build, the documented commands don't work
anymore. Additionally the path to the templates changes now dynamically
with the python version used. This commit puts all the templates into
one global template directory. The command is refactored, so that it's
sufficient to provide the file name. The path to the template will then
be constructed in the command.
  • Loading branch information
open-dynaMIX committed Dec 19, 2024
1 parent e9687a1 commit 13560b3
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 17 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ docker compose up -d
# Wait for the database migrations to complete for the API and Caluma.
make caluma-loadconfig
# upload the templates to DMS
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/identity/templates/identity-labels.docx
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/accounting/templates/accounting-cover.docx
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/case/templates/acknowledgement-de.docx
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/case/templates/acknowledgement-fr.docx
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/case/templates/acknowledgement-en.docx
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/case/templates/credit-approval-de.docx
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/case/templates/credit-approval-fr.docx
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/case/templates/credit-approval-en.docx
docker compose run --rm api poetry run ./manage.py upload_template -t mysagw/case/templates/application.docx
docker compose run --rm api python manage.py upload_template -t identity-labels.docx
docker compose run --rm api python manage.py upload_template -t accounting-cover.docx
docker compose run --rm api python manage.py upload_template -t acknowledgement-de.docx
docker compose run --rm api python manage.py upload_template -t acknowledgement-fr.docx
docker compose run --rm api python manage.py upload_template -t acknowledgement-en.docx
docker compose run --rm api python manage.py upload_template -t credit-approval-de.docx
docker compose run --rm api python manage.py upload_template -t credit-approval-fr.docx
docker compose run --rm api python manage.py upload_template -t credit-approval-en.docx
docker compose run --rm api python manage.py upload_template -t application.docx
```

## Contributing
Expand Down
8 changes: 4 additions & 4 deletions api/mysagw/identity/management/commands/upload_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def __init__(self, *args, **kwargs):
self.client = DMSClient()

def template_file(self, value):
template = Path(value)
template = (
Path(__file__).parent.parent.parent.parent.absolute() / "templates" / value
)
if not template.exists() or not template.is_file:
msg = f"Template not found: {template}"
raise ArgumentTypeError(msg)
Expand All @@ -26,9 +28,7 @@ def add_arguments(self, parser):
parser.add_argument(
"-t",
"--template",
default=Path(__file__).parent.parent.parent.absolute()
/ "templates"
/ f"{settings.DOCUMENT_MERGE_SERVICE_LABELS_TEMPLATE_SLUG}.docx",
default=f"{settings.DOCUMENT_MERGE_SERVICE_LABELS_TEMPLATE_SLUG}.docx",
type=self.template_file,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io
from pathlib import Path

import pytest
from django.conf import settings
Expand All @@ -8,14 +7,12 @@

from mysagw.utils import build_url

TEMPLATE_PATH = Path(__file__).parent.parent.absolute() / "templates"


@pytest.mark.parametrize(
"args,success",
[
([], True),
(["-t", TEMPLATE_PATH / "identity-labels.docx"], True),
(["-t", "identity-labels.docx"], True),
(["-t", "no-existing-template.docx"], False),
],
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 13560b3

Please sign in to comment.