Fakultas Ilmu Komputer UI

Commit 1dea0ac1 authored by Ami's avatar Ami
Browse files

list of clients is now sorted + adding 'search' functionality for searching clients

parent 4be501ca
Pipeline #79193 passed with stages
in 11 minutes and 8 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/?username=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({
......
......@@ -30,6 +30,13 @@ class GetProfilesViewSet(generics.ListAPIView):
nutritionist_id = self.request.user.nutritionist.id
queryset = queryset.filter(
Q(nutritionist=nutritionist_id) & ~Q(id=self.request.user.id))
username = self.request.query_params.get('username')
if username is not None:
u_capital = username.capitalize()
u_lower = username.lower()
queryset = queryset.filter(Q(name__contains=u_capital) | Q(name__contains=u_lower))
queryset = queryset.order_by('name')
return queryset
def list(self, request):
......
Supports Markdown
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