From 6fa64d191a992180211affb9be161927693d8baf Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 29 Apr 2015 09:52:49 +0200 Subject: [PATCH] Improving projects order_by in user order --- taiga/projects/api.py | 4 +-- taiga/projects/filters.py | 25 ----------------- .../migrations/0002_auto_20150327_1056.py | 1 + tests/integration/test_projects.py | 28 +++++++++++++++++++ 4 files changed, 31 insertions(+), 27 deletions(-) delete mode 100644 taiga/projects/filters.py diff --git a/taiga/projects/api.py b/taiga/projects/api.py index 283ad269..e0761db2 100644 --- a/taiga/projects/api.py +++ b/taiga/projects/api.py @@ -30,7 +30,6 @@ from taiga.base.api.permissions import AllowAnyPermission from taiga.base.api.utils import get_object_or_404 from taiga.base.utils.slug import slugify_uniquely -from taiga.projects import filters as project_filters from taiga.projects.history.mixins import HistoryResourceMixin from taiga.projects.mixins.ordering import BulkUpdateOrderMixin from taiga.projects.mixins.on_destroy import MoveOnDestroyMixin @@ -58,8 +57,9 @@ class ProjectViewSet(HistoryResourceMixin, ModelCrudViewSet): admin_serializer_class = serializers.ProjectDetailAdminSerializer list_serializer_class = serializers.ProjectSerializer permission_classes = (permissions.ProjectPermission, ) - filter_backends = (filters.CanViewProjectObjFilterBackend, project_filters.ProjectsFilterBackend) + filter_backends = (filters.CanViewProjectObjFilterBackend,) filter_fields = (('member', 'members'),) + order_by_fields = ("memberships__user_order",) @list_route(methods=["POST"]) def bulk_update_order(self, request, **kwargs): diff --git a/taiga/projects/filters.py b/taiga/projects/filters.py deleted file mode 100644 index ab8cb8b2..00000000 --- a/taiga/projects/filters.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2014 Andrey Antukh -# Copyright (C) 2014 Jesús Espino -# Copyright (C) 2014 David Barragán -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -from taiga.base import filters - -class ProjectsFilterBackend(filters.FilterBackend): - def filter_queryset(self, request, queryset, view): - queryset = super().filter_queryset(request, queryset, view) - if "user_order" in request.QUERY_PARAMS and "member" in request.QUERY_PARAMS: - queryset = queryset.order_by("memberships__user_order") - - return queryset diff --git a/taiga/timeline/migrations/0002_auto_20150327_1056.py b/taiga/timeline/migrations/0002_auto_20150327_1056.py index a4d3d1d8..c1c67365 100644 --- a/taiga/timeline/migrations/0002_auto_20150327_1056.py +++ b/taiga/timeline/migrations/0002_auto_20150327_1056.py @@ -78,6 +78,7 @@ class Migration(migrations.Migration): ('projects', '0019_auto_20150311_0821'), ('contenttypes', '0001_initial'), ('timeline', '0001_initial'), + ('users', '0010_auto_20150414_0936'), ] operations = [ diff --git a/tests/integration/test_projects.py b/tests/integration/test_projects.py index d533a966..f746adef 100644 --- a/tests/integration/test_projects.py +++ b/tests/integration/test_projects.py @@ -321,3 +321,31 @@ def test_create_and_use_template(client): } response = client.json.post(url, json.dumps(data)) assert response.status_code == 201 + + +def test_projects_user_order(client): + user = f.UserFactory.create(is_superuser=True) + project_1 = f.create_project() + role_1 = f.RoleFactory(project=project_1) + f.MembershipFactory(user=user, project=project_1, is_owner=True, role=role_1, user_order=2) + + project_2 = f.create_project() + role_2 = f.RoleFactory(project=project_2) + f.MembershipFactory(user=user, project=project_2, is_owner=True, role=role_2, user_order=1) + + client.login(user) + #Testing default id order + url = reverse("projects-list") + url = "%s?member=%s" % (url, user.id) + response = client.json.get(url) + response_content = json.loads(response.content.decode("utf-8")) + assert response.status_code == 200 + assert(response_content[0]["id"] == project_1.id) + + #Testing user order + url = reverse("projects-list") + url = "%s?member=%s&order_by=memberships__user_order" % (url, user.id) + response = client.json.get(url) + response_content = json.loads(response.content.decode("utf-8")) + assert response.status_code == 200 + assert(response_content[0]["id"] == project_2.id)