From 9377ebcc3c9c9f5959484baa5e0db1fee4109b90 Mon Sep 17 00:00:00 2001 From: Denis Shtanskiy Date: Sat, 13 Apr 2024 12:38:41 +0300 Subject: [PATCH] fix filter, delete comments --- src/backend/api/v1/profile/filters.py | 2 +- src/backend/api/v1/projects/filters.py | 8 +++---- src/backend/api/v1/projects/views.py | 33 +------------------------- 3 files changed, 6 insertions(+), 37 deletions(-) diff --git a/src/backend/api/v1/profile/filters.py b/src/backend/api/v1/profile/filters.py index 045d35f..86731dc 100644 --- a/src/backend/api/v1/profile/filters.py +++ b/src/backend/api/v1/profile/filters.py @@ -4,7 +4,7 @@ from apps.profile.models import Profile -class SpecialistsFilter(FilterSet): +class ProfileFilter(FilterSet): """Класс фильтрации специалистов, по запросу на главной странице.""" ready_to_participate = filters.BooleanFilter() diff --git a/src/backend/api/v1/projects/filters.py b/src/backend/api/v1/projects/filters.py index 807694e..8a4b7ec 100644 --- a/src/backend/api/v1/projects/filters.py +++ b/src/backend/api/v1/projects/filters.py @@ -14,8 +14,8 @@ class ProjectFilter(FilterSet): ended = filters.DateFromToRangeFilter() recruitment_status = filters.MultipleChoiceFilter( choices=( - ("open", "Набор открыт"), - ("closed", "Набор закрыт"), + ("1", "Набор открыт"), + ("2", "Набор закрыт"), ), method="filter_recruitment_status", ) @@ -42,12 +42,12 @@ class Meta: ) def filter_recruitment_status(self, queryset, name, value): - if value == "open": + if value == "1": queryset = queryset.filter( Q(project_specialists__is_requred=True) | ~Q(project_specialists__is_required=False) ) - elif value == "closed": + elif value == "2": queryset = queryset.filter( ~Q(project_specialists__is_reqiered=True), Q(project_specialists__is_required=False), diff --git a/src/backend/api/v1/projects/views.py b/src/backend/api/v1/projects/views.py index c610ac5..784d97d 100644 --- a/src/backend/api/v1/projects/views.py +++ b/src/backend/api/v1/projects/views.py @@ -1,10 +1,8 @@ from django.contrib.auth.models import AnonymousUser from django.db.models import Prefetch, Q from django_filters.rest_framework import DjangoFilterBackend -from rest_framework import mixins # decorators, mixins, status +from rest_framework import mixins from rest_framework.permissions import SAFE_METHODS, AllowAny, IsAuthenticated - -# from rest_framework.response import Response from rest_framework.viewsets import ( GenericViewSet, ModelViewSet, @@ -138,35 +136,6 @@ class ProjectPreviewMainViewSet(mixins.ListModelMixin, GenericViewSet): serializer_class = ProjectPreviewMainSerializer pagination_class = ProjectPreviewMainPagination - # @decorators.action( - # detail=False, - # methods=[ - # "GET", - # "UPDATE", - # "DELETE", - # ], - # url_path=r"my_projects", - # permission_classes=[ - # IsCreatorOrOwnerOrReadOnly, - # ], - # ) - # def my_projects(self, request, **kwargs): - # """Превью поектов в личном кабинете для участника или владельцы.""" - # projects = self.get_object() - # if self.action == "GET": - # return projects - # elif self.action == "UPDATE": - # instance = self.get_object() - # serializer = self.get_serializer( - # instance, data=request.data, partial=True - # ) - # serializer.is_valid(raise_exception=True) - # serializer.save() - # return Response(serializer.data, status=status.HTTP_200_OK) - # else: - # projects.filter(id=self.kwargs.get("pk")).delete() - # return Response(status=status.HTTP_204_NO_CONTENT) - class DraftViewSet(BaseProjectViewSet, ModelViewSet): """Представление для черновиков проекта."""