Fixed bug with api response

This commit is contained in:
Yuriy Kulakov
2021-03-11 19:29:16 +03:00
parent 8488ea88c2
commit 72b70cc585
4 changed files with 44 additions and 14 deletions

View File

@@ -1,9 +1,12 @@
import os
from django.contrib.auth.models import User
from zenpy import Zenpy
from zenpy.lib.exception import APIException
from main.models import UserProfile, User
from main.models import UserProfile
from django.core.exceptions import ObjectDoesNotExist
from access_controller.settings import ZENDESK_ROLES as ROLES, ZENDESK_ROLES
@@ -223,6 +226,9 @@ def update_users_in_model():
"""
users = get_users_list()
for user in users:
profile = User.objects.get(email=user.email).userprofile
update_user_in_model(profile, user)
try:
profile = User.objects.get(email=user.email).userprofile
update_user_in_model(profile, user)
except ObjectDoesNotExist:
pass
return users

View File

@@ -14,4 +14,4 @@ class ProfileSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = UserProfile
fields = ['user', 'role', 'name']
fields = ['user', 'id', 'role', 'name']

View File

@@ -208,7 +208,7 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin, FormView):
users = get_list_or_404(
UserProfile, role='agent')
context['users'] = users
context['engineers'], context['light_agents'] = count_users(users)
context['engineers'], context['light_agents'] = count_users(get_users_list())
return context # TODO: need to get profile page url
@@ -228,7 +228,12 @@ class UsersViewSet(viewsets.ReadOnlyModelViewSet):
def list(self, request, *args, **kwargs):
users = update_users_in_model()
profiles = UserProfile.objects.filter(role='agent')
count = count_users(users)
serializer = self.get_serializer(data=profiles, many=True)
return Response(serializer.data + {'engineers': count[0], 'light_agents': count[1]})
profiles = UserProfile.objects.filter(role='agent')
serializer = self.get_serializer(profiles, many=True)
return Response({
'users': serializer.data,
'engineers': count[0],
'light_agents': count[1]
})