Fixed bug with api response
This commit is contained in:
parent
8488ea88c2
commit
72b70cc585
@ -1,9 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from zenpy import Zenpy
|
from zenpy import Zenpy
|
||||||
from zenpy.lib.exception import APIException
|
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
|
from access_controller.settings import ZENDESK_ROLES as ROLES, ZENDESK_ROLES
|
||||||
|
|
||||||
@ -223,6 +226,9 @@ def update_users_in_model():
|
|||||||
"""
|
"""
|
||||||
users = get_users_list()
|
users = get_users_list()
|
||||||
for user in users:
|
for user in users:
|
||||||
profile = User.objects.get(email=user.email).userprofile
|
try:
|
||||||
update_user_in_model(profile, user)
|
profile = User.objects.get(email=user.email).userprofile
|
||||||
|
update_user_in_model(profile, user)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
pass
|
||||||
return users
|
return users
|
||||||
|
@ -14,4 +14,4 @@ class ProfileSerializer(serializers.HyperlinkedModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserProfile
|
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(
|
users = get_list_or_404(
|
||||||
UserProfile, role='agent')
|
UserProfile, role='agent')
|
||||||
context['users'] = users
|
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
|
return context # TODO: need to get profile page url
|
||||||
|
|
||||||
|
|
||||||
@ -228,7 +228,12 @@ class UsersViewSet(viewsets.ReadOnlyModelViewSet):
|
|||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
users = update_users_in_model()
|
users = update_users_in_model()
|
||||||
profiles = UserProfile.objects.filter(role='agent')
|
|
||||||
count = count_users(users)
|
count = count_users(users)
|
||||||
serializer = self.get_serializer(data=profiles, many=True)
|
profiles = UserProfile.objects.filter(role='agent')
|
||||||
return Response(serializer.data + {'engineers': count[0], 'light_agents': count[1]})
|
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 {
|
class TableRow extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -20,7 +22,13 @@ class TableRow extends React.Component {
|
|||||||
</td>
|
</td>
|
||||||
<td>{this.props.user.user.email}</td>
|
<td>{this.props.user.user.email}</td>
|
||||||
<td>{this.props.user.role}</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>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -29,20 +37,31 @@ class TableRow extends React.Component {
|
|||||||
class TableBody extends React.Component {
|
class TableBody extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { users: [] };
|
this.state = {
|
||||||
|
users: [],
|
||||||
|
engineers: 0,
|
||||||
|
light_agents: 0,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get_users() {
|
get_users() {
|
||||||
axios.get("/api/users").then((response) => {
|
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() {
|
componentDidMount() {
|
||||||
this.interval = setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
this.get_users();
|
this.get_users();
|
||||||
move_checkboxes();
|
}, 10000);
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -56,5 +75,5 @@ class TableBody extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
move_checkboxes();
|
|
||||||
ReactDOM.render(<TableBody />, document.getElementById("table"));
|
ReactDOM.render(<TableBody />, document.getElementById("table"));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user