service_tariff.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from django_tables2 import SingleTableView
  2. from django.views.generic.edit import UpdateView, CreateView
  3. from SharixAdmin.tables import ServiceTariffTable
  4. from SharixAdmin.forms import ServiceTariffCreateForm, ServiceTariffUpdateForm
  5. from metaservicesynced.models import Service
  6. from django.urls import reverse
  7. from SharixAdmin.views.context import get_context
  8. class ServiceTariffCreate(CreateView):
  9. model = Service
  10. form_class = ServiceTariffCreateForm
  11. template_name = "SharixAdmin/service_tariff_form.html"
  12. def get_context_data(self, **kwargs):
  13. context = super().get_context_data(**kwargs)
  14. context.update(get_context(self.request, {
  15. 'title': 'Тарифы услуг',
  16. 'object': self.object,
  17. }))
  18. return context
  19. def get_success_url(self):
  20. return reverse('service_tariff')
  21. class ServiceTariffListView(SingleTableView):
  22. table_class = ServiceTariffTable
  23. queryset = Service.objects.all()
  24. template_name = 'SharixAdmin/service_tariff.html'
  25. def get_context_data(self, **kwargs):
  26. context = super().get_context_data(**kwargs)
  27. context.update(get_context(self.request, {
  28. 'title': 'Исполнители',
  29. 'object_list': context['object_list'],
  30. }))
  31. return context
  32. class ServiceTariffUpdateView(UpdateView):
  33. model = Service
  34. form_class = ServiceTariffUpdateForm
  35. template_name = "SharixAdmin/service_tariff_form.html"
  36. def get_context_data(self, **kwargs):
  37. context = super().get_context_data(**kwargs)
  38. context.update(get_context(self.request, {
  39. 'title': 'Тарифы услуг',
  40. 'object': self.object,
  41. }))
  42. return context
  43. def get_success_url(self):
  44. return reverse('service_tariff')