task_management.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django_tables2 import SingleTableView
  2. from django.contrib.auth.mixins import UserPassesTestMixin
  3. from SharixAdmin.groups import group_required
  4. from SharixAdmin.tables import TaskTable
  5. from django.contrib.auth.decorators import login_required
  6. from dbsynce.models import Company
  7. from django.http import JsonResponse
  8. from django.utils.translation import gettext as _
  9. class TaskListView(UserPassesTestMixin, SingleTableView):
  10. table_class = TaskTable
  11. queryset = Company.objects.all()
  12. template_name = 'SharixAdmin/task_management.html'
  13. def get_context_data(self, **kwargs):
  14. context = super().get_context_data(**kwargs)
  15. context.update({
  16. 'title': _('Управление задачами'),
  17. 'object_list': context['object_list'],
  18. 'current_page': "task_management"
  19. })
  20. return context
  21. def test_func(self) -> bool or None:
  22. group_names = ('METASERVICE-ADMIN')
  23. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  24. return True
  25. return False
  26. @login_required
  27. @group_required('METASERVICE-ADMIN')
  28. def change_partners_status(request):
  29. if request.method == 'POST':
  30. partners_id = request.POST.get('partners_id')
  31. new_status = request.POST.get('new_status')
  32. partners = Company.objects.get(pk=partners_id)
  33. partners.status = new_status
  34. partners.save()
  35. return JsonResponse({'status': 'success'})
  36. else:
  37. return JsonResponse({'status': 'error'})