service.py 980 B

12345678910111213141516171819202122232425262728
  1. from django_tables2 import SingleTableView
  2. from SharixAdmin.tables import ServiceTable
  3. from metaservicesynced.models import Service
  4. from django.contrib.auth.decorators import login_required
  5. from SharixAdmin.views.context import get_context
  6. class ServiceListView(SingleTableView):
  7. table_class = ServiceTable
  8. queryset = Service.objects.all()
  9. template_name = 'SharixAdmin/service.html'
  10. def get_context_data(self, **kwargs):
  11. context = super().get_context_data(**kwargs)
  12. context.update(get_context(self.request, {
  13. 'title': 'Тарифы',
  14. 'object_list': context['object_list'],
  15. }))
  16. return context
  17. @login_required
  18. def change_service_status(request):
  19. if request.method == 'POST':
  20. service_id = request.POST.get('service_id')
  21. new_status = request.POST.get('new_status')
  22. service = Service.objects.get(pk=service_id)
  23. service.status = new_status
  24. service.save()