mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
feat: state grouping and ordering list (#253)
* feat: state grouping and ordering list * fix: state grouping in state list endpoint
This commit is contained in:
parent
af1d49bbf5
commit
92d5749997
@ -1,6 +1,11 @@
|
|||||||
|
# Python imports
|
||||||
|
from itertools import groupby
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from rest_framework import status
|
||||||
|
from sentry_sdk import capture_exception
|
||||||
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from . import BaseViewSet
|
from . import BaseViewSet
|
||||||
@ -31,6 +36,25 @@ class StateViewSet(BaseViewSet):
|
|||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def list(self, request, slug, project_id):
|
||||||
|
try:
|
||||||
|
state_dict = dict()
|
||||||
|
states = StateSerializer(self.get_queryset(), many=True).data
|
||||||
|
|
||||||
|
for key, value in groupby(
|
||||||
|
sorted(states, key=lambda state: state["group"]),
|
||||||
|
lambda state: state.get("group"),
|
||||||
|
):
|
||||||
|
state_dict[str(key)] = list(value)
|
||||||
|
|
||||||
|
return Response(state_dict, status=status.HTTP_200_OK)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": "Something went wrong please try again later"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
def destroy(self, request, slug, project_id, pk):
|
def destroy(self, request, slug, project_id, pk):
|
||||||
try:
|
try:
|
||||||
state = State.objects.get(
|
state = State.objects.get(
|
||||||
|
Loading…
Reference in New Issue
Block a user