Add django-scopes

This commit is contained in:
Tobias Kunze 2025-03-20 10:32:03 +01:00
parent 2dcc5650a9
commit 6e6f2d0993
4 changed files with 22 additions and 2 deletions

View file

@ -9,6 +9,7 @@ dependencies = [
"cryptography>=44.0.2", "cryptography>=44.0.2",
"django==5.2b1", "django==5.2b1",
"django-allauth>=65.5.0", "django-allauth>=65.5.0",
"django-scopes>=2.0.0",
"django-template-partials>=24.4", "django-template-partials>=24.4",
"pillow>=11.1.0", "pillow>=11.1.0",
"psycopg2-binary>=2.9.10", "psycopg2-binary>=2.9.10",

View file

@ -1,5 +1,6 @@
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.urls import resolve from django.urls import resolve
from django_scopes import scope
from servala.core.models import Organization from servala.core.models import Organization
@ -16,7 +17,8 @@ class OrganizationMiddleware:
if organization_slug: if organization_slug:
pk = organization_slug.rsplit("-", maxsplit=1)[-1] pk = organization_slug.rsplit("-", maxsplit=1)[-1]
request.organization = get_object_or_404(Organization, pk=pk) request.organization = get_object_or_404(Organization, pk=pk)
else: with scope(organization=request.organization):
request.organization = None return self.get_response(request)
request.organization = None
return self.get_response(request) return self.get_response(request)

View file

@ -4,6 +4,7 @@ from django.urls import reverse
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django_scopes import ScopedManager
from .mixins import ServalaModelMixin from .mixins import ServalaModelMixin
@ -136,6 +137,8 @@ class OrganizationMembership(ServalaModelMixin, models.Model):
verbose_name=_("Role"), verbose_name=_("Role"),
) )
objects = ScopedManager(organization="organization")
class Meta: class Meta:
verbose_name = _("Organization membership") verbose_name = _("Organization membership")
verbose_name_plural = _("Organization memberships") verbose_name_plural = _("Organization memberships")

14
uv.lock generated
View file

@ -248,6 +248,18 @@ dependencies = [
] ]
sdist = { url = "https://files.pythonhosted.org/packages/66/f8/b58f84c29bcbca3798939279a98e2423e6e53a38c29e3fed7700ff3d6984/django_allauth-65.5.0.tar.gz", hash = "sha256:1a564fd2f5413054559078c2b7146796b517c1e7a38c6312e9de7c9bb708325d", size = 1624216 } sdist = { url = "https://files.pythonhosted.org/packages/66/f8/b58f84c29bcbca3798939279a98e2423e6e53a38c29e3fed7700ff3d6984/django_allauth-65.5.0.tar.gz", hash = "sha256:1a564fd2f5413054559078c2b7146796b517c1e7a38c6312e9de7c9bb708325d", size = 1624216 }
[[package]]
name = "django-scopes"
version = "2.0.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "django" },
]
sdist = { url = "https://files.pythonhosted.org/packages/a5/d7/a26ccb685b64e8e0b21f107b01ea16636a899a380175fe29d7c01d3d8395/django-scopes-2.0.0.tar.gz", hash = "sha256:d190d9a2462bce812bc6fdd254e47ba031f6fba3279c8ac7397c671df0a4e54f", size = 15118 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/15/3d/94d82839c111a36145b5ec1fb407a85f9a460af5974a07f4c6d3cc414358/django_scopes-2.0.0-py3-none-any.whl", hash = "sha256:9cf521b4d543ffa2ff6369fb5a1dda03567e862ba89626c01405f3d93ca04724", size = 16660 },
]
[[package]] [[package]]
name = "django-template-partials" name = "django-template-partials"
version = "24.4" version = "24.4"
@ -658,6 +670,7 @@ dependencies = [
{ name = "cryptography" }, { name = "cryptography" },
{ name = "django" }, { name = "django" },
{ name = "django-allauth" }, { name = "django-allauth" },
{ name = "django-scopes" },
{ name = "django-template-partials" }, { name = "django-template-partials" },
{ name = "pillow" }, { name = "pillow" },
{ name = "psycopg2-binary" }, { name = "psycopg2-binary" },
@ -683,6 +696,7 @@ requires-dist = [
{ name = "cryptography", specifier = ">=44.0.2" }, { name = "cryptography", specifier = ">=44.0.2" },
{ name = "django", specifier = "==5.2b1" }, { name = "django", specifier = "==5.2b1" },
{ name = "django-allauth", specifier = ">=65.5.0" }, { name = "django-allauth", specifier = ">=65.5.0" },
{ name = "django-scopes", specifier = ">=2.0.0" },
{ name = "django-template-partials", specifier = ">=24.4" }, { name = "django-template-partials", specifier = ">=24.4" },
{ name = "pillow", specifier = ">=11.1.0" }, { name = "pillow", specifier = ">=11.1.0" },
{ name = "psycopg2-binary", specifier = ">=2.9.10" }, { name = "psycopg2-binary", specifier = ">=2.9.10" },