diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index b4d8019..9aad7ef 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -13,7 +13,8 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.10","3.11","3.12"] + python-version: ["3.10", "3.11","3.12"] + django-version: ["3.2.9","4.1","5.1"] steps: - uses: actions/checkout@v3 @@ -25,7 +26,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install setuptools - python -m pip install . + python -m pip install . "Django~=${{ matrix.django-version }}" - name: Run Tests run: | python ./example/manage.py test django_walletpass diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index c6c5af9..14d0ec6 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -8,7 +8,9 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11","3.12"] + django-version: ["3.2.9","4.1","5.1"] + steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -18,8 +20,9 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install pylint python -m pip install setuptools pylint - python -m pip install . + python -m pip install . "Django~=${{ matrix.django-version }}" - name: Analysing the code with pylint run: | pylint --rcfile=.pylintrc $(git ls-files '*.py') diff --git a/README.md b/README.md index 4adeb3b..c2ed835 100644 --- a/README.md +++ b/README.md @@ -112,9 +112,16 @@ WALLETPASS_CONF = { # Defaults to DEFAULT_FILE_STORAGE 'STORAGE_CLASS': 'my.custom.storageclass, 'UPLOAD_TO': 'passes' + 'STORAGE_BACKEND': 's3storage' # Dj4.2+ only } ``` +`STORAGE_BACKEND` is the key of the django settings `STORAGES` storage config. e.g + +``` +STORAGES['s3storage']['BACKEND'] = 'some.s3.backend.class' +``` + ### Push notifications sandbox (optional) Default: False diff --git a/django_walletpass/settings.py b/django_walletpass/settings.py index a1fa0c5..1064ee7 100644 --- a/django_walletpass/settings.py +++ b/django_walletpass/settings.py @@ -1,5 +1,7 @@ import os from collections import UserDict + +import django from django.conf import settings as django_settings from django.test.signals import setting_changed @@ -11,6 +13,11 @@ with open(os.path.join(FULL_BASE_DIR, 'certs', 'AppleWWDRCA.cer'), 'rb') as _ffile: wwdrca_content = _ffile.read() +if django.VERSION < (4, 2): + STORAGE_CLASS = django_settings.DEFAULT_FILE_STORAGE +else: + STORAGE_CLASS = django_settings.STORAGES["default"]["BACKEND"] + DEFAULTS = { 'PUSH_AUTH_STRATEGY': 'legacy', # legacy or token 'TOKEN_AUTH_KEY_PATH': None, @@ -29,7 +36,8 @@ 'SERVICE_URL': None, 'WALLETPASS_PUSH_CLASS': 'django_walletpass.services.PushBackend', 'PUSH_SANDBOX': False, - 'STORAGE_CLASS': django_settings.DEFAULT_FILE_STORAGE, + 'STORAGE_BACKEND': None, # DJ4.2+ only + 'STORAGE_CLASS': STORAGE_CLASS, 'STORAGE_HTTP_REDIRECT': False, 'UPLOAD_TO': 'passes', } @@ -49,6 +57,8 @@ def update_conf(self): if 'APPLE_WWDRCA_PEM_PATH' in new: with open(new['APPLE_WWDRCA_PEM_PATH'], 'rb') as ffile: new['WWDRCA_PEM_CONTENT'] = ffile.read() + if 'STORAGE_BACKEND' in new: + new['STORAGE_CLASS'] = new.STORAGES[new.STORAGE_BACKEND]["BACKEND"] self.data.update(new) diff --git a/django_walletpass/tests/main.py b/django_walletpass/tests/main.py index 485065a..945498f 100644 --- a/django_walletpass/tests/main.py +++ b/django_walletpass/tests/main.py @@ -225,6 +225,6 @@ def test_create_log(self): created_log = Log.objects.first() self.assertIsNotNone(created_log) expected_timestamp = datetime.datetime.strptime(expected_timestamp_str, "%Y-%m-%d %I:%M:%S %p %z") - expected_utc_timestamp = expected_timestamp.astimezone(timezone.utc) + expected_utc_timestamp = expected_timestamp.astimezone(datetime.timezone.utc) self.assertEqual(created_log.created_at, expected_utc_timestamp)