partners.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from django_tables2 import SingleTableView
  2. from SharixAdmin.tables import PartnersTable
  3. from django.contrib.auth.decorators import login_required
  4. from metaservicesynced.models import Company
  5. from SharixAdmin.views.context import get_context
  6. from django.http import JsonResponse
  7. class PartnersListView(SingleTableView):
  8. table_class = PartnersTable
  9. queryset = Company.objects.all()
  10. template_name = 'SharixAdmin/partners.html'
  11. def get_context_data(self, **kwargs):
  12. context = super().get_context_data(**kwargs)
  13. context.update(get_context(self.request, {
  14. 'title': 'Партнеры',
  15. 'object_list': context['object_list'],
  16. }))
  17. return context
  18. @login_required
  19. def change_partners_status(request):
  20. if request.method == 'POST':
  21. partners_id = request.POST.get('partners_id')
  22. new_status = request.POST.get('new_status')
  23. partners = Company.objects.get(pk=partners_id)
  24. partners.status = new_status
  25. partners.save()
  26. return JsonResponse({'status': 'success'})
  27. else:
  28. return JsonResponse({'status': 'error'})