Skip to content

Commit 7f4aaa0

Browse files
feat: add case-insensitive choice field for task status filtering (#228)
- Introduced CaseInsensitiveChoiceField to handle status input in a case-insensitive manner, improving user experience when filtering tasks by status. - Updated GetTaskQueryParamsSerializer to utilize the new field for the status parameter, ensuring consistent validation and processing of status values. Co-authored-by: Amit Prakash <[email protected]>
1 parent 3e51495 commit 7f4aaa0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

todo/serializers/get_tasks_serializer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
from todo.constants.task import SORT_FIELDS, SORT_ORDERS, SORT_FIELD_CREATED_AT, SORT_FIELD_DEFAULT_ORDERS, TaskStatus
55

66

7+
class CaseInsensitiveChoiceField(serializers.ChoiceField):
8+
def to_internal_value(self, data):
9+
if isinstance(data, str):
10+
data = data.upper()
11+
return super().to_internal_value(data)
12+
13+
714
class GetTaskQueryParamsSerializer(serializers.Serializer):
815
page = serializers.IntegerField(
916
required=False,
@@ -37,7 +44,7 @@ class GetTaskQueryParamsSerializer(serializers.Serializer):
3744

3845
teamId = serializers.CharField(required=False, allow_blank=False, allow_null=True)
3946

40-
status = serializers.ChoiceField(
47+
status = CaseInsensitiveChoiceField(
4148
choices=[status.value for status in TaskStatus],
4249
required=False,
4350
allow_null=True,

0 commit comments

Comments
 (0)