Fakultas Ilmu Komputer UI

Commit 1085a3de authored by Muzaki Azami's avatar Muzaki Azami
Browse files

Merge branch 'sorting-client-and-adding-search' into 'staging'

Sorting client and adding search

See merge request !69
parents 45b294be 9d83e075
Pipeline #79225 passed with stages
in 15 minutes and 18 seconds
......@@ -158,6 +158,26 @@ class GetProfilesAndCSVTest(APITestCase):
expected_response = []
users = CustomUser.objects.all()
users = users.order_by('name')
for user in users:
expected_response.append({
'user': CustomUserDetailsSerializer(user).data,
'diet_profile_id': user.diet_profile.id \
if user.diet_profile is not None else None,
'diet_questionnaire_id': user.diet_questionnaire.id \
if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else None
})
self.assertEqual(response.data, expected_response)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_specific_user(self):
response = self.client.get("/profiles/?name=tesb")
expected_response = []
users = CustomUser.objects.filter(name="tesb")
users = users.order_by('name')
for user in users:
expected_response.append({
'user': CustomUserDetailsSerializer(user).data,
......@@ -215,6 +235,7 @@ class GetProfilesAndCSVTest(APITestCase):
self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + json_response['access_token'])
response = self.client.get(self.BASE_URL,secure=True)
users = CustomUser.objects.all()
users = users.order_by('name')
expected_response = []
for user in users:
expected_response.append({
......
......@@ -19,7 +19,7 @@ class GetProfilesViewSet(generics.ListAPIView):
def get_queryset(self):
"""
Optionally restricts the returned purchases to a given user,
by filtering against a `username` query parameter in the URL.
by filtering against a `name` query parameter in the URL.
"""
groups = self.request.user.groups.values_list('name',flat = True) # QuerySet Object
groups_list = list(groups) # QuerySet to `list`
......@@ -30,6 +30,12 @@ class GetProfilesViewSet(generics.ListAPIView):
nutritionist_id = self.request.user.nutritionist.id
queryset = queryset.filter(
Q(nutritionist=nutritionist_id) & ~Q(id=self.request.user.id))
name = self.request.query_params.get('name')
if name is not None:
queryset = queryset.filter(Q(name__contains=name.capitalize())
| Q(name__contains=name.lower()))
queryset = queryset.order_by('name')
return queryset
def list(self, request):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment