become_partner.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 become_partnerTable
  5. from django.contrib.auth.decorators import login_required
  6. from metaservicesynced.models import Company
  7. from SharixAdmin.views.context import get_context
  8. from django.http import JsonResponse
  9. from django.http import HttpResponse
  10. class become_partnerListView(UserPassesTestMixin, SingleTableView):
  11. table_class = become_partnerTable
  12. queryset = Company.objects.all()
  13. template_name = 'SharixAdmin/become_partner.html'
  14. def get_context_data(self, **kwargs):
  15. context = super().get_context_data(**kwargs)
  16. context.update(get_context(self.request, {
  17. 'title': 'Стать партнером',
  18. 'object_list': context['object_list'],
  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_become_partner_status(request):
  29. if request.method == 'POST':
  30. become_partner_id = request.POST.get('become_partner_id')
  31. new_status = request.POST.get('new_status')
  32. become_partner = Company.objects.get(pk=become_partner_id)
  33. become_partner.status = new_status
  34. coopertion.save()
  35. return JsonResponse({'status': 'success'})
  36. else:
  37. return JsonResponse({'status': 'error'})