diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7cc40d10a..b1376ee51 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,8 +1,9 @@ # Contributing -Contributions to mysagw are very welcome! Best have a look at the open [issues](https://github.com/adfinis-sygroup/mysagw) -and open a [GitHub pull request](https://github.com/adfinis-sygroup/mysagw/compare). See instructions below how to setup development -environment. Before writing any code, best discuss your proposed change in a GitHub issue to see if the proposed change makes sense for the project. +Contributions to mySAGW are very welcome! Best have a look at the open [issues](https://github.com/adfinis-sygroup/mysagw) +and open a [GitHub pull request](https://github.com/adfinis-sygroup/mysagw/compare). See instructions below how to set up development +environment. Before writing any code, best discuss your proposed change in a GitHub +issue to see if the proposed change makes sense for the project. ## Setup development environment @@ -11,14 +12,23 @@ environment. Before writing any code, best discuss your proposed change in a Git To work on mysagw you first need to clone ```bash -git clone https://github.com/adfinis-sygroup/mysagw.git -cd mysagw +git clone https://github.com/adfinis/mySAGW.git +cd mySAGW +``` + +### Build the dev containers + +By default, it pulls images for prod, that don't contain any tooling needed during dev. +In order to have those tools available, you need to build those containers first: + +```bash +docker compose build --pull api caluma ``` ### Open Shell Once it is cloned you can easily open a shell in the docker container to -open an development environment. +open a development environment. ```bash # needed for permission handling @@ -43,8 +53,7 @@ ruff format . pytest # create migrations ./manage.py makemigrations -# install debugger or other temporary dependencies -pip install --user pdbpp +# you can use pip to install other temporary dependencies ``` Writing of code can still happen outside the docker container of course. diff --git a/README.md b/README.md index 224f0d6a7..7b8dd0b23 100644 --- a/README.md +++ b/README.md @@ -85,15 +85,10 @@ 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 identity-labels.docx \ + accounting-cover.docx acknowledgement-de.docx acknowledgement-fr.docx \ + acknowledgement-en.docx credit-approval-de.docx credit-approval-fr.docx \ + credit-approval-en.docx application.docx ``` ## Contributing diff --git a/api/mysagw/identity/management/commands/upload_template.py b/api/mysagw/identity/management/commands/upload_template.py index b1137c625..9869f7256 100644 --- a/api/mysagw/identity/management/commands/upload_template.py +++ b/api/mysagw/identity/management/commands/upload_template.py @@ -1,5 +1,4 @@ from argparse import ArgumentTypeError -from pathlib import Path from django.conf import settings from django.core.management.base import BaseCommand @@ -9,14 +8,14 @@ class Command(BaseCommand): - help = "Upload template for exports" + help = "Upload templates for exports" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.client = DMSClient() def template_file(self, value): - template = Path(value) + template = settings.DOCUMENT_MERGE_SERVICE_TEMPLATE_DIR / value if not template.exists() or not template.is_file: msg = f"Template not found: {template}" raise ArgumentTypeError(msg) @@ -24,12 +23,13 @@ def template_file(self, value): 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", + "templates", + default=[ + settings.DOCUMENT_MERGE_SERVICE_TEMPLATE_DIR + / f"{settings.DOCUMENT_MERGE_SERVICE_LABELS_TEMPLATE_SLUG}.docx" + ], type=self.template_file, + nargs="*", ) def _upload_template(self, template, update=False): @@ -51,6 +51,7 @@ def _upload_template(self, template, update=False): return True def handle(self, *args, **options): - template = options.get("template") - if self._upload_template(template) is False: - assert self._upload_template(template, update=True) is True + templates = options.get("templates") + for template in templates: + if self._upload_template(template) is False: + assert self._upload_template(template, update=True) is True diff --git a/api/mysagw/identity/tests/test_upload_labels_template_command.py b/api/mysagw/identity/tests/test_upload_labels_template_command.py index 87790309d..87be68bee 100644 --- a/api/mysagw/identity/tests/test_upload_labels_template_command.py +++ b/api/mysagw/identity/tests/test_upload_labels_template_command.py @@ -1,5 +1,4 @@ import io -from pathlib import Path import pytest from django.conf import settings @@ -8,15 +7,13 @@ 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", "no-existing-template.docx"], False), + (["identity-labels.docx"], True), + (["no-existing-template.docx"], False), ], ) def test_upload_labels_template_command(requests_mock, args, success): @@ -56,5 +53,5 @@ def do_assertions(m): with pytest.raises(CommandError) as e: call_command("upload_template", *args) assert e.value.args[0].startswith( - "Error: argument -t/--template: Template not found:", + "Error: argument templates: Template not found:", ) diff --git a/api/mysagw/settings.py b/api/mysagw/settings.py index 825b87ded..b96766b12 100644 --- a/api/mysagw/settings.py +++ b/api/mysagw/settings.py @@ -168,11 +168,14 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET): "DOCUMENT_MERGE_SERVICE_URL", default="http://dms:8000/api/v1", ) + DOCUMENT_MERGE_SERVICE_ENGINE = env.str( "DOCUMENT_MERGE_SERVICE_ENGINE", default="docx-template", ) +DOCUMENT_MERGE_SERVICE_TEMPLATE_DIR = Path(__file__).parent.resolve() / "templates" + DOCUMENT_MERGE_SERVICE_LABELS_TEMPLATE_SLUG = env.str( "DOCUMENT_MERGE_SERVICE_LABELS_TEMPLATE_SLUG", default="identity-labels", diff --git a/api/mysagw/accounting/templates/accounting-cover.docx b/api/mysagw/templates/accounting-cover.docx similarity index 100% rename from api/mysagw/accounting/templates/accounting-cover.docx rename to api/mysagw/templates/accounting-cover.docx diff --git a/api/mysagw/case/templates/acknowledgement-de.docx b/api/mysagw/templates/acknowledgement-de.docx similarity index 100% rename from api/mysagw/case/templates/acknowledgement-de.docx rename to api/mysagw/templates/acknowledgement-de.docx diff --git a/api/mysagw/case/templates/acknowledgement-en.docx b/api/mysagw/templates/acknowledgement-en.docx similarity index 100% rename from api/mysagw/case/templates/acknowledgement-en.docx rename to api/mysagw/templates/acknowledgement-en.docx diff --git a/api/mysagw/case/templates/acknowledgement-fr.docx b/api/mysagw/templates/acknowledgement-fr.docx similarity index 100% rename from api/mysagw/case/templates/acknowledgement-fr.docx rename to api/mysagw/templates/acknowledgement-fr.docx diff --git a/api/mysagw/case/templates/application.docx b/api/mysagw/templates/application.docx similarity index 100% rename from api/mysagw/case/templates/application.docx rename to api/mysagw/templates/application.docx diff --git a/api/mysagw/case/templates/credit-approval-de.docx b/api/mysagw/templates/credit-approval-de.docx similarity index 100% rename from api/mysagw/case/templates/credit-approval-de.docx rename to api/mysagw/templates/credit-approval-de.docx diff --git a/api/mysagw/case/templates/credit-approval-en.docx b/api/mysagw/templates/credit-approval-en.docx similarity index 100% rename from api/mysagw/case/templates/credit-approval-en.docx rename to api/mysagw/templates/credit-approval-en.docx diff --git a/api/mysagw/case/templates/credit-approval-fr.docx b/api/mysagw/templates/credit-approval-fr.docx similarity index 100% rename from api/mysagw/case/templates/credit-approval-fr.docx rename to api/mysagw/templates/credit-approval-fr.docx diff --git a/api/mysagw/identity/templates/identity-labels.docx b/api/mysagw/templates/identity-labels.docx similarity index 100% rename from api/mysagw/identity/templates/identity-labels.docx rename to api/mysagw/templates/identity-labels.docx