From a7268443caf1da5ed7cf627904baa6dbfac99991 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 13 Jul 2020 17:08:36 +0300 Subject: [PATCH] Add support for a modifying the chunk storage location --- django_etebase/app_settings.py | 7 +++++++ django_etebase/models.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/django_etebase/app_settings.py b/django_etebase/app_settings.py index 3c659c8..33dc65f 100644 --- a/django_etebase/app_settings.py +++ b/django_etebase/app_settings.py @@ -61,6 +61,13 @@ class AppSettings: return self.import_from_str(func) return None + @cached_property + def CHUNK_PATH_FUNC(self): # pylint: disable=invalid-name + func = self._setting("CHUNK_PATH_FUNC", None) + if func is not None: + return self.import_from_str(func) + return None + @cached_property def CHALLENGE_VALID_SECONDS(self): # pylint: disable=invalid-name return self._setting("CHALLENGE_VALID_SECONDS", 60) diff --git a/django_etebase/models.py b/django_etebase/models.py index 397600e..f3704a3 100644 --- a/django_etebase/models.py +++ b/django_etebase/models.py @@ -21,6 +21,8 @@ from django.db.models import Q from django.utils.functional import cached_property from django.utils.crypto import get_random_string +from . import app_settings + UidValidator = RegexValidator(regex=r'^[a-zA-Z0-9\-_]{20,}$', message='Not a valid UID') @@ -79,6 +81,10 @@ class CollectionItem(models.Model): def chunk_directory_path(instance, filename): + custom_func = app_settings.CHUNK_PATH_FUNC + if custom_func is not None: + return custom_func(instance, filename) + item = instance.item col = item.collection user_id = col.owner.id