mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-03 05:11:31 -05:00
convert TreeMixin and FuzzyFilterMixin to swagger schemas
This commit is contained in:
@@ -164,14 +164,13 @@ class ExtendedRecipeMixin():
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
# @extend_schema_view(
|
@extend_schema_view(list=extend_schema(parameters=[
|
||||||
# list=extend_schema(
|
OpenApiParameter(name='query', description='lookup if query string is contained within the name, case insensitive', type=str),
|
||||||
# parameters=[
|
OpenApiParameter(name='updated_at', description='if model has an updated_at timestamp, filter only models updated at or after datetime', type=str), # TODO format hint
|
||||||
# OpenApiParameter(name='query', description='Match name field against against parameter', type=str)
|
OpenApiParameter(name='limit', description='limit number of entries to return', type=str),
|
||||||
# ]
|
OpenApiParameter(name='random', description='randomly orders entries (only works together with limit)', type=str),
|
||||||
# )
|
]))
|
||||||
# )
|
class FuzzyFilterMixin(viewsets.ModelViewSet, ExtendedRecipeMixin):
|
||||||
class FuzzyFilterMixin(ViewSetMixin, ExtendedRecipeMixin):
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
self.queryset = self.queryset.filter(space=self.request.space).order_by(Lower('name').asc())
|
self.queryset = self.queryset.filter(space=self.request.space).order_by(Lower('name').asc())
|
||||||
@@ -293,7 +292,11 @@ class MergeMixin(ViewSetMixin):
|
|||||||
return Response(content, status=status.HTTP_400_BAD_REQUEST)
|
return Response(content, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
class TreeMixin(MergeMixin, FuzzyFilterMixin, ExtendedRecipeMixin):
|
@extend_schema_view(list=extend_schema(parameters=[
|
||||||
|
OpenApiParameter(name='root', description='Return first level children of {obj} with ID [int]. Integer 0 will return root {obj}s.', type=int),
|
||||||
|
OpenApiParameter(name='tree', description='Return all self and children of {} with ID [int].', type=int),
|
||||||
|
]))
|
||||||
|
class TreeMixin(MergeMixin, FuzzyFilterMixin):
|
||||||
# schema = TreeSchema()
|
# schema = TreeSchema()
|
||||||
model = None
|
model = None
|
||||||
|
|
||||||
@@ -493,7 +496,8 @@ class SupermarketViewSet(StandardFilterModelViewSet):
|
|||||||
return super().get_queryset()
|
return super().get_queryset()
|
||||||
|
|
||||||
|
|
||||||
class SupermarketCategoryViewSet(viewsets.ModelViewSet, FuzzyFilterMixin, MergeMixin):
|
# TODO does supermarket category have settings to support fuzzy filtering and/or merge?
|
||||||
|
class SupermarketCategoryViewSet(FuzzyFilterMixin, MergeMixin):
|
||||||
queryset = SupermarketCategory.objects
|
queryset = SupermarketCategory.objects
|
||||||
model = SupermarketCategory
|
model = SupermarketCategory
|
||||||
serializer_class = SupermarketCategorySerializer
|
serializer_class = SupermarketCategorySerializer
|
||||||
@@ -515,14 +519,7 @@ class SupermarketCategoryRelationViewSet(StandardFilterModelViewSet):
|
|||||||
return super().get_queryset()
|
return super().get_queryset()
|
||||||
|
|
||||||
|
|
||||||
# TODO make TreeMixin a view type and move schema to view type
|
class KeywordViewSet(TreeMixin):
|
||||||
@extend_schema_view(list=extend_schema(parameters=[
|
|
||||||
OpenApiParameter(name='query', description='lookup if query string is contained within the name, case insensitive', type=str),
|
|
||||||
OpenApiParameter(name='updated_at', description='if model has an updated_at timestamp, filter only models updated at or after datetime', type=str), # TODO format hint
|
|
||||||
OpenApiParameter(name='limit', description='limit number of entries to return', type=str),
|
|
||||||
OpenApiParameter(name='random', description='randomly orders entries (only works together with limit)', type=str),
|
|
||||||
]))
|
|
||||||
class KeywordViewSet(viewsets.ModelViewSet, TreeMixin):
|
|
||||||
queryset = Keyword.objects
|
queryset = Keyword.objects
|
||||||
model = Keyword
|
model = Keyword
|
||||||
serializer_class = KeywordSerializer
|
serializer_class = KeywordSerializer
|
||||||
@@ -530,16 +527,13 @@ class KeywordViewSet(viewsets.ModelViewSet, TreeMixin):
|
|||||||
pagination_class = DefaultPagination
|
pagination_class = DefaultPagination
|
||||||
|
|
||||||
|
|
||||||
class UnitViewSet(StandardFilterModelViewSet, MergeMixin):
|
class UnitViewSet(MergeMixin, FuzzyFilterMixin):
|
||||||
queryset = Unit.objects
|
queryset = Unit.objects
|
||||||
model = Unit
|
model = Unit
|
||||||
serializer_class = UnitSerializer
|
serializer_class = UnitSerializer
|
||||||
permission_classes = [CustomIsUser & CustomTokenHasReadWriteScope]
|
permission_classes = [CustomIsUser & CustomTokenHasReadWriteScope]
|
||||||
pagination_class = DefaultPagination
|
pagination_class = DefaultPagination
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return super().get_queryset()
|
|
||||||
|
|
||||||
|
|
||||||
class FoodInheritFieldViewSet(viewsets.ReadOnlyModelViewSet):
|
class FoodInheritFieldViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
queryset = FoodInheritField.objects
|
queryset = FoodInheritField.objects
|
||||||
@@ -552,14 +546,7 @@ class FoodInheritFieldViewSet(viewsets.ReadOnlyModelViewSet):
|
|||||||
return super().get_queryset()
|
return super().get_queryset()
|
||||||
|
|
||||||
|
|
||||||
# TODO make TreeMixin a view type and move schema to view type
|
class FoodViewSet(TreeMixin):
|
||||||
@extend_schema_view(list=extend_schema(parameters=[
|
|
||||||
OpenApiParameter(name='query', description='lookup if query string is contained within the name, case insensitive', type=str),
|
|
||||||
OpenApiParameter(name='updated_at', description='if model has an updated_at timestamp, filter only models updated at or after datetime', type=str), # TODO format hint
|
|
||||||
OpenApiParameter(name='limit', description='limit number of entries to return', type=str),
|
|
||||||
OpenApiParameter(name='random', description='randomly orders entries (only works together with limit)', type=str),
|
|
||||||
]))
|
|
||||||
class FoodViewSet(viewsets.ModelViewSet, TreeMixin):
|
|
||||||
queryset = Food.objects
|
queryset = Food.objects
|
||||||
model = Food
|
model = Food
|
||||||
serializer_class = FoodSerializer
|
serializer_class = FoodSerializer
|
||||||
|
|||||||
Reference in New Issue
Block a user