Fixed bug with api response
This commit is contained in:
parent
8488ea88c2
commit
72b70cc585
@ -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
|
||||
|
@ -14,4 +14,4 @@ class ProfileSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
fields = ['user', 'role', 'name']
|
||||
fields = ['user', 'id', 'role', 'name']
|
||||
|
@ -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]
|
||||
})
|
||||
|
||||
|
@ -10,7 +10,9 @@ function move_checkboxes() {
|
||||
}
|
||||
}
|
||||
}
|
||||
move_checkboxes();
|
||||
|
||||
// React
|
||||
class TableRow extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
@ -20,7 +22,13 @@ class TableRow extends React.Component {
|
||||
</td>
|
||||
<td>{this.props.user.user.email}</td>
|
||||
<td>{this.props.user.role}</td>
|
||||
<td className="checkbox_field"></td>
|
||||
<td>
|
||||
<input
|
||||
type="checkbox"
|
||||
value={this.props.user.id}
|
||||
className="form-check-input"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
@ -29,20 +37,31 @@ class TableRow extends React.Component {
|
||||
class TableBody extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { users: [] };
|
||||
this.state = {
|
||||
users: [],
|
||||
engineers: 0,
|
||||
light_agents: 0,
|
||||
};
|
||||
}
|
||||
|
||||
get_users() {
|
||||
axios.get("/api/users").then((response) => {
|
||||
this.setState({ users: response.data });
|
||||
this.setState({
|
||||
users: response.data.users,
|
||||
engineers: response.data.engineers,
|
||||
light_agents: response.data.light_agents,
|
||||
});
|
||||
let elements = document.querySelectorAll(".info-quantity-value");
|
||||
console.log(elements)
|
||||
elements[0].innerHTML = this.state.engineers;
|
||||
elements[1].innerHTML = this.state.light_agents;
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.interval = setInterval(() => {
|
||||
this.get_users();
|
||||
move_checkboxes();
|
||||
}, 1000);
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@ -56,5 +75,5 @@ class TableBody extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
move_checkboxes();
|
||||
ReactDOM.render(<TableBody />, document.getElementById("table"));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user