12345678910111213141516171819202122232425262728293031323334353637383940 |
- from django_tables2 import SingleTableView
- from django.contrib.auth.mixins import UserPassesTestMixin
- from SharixAdmin.groups import group_required
- from SharixAdmin.tables import CooperationTable
- from django.contrib.auth.decorators import login_required
- from metaservicesynced.models import Company
- from SharixAdmin.views.context import get_context
- from django.http import JsonResponse
- class CooperationListView(UserPassesTestMixin, SingleTableView):
- table_class = CooperationTable
- queryset = Company.objects.all()
- template_name = 'SharixAdmin/cooperation.html'
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update(get_context(self.request, {
- 'title': 'Сотрудничество',
- 'object_list': context['object_list'],
- }))
- return context
-
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
- @login_required
- @group_required('METASERVICE-ADMIN')
- def change_cooperation_status(request):
- if request.method == 'POST':
- cooperation_id = request.POST.get('cooperation_id')
- new_status = request.POST.get('new_status')
- cooperation = Company.objects.get(pk=cooperation_id)
- cooperation.status = new_status
- coopertion.save()
- return JsonResponse({'status': 'success'})
- else:
- return JsonResponse({'status': 'error'})
|