1234567891011121314151617181920212223242526272829303132333435363738394041 |
- from django_tables2 import SingleTableView
- from django.contrib.auth.mixins import UserPassesTestMixin
- from SharixAdmin.utils import group_required
- from SharixAdmin.tables import ResourceTable
- from django.contrib.auth.decorators import login_required
- from dbsynce.models import Resource
- from django.http import JsonResponse
- from django.utils.translation import gettext as _
- class ResourceListView(UserPassesTestMixin, SingleTableView):
- table_class = ResourceTable
- queryset = Resource.objects.all()
- template_name = 'SharixAdmin/resource.html'
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': _('Resources'),
- 'object_list': context['object_list'],
- })
- return context
-
- def test_func(self) -> bool or None:
- group_names = ('PARTNER-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('PARTNER-ADMIN')
- def change_resource_status(request):
- if request.method == 'POST':
- resource_id = request.POST.get('resource_id')
- new_status = request.POST.get('new_status')
-
- resource = Resource.objects.get(pk=resource_id)
- resource.status = new_status
- resource.save()
- return JsonResponse({'status': 'success'})
- else:
- return JsonResponse({'status': 'error'})
|