partners.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django_tables2 import SingleTableView
  2. from sharix_admin.utils import group_required
  3. from sharix_admin.tables import PartnersTable
  4. from django.contrib.auth.decorators import login_required
  5. from dbsynce.models import Company
  6. from django.http import JsonResponse
  7. from django.utils.translation import gettext as _
  8. from .base import BaseView
  9. class PartnersListView(BaseView, SingleTableView):
  10. page_title = _('Partners')
  11. page_name = 'partners'
  12. table_class = PartnersTable
  13. queryset = Company.objects.all()
  14. template_name = 'sharix_admin/partners.html'
  15. def get_context_data(self, **kwargs):
  16. context = super().get_context_data(**kwargs)
  17. context.update({
  18. 'object_list': context['object_list'],
  19. })
  20. return context
  21. def test_func(self):
  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'})