Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions core/orgs/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db.models import Count
from django.http import Http404
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from pydash import get
from rest_framework import mixins, status, generics
Expand Down Expand Up @@ -30,10 +31,8 @@

TRUTHY = get_truthy_values()


class OrganizationListView(BaseAPIView,
ListWithHeadersMixin,
mixins.CreateModelMixin):
class OrganizationListView(BaseAPIView, ListWithHeadersMixin, mixins.CreateModelMixin):

model = Organization
queryset = Organization.objects.filter(is_active=True)
es_fields = Organization.es_fields
Expand Down Expand Up @@ -76,7 +75,16 @@ def get_serializer_class(self):

return OrganizationListSerializer

@swagger_auto_schema(manual_parameters=[org_no_members_param])
@swagger_auto_schema(
manual_parameters=[
openapi.Parameter(NO_MEMBERS, openapi.IN_QUERY, description="Filter organizations with no members", type=openapi.TYPE_BOOLEAN),
openapi.Parameter('UPDATED_SINCE_PARAM', openapi.IN_QUERY, description="Filter by update date", type=openapi.TYPE_STRING, format=openapi.FORMAT_DATETIME),
openapi.Parameter(UPDATED_BY_USERNAME_PARAM, openapi.IN_QUERY, description="Filter Orgs by the update by user", type=openapi.TYPE_STRING),
openapi.Parameter('verbose', openapi.IN_QUERY, description="Include verbose details", type=openapi.TYPE_BOOLEAN, default=False),
],
Comment thread
snyaggarwal marked this conversation as resolved.

responses={status.HTTP_200_OK: OrganizationListSerializer(many=True)}
)
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)

Expand Down Expand Up @@ -106,7 +114,6 @@ class OrganizationBaseView(BaseAPIView, RetrieveAPIView, DestroyAPIView):
model = Organization
queryset = Organization.objects.filter(is_active=True)


class OrganizationLogoView(OrganizationBaseView, BaseLogoView):
serializer_class = OrganizationDetailSerializer

Expand All @@ -115,7 +122,7 @@ def get_permissions(self):
return [HasPrivateAccess(), ]

return [CanViewConceptDictionary(), ]


class OrganizationOverviewView(OrganizationBaseView, RetrieveAPIView, UpdateAPIView):
serializer_class = OrganizationOverviewSerializer
Expand All @@ -128,7 +135,7 @@ def get_permissions(self):

def get_queryset(self):
return super().get_queryset().filter(mnemonic=self.kwargs['org'])


class OrganizationDetailView(OrganizationBaseView, mixins.UpdateModelMixin, mixins.CreateModelMixin, TaskMixin):
def get_permissions(self):
Expand Down Expand Up @@ -170,15 +177,15 @@ def destroy(self, request, *args, **kwargs):
return result

return Response(status=status.HTTP_204_NO_CONTENT)


class OrganizationClientConfigsView(ResourceClientConfigsView):
lookup_field = 'org'
model = Organization
queryset = Organization.objects.filter(is_active=True)
permission_classes = (CanViewConceptDictionary, )


class OrganizationMemberView(generics.GenericAPIView):
userprofile = None
user_in_org = False
Expand Down Expand Up @@ -235,8 +242,12 @@ def delete(self, request, **kwargs): # pylint: disable=unused-argument
self.userprofile.save()

return Response(status=status.HTTP_204_NO_CONTENT)





def get(self, request, *args, **kwargs):
Comment thread
WestOnyinsi marked this conversation as resolved.
Outdated
return super().get(request, *args, **kwargs)

class OrganizationResourceAbstractListView:
def get_queryset(self):
username = self.kwargs.get('user', None)
Expand All @@ -249,34 +260,30 @@ def get_queryset(self):

return self.queryset.filter(organization__in=user.organizations.all(), version=HEAD)


class OrganizationSourceListView(OrganizationResourceAbstractListView, SourceListView):
pass



class OrganizationCollectionListView(OrganizationResourceAbstractListView, CollectionListView):
pass



class OrganizationExtrasBaseView(APIView):
def get_object(self):
instance = Organization.objects.filter(is_active=True, mnemonic=self.kwargs['org']).first()

if not instance:
raise Http404()
return instance



class OrganizationExtrasView(OrganizationExtrasBaseView):
serializer_class = OrganizationDetailSerializer

def get(self, request, org): # pylint: disable=unused-argument
return Response(get(self.get_object(), 'extras', {}))


class OrganizationExtraRetrieveUpdateDestroyView(OrganizationExtrasBaseView, RetrieveUpdateDestroyAPIView):
serializer_class = OrganizationDetailSerializer


def retrieve(self, request, *args, **kwargs):
key = kwargs.get('extra')
instance = self.get_object()
Expand All @@ -286,6 +293,8 @@ def retrieve(self, request, *args, **kwargs):

return Response({'detail': NOT_FOUND}, status=status.HTTP_404_NOT_FOUND)


)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like a typo, not needed

def update(self, request, **kwargs): # pylint: disable=arguments-differ
key = kwargs.get('extra')
value = request.data.get(key)
Expand All @@ -299,6 +308,7 @@ def update(self, request, **kwargs): # pylint: disable=arguments-differ
instance.set_checksums()
return Response({key: value})


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

def delete(self, request, *args, **kwargs):
key = kwargs.get('extra')
instance = self.get_object()
Expand Down