From c8540694c59f4085293609a61c952f9022610a05 Mon Sep 17 00:00:00 2001 From: dangannn Date: Sun, 16 Mar 2025 20:40:27 +0300 Subject: [PATCH 1/4] feat: user list max skills query arg --- Dockerfile | 2 ++ docker-compose.yml | 1 + users/views.py | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Dockerfile b/Dockerfile index 516d3605..08817c57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,8 @@ ENV PYTHONFAULTHANDLER=1 \ POETRY_VERSION=1.2.2 RUN pip install "poetry==$POETRY_VERSION" +RUN apt install -y cmake +RUN rm -rf /var/lib/apt/lists/* RUN mkdir /procollab diff --git a/docker-compose.yml b/docker-compose.yml index 0bbeda3c..998a7b73 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: command: bash ./scripts/startup.sh volumes: - ./log:/procollab/log + - ./:/procollab/. env_file: - .env environment: diff --git a/users/views.py b/users/views.py index 3d8f22f8..7837a6f5 100644 --- a/users/views.py +++ b/users/views.py @@ -94,6 +94,31 @@ class UserList(ListCreateAPIView): filter_backends = (filters.DjangoFilterBackend,) filterset_class = UserFilter + def list(self, request, *args, **kwargs): + max_skills = request.query_params.get("max_skills", None) + if max_skills is not None: + try: + max_skills = int(max_skills) + if max_skills < 0: + return Response( + {"error": "max_skills must be a positive integer"}, + status=status.HTTP_400_BAD_REQUEST, + ) + except ValueError: + return Response( + {"error": "max_skills must be an integer"}, + status=status.HTTP_400_BAD_REQUEST, + ) + + response = super().list(request, *args, **kwargs) + + if max_skills is not None: + for user_data in response.data.get("results", []): + if "skills" in user_data: + user_data["skills"] = user_data["skills"][:max_skills] + + return response + def post(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) From bbc5684166bc2363a0d4e6046e7c98aa18509e15 Mon Sep 17 00:00:00 2001 From: dangannn Date: Sun, 16 Mar 2025 20:50:50 +0300 Subject: [PATCH 2/4] feat: user list max skills query arg for current users --- users/views.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/users/views.py b/users/views.py index 7837a6f5..888a4f92 100644 --- a/users/views.py +++ b/users/views.py @@ -284,8 +284,27 @@ class CurrentUser(GenericAPIView): def get(self, request): user = request.user + + max_skills = request.query_params.get("max_skills", None) + if max_skills is not None: + try: + max_skills = int(max_skills) + if max_skills < 0: + return Response( + {"error": "max_skills must be a positive integer"}, + status=status.HTTP_400_BAD_REQUEST, + ) + except ValueError: + return Response( + {"error": "max_skills must be an integer"}, + status=status.HTTP_400_BAD_REQUEST, + ) + serializer = self.get_serializer(user) + if max_skills is not None and "skills" in serializer.data: + serializer.data["skills"] = serializer.data["skills"][:max_skills] + if settings.DEBUG: skills_url_name = ( "https://skills.dev.procollab.ru/progress/subscription-data/" From 795d8c7b810349b689584a859823cb5859246bd5 Mon Sep 17 00:00:00 2001 From: Daniil Nikoronov <110919308+dangannn@users.noreply.github.com> Date: Sun, 16 Mar 2025 21:04:48 +0300 Subject: [PATCH 3/4] Update django-test.yml --- .github/workflows/django-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/django-test.yml b/.github/workflows/django-test.yml index 4514720d..5359fddb 100644 --- a/.github/workflows/django-test.yml +++ b/.github/workflows/django-test.yml @@ -19,7 +19,7 @@ jobs: python-version: 3.11 - name: cache poetry install - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.local key: poetry-1.2.2-0 @@ -46,4 +46,4 @@ jobs: - name: Run tests run: poetry run python manage.py test env: - DEBUG: True \ No newline at end of file + DEBUG: True From 841bdfe5230bf34d4084699bb22e111e14fc1dc6 Mon Sep 17 00:00:00 2001 From: Daniil Nikoronov <110919308+dangannn@users.noreply.github.com> Date: Sun, 16 Mar 2025 21:05:36 +0300 Subject: [PATCH 4/4] Update django-test.yml --- .github/workflows/django-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django-test.yml b/.github/workflows/django-test.yml index 5359fddb..d72dd1bd 100644 --- a/.github/workflows/django-test.yml +++ b/.github/workflows/django-test.yml @@ -32,7 +32,7 @@ jobs: - name: cache deps id: cache-deps - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: .venv key: pydeps-${{ hashFiles('**/poetry.lock') }}