From 15b0ad9c12c1763d91410bde36cfefd801745714 Mon Sep 17 00:00:00 2001 From: xinwen Date: Mon, 8 Mar 2021 17:19:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B8=85=E7=90=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=20`orgs.mixins.api.OrgMembershipModelViewSetMixin`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/orgs/mixins/api.py | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/apps/orgs/mixins/api.py b/apps/orgs/mixins/api.py index f40f9f7fa..bfcd4b7af 100644 --- a/apps/orgs/mixins/api.py +++ b/apps/orgs/mixins/api.py @@ -1,17 +1,15 @@ # -*- coding: utf-8 -*- # -from django.shortcuts import get_object_or_404 from rest_framework.viewsets import ModelViewSet, GenericViewSet from rest_framework_bulk import BulkModelViewSet from common.mixins import CommonApiMixin, RelationMixin from orgs.utils import current_org from ..utils import set_to_root_org -from ..models import Organization __all__ = [ - 'RootOrgViewMixin', 'OrgMembershipModelViewSetMixin', 'OrgModelViewSet', - 'OrgBulkModelViewSet', 'OrgQuerySetMixin', 'OrgGenericViewSet', 'OrgRelationMixin' + 'RootOrgViewMixin', 'OrgModelViewSet', 'OrgBulkModelViewSet', 'OrgQuerySetMixin', + 'OrgGenericViewSet', 'OrgRelationMixin' ] @@ -62,27 +60,6 @@ class OrgBulkModelViewSet(CommonApiMixin, OrgQuerySetMixin, BulkModelViewSet): return False -class OrgMembershipModelViewSetMixin: - org = None - membership_class = None - lookup_field = 'user' - lookup_url_kwarg = 'user_id' - http_method_names = ['get', 'post', 'delete', 'head', 'options'] - - def dispatch(self, request, *args, **kwargs): - self.org = get_object_or_404(Organization, pk=kwargs.get('org_id')) - return super().dispatch(request, *args, **kwargs) - - def get_serializer_context(self): - context = super().get_serializer_context() - context['org'] = self.org - return context - - def get_queryset(self): - queryset = self.membership_class.objects.filter(organization=self.org) - return queryset - - class OrgRelationMixin(RelationMixin): def get_queryset(self): queryset = super().get_queryset()