cardo-python-utils 0.5.5__tar.gz → 0.5.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cardo_python_utils-0.5.5/cardo_python_utils.egg-info → cardo_python_utils-0.5.7}/PKG-INFO +1 -1
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7/cardo_python_utils.egg-info}/PKG-INFO +1 -1
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/pyproject.toml +1 -1
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/admin/user_group.py +1 -1
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/celery/tenant_aware_task.py +14 -6
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/oidc_settings.py +1 -1
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/storage/tenant_aware_storage.py +19 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/LICENSE +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/MANIFEST.in +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/README.rst +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/cardo_python_utils.egg-info/SOURCES.txt +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/cardo_python_utils.egg-info/dependency_links.txt +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/cardo_python_utils.egg-info/requires.txt +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/cardo_python_utils.egg-info/top_level.txt +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/choices.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/data_structures.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/db.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/README.md +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/admin/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/admin/auth.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/admin/templates/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/admin/templates/user_groups_changelist.html +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/admin/views.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/api/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/api/drf.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/api/ninja.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/api/utils.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/apps.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/auth/service.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/celery/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/celery/tenant_aware_database_scheduler.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/db/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/db/alias.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/db/routers.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/db/transaction.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/db/utils.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/management/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/management/commands/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/management/commands/migrateall.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/management/commands/shell.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/management/commands/showmigrations.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/management/commands/tenant_aware_command.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/middleware/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/middleware/tenant_aware_http_middleware.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/middleware/tenant_aware_websocket_middleware.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0001_initial.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0001_initial_squashed_0005_alter_userrole_id.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0002_auto_20220120_1617.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0003_auto_20220513_1025.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0004_auto_20220817_1526.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0005_alter_userrole_id.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0006_userrole_organization_and_more.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0007_user_demo.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0008_delete_userrole.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/models/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/models/user.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/models/user_group.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/redis/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/redis/key_function.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/settings.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/storage/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/tenant_context.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/tests/__init__.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/tests/conftest.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django_utils.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/esma_choices.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/exceptions.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/imports.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/math.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/text.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/time.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/types_hinting.py +0 -0
- {cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/setup.cfg +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cardo-python-utils"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.7"
|
|
8
8
|
description = "Python library enhanced with a wide range of functions for different scenarios."
|
|
9
9
|
readme = "README.rst"
|
|
10
10
|
requires-python = ">=3.8"
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/admin/user_group.py
RENAMED
|
@@ -71,7 +71,7 @@ class UserGroupAdminBase(admin.ModelAdmin, metaclass=UserGroupAdminMetaclass):
|
|
|
71
71
|
queryset = super().get_queryset(request)
|
|
72
72
|
|
|
73
73
|
queryset = queryset.annotate(**{
|
|
74
|
-
f"allowed_{entity}_count": Count(f"allowed_{entity}") for entity in self.app_entities
|
|
74
|
+
f"allowed_{entity}_count": Count(f"allowed_{entity}", distinct=True) for entity in self.app_entities
|
|
75
75
|
})
|
|
76
76
|
|
|
77
77
|
return queryset
|
|
@@ -15,6 +15,8 @@ except ImportError:
|
|
|
15
15
|
TaskClass = Task
|
|
16
16
|
USE_QUEUE_ONCE = False
|
|
17
17
|
|
|
18
|
+
CELERY_BACKEND_CLEANUP_TASK = "celery.backend_cleanup"
|
|
19
|
+
|
|
18
20
|
|
|
19
21
|
class TenantAwareTask(TaskClass):
|
|
20
22
|
#: Enable argument checking.
|
|
@@ -46,7 +48,7 @@ class TenantAwareTask(TaskClass):
|
|
|
46
48
|
if kwargs is None:
|
|
47
49
|
kwargs = {}
|
|
48
50
|
|
|
49
|
-
if TENANT_KEY not in kwargs:
|
|
51
|
+
if TENANT_KEY not in kwargs and self.name != CELERY_BACKEND_CLEANUP_TASK:
|
|
50
52
|
kwargs[TENANT_KEY] = TenantContext.get()
|
|
51
53
|
|
|
52
54
|
return super().apply(
|
|
@@ -61,19 +63,19 @@ class TenantAwareTask(TaskClass):
|
|
|
61
63
|
if kwargs is None:
|
|
62
64
|
kwargs = {}
|
|
63
65
|
|
|
64
|
-
if TENANT_KEY not in kwargs:
|
|
66
|
+
if TENANT_KEY not in kwargs and self.name != CELERY_BACKEND_CLEANUP_TASK:
|
|
65
67
|
kwargs[TENANT_KEY] = TenantContext.get()
|
|
66
68
|
|
|
67
69
|
return super().apply_async(args, kwargs, task_id, producer, link, link_error, shadow, **options)
|
|
68
70
|
|
|
69
71
|
def s(self, *args, **kwargs):
|
|
70
|
-
if TENANT_KEY not in kwargs:
|
|
72
|
+
if TENANT_KEY not in kwargs and self.name != CELERY_BACKEND_CLEANUP_TASK:
|
|
71
73
|
kwargs[TENANT_KEY] = TenantContext.get()
|
|
72
74
|
|
|
73
75
|
return self.signature(args, kwargs)
|
|
74
76
|
|
|
75
77
|
def si(self, *args, **kwargs):
|
|
76
|
-
if TENANT_KEY not in kwargs:
|
|
78
|
+
if TENANT_KEY not in kwargs and self.name != CELERY_BACKEND_CLEANUP_TASK:
|
|
77
79
|
kwargs[TENANT_KEY] = TenantContext.get()
|
|
78
80
|
|
|
79
81
|
return self.signature(args, kwargs, immutable=True)
|
|
@@ -87,8 +89,14 @@ class TenantAwareTask(TaskClass):
|
|
|
87
89
|
key = self.get_key(args, kwargs)
|
|
88
90
|
self.once_backend.clear_lock(key)
|
|
89
91
|
|
|
90
|
-
if self.name !=
|
|
91
|
-
|
|
92
|
+
if self.name != CELERY_BACKEND_CLEANUP_TASK:
|
|
93
|
+
try:
|
|
94
|
+
tenant = kwargs.pop(TENANT_KEY)
|
|
95
|
+
except KeyError:
|
|
96
|
+
raise RuntimeError(
|
|
97
|
+
f"TenantAwareTask {self.name} called without tenant in kwargs. "
|
|
98
|
+
f"Make sure to call the task with the tenant in the kwargs or use the apply/apply_async/s/si methods."
|
|
99
|
+
)
|
|
92
100
|
TenantContext.set(tenant)
|
|
93
101
|
|
|
94
102
|
return self.run(*args, **kwargs)
|
|
@@ -12,7 +12,7 @@ from django.conf import settings
|
|
|
12
12
|
from .tenant_context import TenantContext
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
KEYCLOAK_SERVER_URL_TEMPLATE = os.getenv("KEYCLOAK_SERVER_URL_TEMPLATE", "https://
|
|
15
|
+
KEYCLOAK_SERVER_URL_TEMPLATE = os.getenv("KEYCLOAK_SERVER_URL_TEMPLATE", "https://id.{realm}.company.com")
|
|
16
16
|
KEYCLOAK_CONFIDENTIAL_CLIENT_ID = os.getenv("KEYCLOAK_CONFIDENTIAL_CLIENT_ID", None)
|
|
17
17
|
|
|
18
18
|
OIDC_CLIENT_AUTH_METHOD = getattr(settings, "OIDC_CLIENT_AUTH_METHOD", "client_assertion")
|
|
@@ -60,6 +60,14 @@ class TenantAwareS3Storage(S3Boto3Storage):
|
|
|
60
60
|
def __init__(self, *args, **kwargs):
|
|
61
61
|
# Don't set bucket_name here; it will be resolved dynamically
|
|
62
62
|
super().__init__(*args, **kwargs)
|
|
63
|
+
self._buckets = {}
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def bucket(self):
|
|
67
|
+
bucket_name = self.bucket_name # resolves current tenant
|
|
68
|
+
if bucket_name not in self._buckets:
|
|
69
|
+
self._buckets[bucket_name] = self.connection.Bucket(bucket_name)
|
|
70
|
+
return self._buckets[bucket_name]
|
|
63
71
|
|
|
64
72
|
@property
|
|
65
73
|
def bucket_name(self):
|
|
@@ -75,6 +83,17 @@ class TenantAwareS3Storage(S3Boto3Storage):
|
|
|
75
83
|
# Allow setting bucket_name but it will be overridden by the property getter
|
|
76
84
|
self._bucket_name_override = value
|
|
77
85
|
|
|
86
|
+
def __getstate__(self):
|
|
87
|
+
"""Override __getstate__ to exclude the _buckets cache from being pickled."""
|
|
88
|
+
state = super().__getstate__()
|
|
89
|
+
state.pop("_buckets", None)
|
|
90
|
+
return state
|
|
91
|
+
|
|
92
|
+
def __setstate__(self, state):
|
|
93
|
+
"""Override __setstate__ to reinitialize the _buckets cache after unpickling."""
|
|
94
|
+
super().__setstate__(state)
|
|
95
|
+
self._buckets = {}
|
|
96
|
+
|
|
78
97
|
|
|
79
98
|
class TenantAwarePrivateS3Storage(TenantAwareS3Storage):
|
|
80
99
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/cardo_python_utils.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/cardo_python_utils.egg-info/requires.txt
RENAMED
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/cardo_python_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/celery/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/management/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/middleware/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/0001_initial.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/migrations/__init__.py
RENAMED
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/models/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/models/user_group.py
RENAMED
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/redis/key_function.py
RENAMED
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.5 → cardo_python_utils-0.5.7}/python_utils/django/storage/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|