Add django-scopes
This commit is contained in:
parent
2dcc5650a9
commit
6e6f2d0993
4 changed files with 22 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import resolve
|
||||
from django_scopes import scope
|
||||
|
||||
from servala.core.models import Organization
|
||||
|
||||
|
@ -16,7 +17,8 @@ class OrganizationMiddleware:
|
|||
if organization_slug:
|
||||
pk = organization_slug.rsplit("-", maxsplit=1)[-1]
|
||||
request.organization = get_object_or_404(Organization, pk=pk)
|
||||
else:
|
||||
request.organization = None
|
||||
with scope(organization=request.organization):
|
||||
return self.get_response(request)
|
||||
|
||||
request.organization = None
|
||||
return self.get_response(request)
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.urls import reverse
|
|||
from django.utils.functional import cached_property
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_scopes import ScopedManager
|
||||
|
||||
from .mixins import ServalaModelMixin
|
||||
|
||||
|
@ -136,6 +137,8 @@ class OrganizationMembership(ServalaModelMixin, models.Model):
|
|||
verbose_name=_("Role"),
|
||||
)
|
||||
|
||||
objects = ScopedManager(organization="organization")
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Organization membership")
|
||||
verbose_name_plural = _("Organization memberships")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue