Improving projects order_by in user order
parent
42da513ad5
commit
6fa64d191a
|
@ -30,7 +30,6 @@ from taiga.base.api.permissions import AllowAnyPermission
|
||||||
from taiga.base.api.utils import get_object_or_404
|
from taiga.base.api.utils import get_object_or_404
|
||||||
from taiga.base.utils.slug import slugify_uniquely
|
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.history.mixins import HistoryResourceMixin
|
||||||
from taiga.projects.mixins.ordering import BulkUpdateOrderMixin
|
from taiga.projects.mixins.ordering import BulkUpdateOrderMixin
|
||||||
from taiga.projects.mixins.on_destroy import MoveOnDestroyMixin
|
from taiga.projects.mixins.on_destroy import MoveOnDestroyMixin
|
||||||
|
@ -58,8 +57,9 @@ class ProjectViewSet(HistoryResourceMixin, ModelCrudViewSet):
|
||||||
admin_serializer_class = serializers.ProjectDetailAdminSerializer
|
admin_serializer_class = serializers.ProjectDetailAdminSerializer
|
||||||
list_serializer_class = serializers.ProjectSerializer
|
list_serializer_class = serializers.ProjectSerializer
|
||||||
permission_classes = (permissions.ProjectPermission, )
|
permission_classes = (permissions.ProjectPermission, )
|
||||||
filter_backends = (filters.CanViewProjectObjFilterBackend, project_filters.ProjectsFilterBackend)
|
filter_backends = (filters.CanViewProjectObjFilterBackend,)
|
||||||
filter_fields = (('member', 'members'),)
|
filter_fields = (('member', 'members'),)
|
||||||
|
order_by_fields = ("memberships__user_order",)
|
||||||
|
|
||||||
@list_route(methods=["POST"])
|
@list_route(methods=["POST"])
|
||||||
def bulk_update_order(self, request, **kwargs):
|
def bulk_update_order(self, request, **kwargs):
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
|
||||||
# Copyright (C) 2014 Jesús Espino <jespinog@gmail.com>
|
|
||||||
# Copyright (C) 2014 David Barragán <bameda@dbarragan.com>
|
|
||||||
# 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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
|
|
|
@ -78,6 +78,7 @@ class Migration(migrations.Migration):
|
||||||
('projects', '0019_auto_20150311_0821'),
|
('projects', '0019_auto_20150311_0821'),
|
||||||
('contenttypes', '0001_initial'),
|
('contenttypes', '0001_initial'),
|
||||||
('timeline', '0001_initial'),
|
('timeline', '0001_initial'),
|
||||||
|
('users', '0010_auto_20150414_0936'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
|
|
@ -321,3 +321,31 @@ def test_create_and_use_template(client):
|
||||||
}
|
}
|
||||||
response = client.json.post(url, json.dumps(data))
|
response = client.json.post(url, json.dumps(data))
|
||||||
assert response.status_code == 201
|
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)
|
||||||
|
|
Loading…
Reference in New Issue