Skip to content

Commit

Permalink
Merge 46beb28 into cd1a98a
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Jul 24, 2019
2 parents cd1a98a + 46beb28 commit 763190e
Show file tree
Hide file tree
Showing 18 changed files with 2,990 additions and 112 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ coreapi = "==2.3.3"
whitenoise = "==4.1.2"
pytz = "==2018.7"
drf-yasg = "*"
pyparsing = "==2.4.0"

[dev-packages]
"flake8" = "*"
Expand Down
17 changes: 13 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

158 changes: 155 additions & 3 deletions bothub/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ def get_object(self):

# ViewSets

@method_decorator(
name='create',
decorator=swagger_auto_schema(
deprecated=True
),
)
class NewRepositoryViewSet(
mixins.CreateModelMixin,
GenericViewSet):
Expand Down Expand Up @@ -415,7 +421,8 @@ def create(self, request, *args, **kwargs):
description='Nickname User to find repositories',
type=openapi.TYPE_STRING
),
]
],
deprecated=True
)
)
class SearchRepositoriesViewSet(
Expand Down Expand Up @@ -443,6 +450,30 @@ def get_queryset(self, *args, **kwargs):
return self.queryset.none()


@method_decorator(
name='retrieve',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='partial_update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='destroy',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryViewSet(
MultipleFieldLookupMixin,
mixins.RetrieveModelMixin,
Expand Down Expand Up @@ -473,6 +504,12 @@ class RepositoryViewSet(
RepositoryPermission,
]

@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@action(
detail=True,
methods=['GET'],
Expand Down Expand Up @@ -533,6 +570,12 @@ def train(self, request, **kwargs):
code=request.status_code)
return Response(request.json()) # pragma: no cover

@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@action(
detail=True,
methods=['POST'],
Expand Down Expand Up @@ -635,6 +678,12 @@ def get_permissions(self):
return super().get_permissions()


@method_decorator(
name='create',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class NewRepositoryExampleViewSet(
mixins.CreateModelMixin,
GenericViewSet):
Expand All @@ -652,6 +701,24 @@ class NewRepositoryExampleViewSet(
deprecated=True,
)
)
@method_decorator(
name='update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='partial_update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='destroy',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryExampleViewSet(
mixins.RetrieveModelMixin,
mixins.DestroyModelMixin,
Expand Down Expand Up @@ -682,6 +749,12 @@ def perform_destroy(self, obj):
obj.delete()


@method_decorator(
name='create',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class NewRepositoryTranslatedExampleViewSet(
mixins.CreateModelMixin,
GenericViewSet):
Expand All @@ -693,6 +766,30 @@ class NewRepositoryTranslatedExampleViewSet(
permission_classes = [permissions.IsAuthenticated]


@method_decorator(
name='retrieve',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='partial_update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='destroy',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryTranslatedExampleViewSet(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
Expand Down Expand Up @@ -952,6 +1049,12 @@ class UserProfileViewSet(
lookup_field = 'nickname'


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True
),
)
class Categories(
mixins.ListModelMixin,
GenericViewSet):
Expand Down Expand Up @@ -989,6 +1092,12 @@ class RepositoriesViewSet(
]


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class TranslationsViewSet(
mixins.ListModelMixin,
GenericViewSet):
Expand All @@ -1000,6 +1109,12 @@ class TranslationsViewSet(
filter_class = TranslationsFilter


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryAuthorizationViewSet(
mixins.ListModelMixin,
GenericViewSet):
Expand Down Expand Up @@ -1030,7 +1145,7 @@ class RepositoryAuthorizationViewSet(
type=openapi.TYPE_STRING,
required=True
),
]
], deprecated=True
)
)
@method_decorator(
Expand All @@ -1051,7 +1166,8 @@ class RepositoryAuthorizationViewSet(
type=openapi.TYPE_STRING,
required=True
),
]
],
deprecated=True
)
)
class RepositoryAuthorizationRoleViewSet(
Expand Down Expand Up @@ -1121,6 +1237,12 @@ def list(self, request, *args, **kwargs):
return Response(serializer.data)


@method_decorator(
name='create',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RequestAuthorizationViewSet(
mixins.CreateModelMixin,
GenericViewSet):
Expand All @@ -1134,6 +1256,12 @@ class RequestAuthorizationViewSet(
]


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryAuthorizationRequestsViewSet(
mixins.ListModelMixin,
GenericViewSet):
Expand All @@ -1149,6 +1277,24 @@ class RepositoryAuthorizationRequestsViewSet(
]


@method_decorator(
name='update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='partial_update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='destroy',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class ReviewAuthorizationRequestViewSet(
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
Expand Down Expand Up @@ -1189,6 +1335,12 @@ class RepositoryEntitiesViewSet(
]


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryUpdatesViewSet(
mixins.ListModelMixin,
GenericViewSet):
Expand Down
8 changes: 4 additions & 4 deletions bothub/api/v2/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Metadata(BaseMetadata):
EntityText: 'entity text',
})

def determine_metadata(self, request, view):
def determine_metadata(self, request, view): # pragma: no cover
metadata = OrderedDict()
metadata['name'] = view.get_view_name()
metadata['description'] = view.get_view_description()
Expand All @@ -60,23 +60,23 @@ def determine_metadata(self, request, view):
metadata['actions'] = actions
return metadata

def determine_actions(self, request, view):
def determine_actions(self, request, view): # pragma: no cover
actions = {}
for method in {'PUT', 'POST'} & set(view.allowed_methods):
serializer = view.get_serializer()
actions[method] = self.get_serializer_info(serializer)
view.request = request
return actions

def get_serializer_info(self, serializer):
def get_serializer_info(self, serializer): # pragma: no cover
if hasattr(serializer, 'child'):
serializer = serializer.child
return OrderedDict([
(field_name, self.get_field_info(field))
for field_name, field in serializer.fields.items()
])

def get_field_info(self, field):
def get_field_info(self, field): # pragma: no cover
field_info = OrderedDict()
field_info['type'] = self.label_lookup[field] or 'field'
field_info['required'] = getattr(field, 'required', False)
Expand Down
20 changes: 20 additions & 0 deletions bothub/api/v2/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.shortcuts import get_object_or_404


class MultipleFieldLookupMixin(object):
"""
Apply this mixin to any view or viewset to get multiple field filtering
based on a `lookup_fields` attribute, instead of the default single field
filtering.
"""

def get_object(self): # pragma: no cover
queryset = self.get_queryset()
queryset = self.filter_queryset(queryset)
filter = {}
for field in self.lookup_fields:
if self.kwargs.get(field):
filter[field] = self.kwargs[field]
obj = get_object_or_404(queryset, **filter)
self.check_object_permissions(self.request, obj)
return obj

0 comments on commit 763190e

Please sign in to comment.