1
0

service_tariff.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from django_tables2 import SingleTableView
  2. from django.contrib.auth.mixins import UserPassesTestMixin
  3. from django.views.generic.edit import UpdateView, CreateView
  4. from SharixAdmin.tables import ServiceTariffTable
  5. from SharixAdmin.forms import ServiceTariffCreateForm, ServiceTariffUpdateForm
  6. from metaservicesynced.models import Service
  7. from django.urls import reverse
  8. from SharixAdmin.views.context import get_context
  9. class ServiceTariffCreate(UserPassesTestMixin, CreateView):
  10. model = Service
  11. form_class = ServiceTariffCreateForm
  12. template_name = "SharixAdmin/service_tariff_form.html"
  13. def get_context_data(self, **kwargs):
  14. context = super().get_context_data(**kwargs)
  15. context.update(get_context(self.request, {
  16. 'title': 'Тарифы услуг',
  17. 'object': self.object,
  18. }))
  19. return context
  20. def get_success_url(self):
  21. return reverse('service_tariff')
  22. def test_func(self) -> bool or None:
  23. group_names = ('PARTNER-ADMIN')
  24. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  25. return True
  26. return False
  27. class ServiceTariffListView(UserPassesTestMixin, SingleTableView):
  28. table_class = ServiceTariffTable
  29. queryset = Service.objects.all()
  30. template_name = 'SharixAdmin/service_tariff.html'
  31. def get_context_data(self, **kwargs):
  32. context = super().get_context_data(**kwargs)
  33. context.update(get_context(self.request, {
  34. 'title': 'Исполнители',
  35. 'object_list': context['object_list'],
  36. }))
  37. return context
  38. def test_func(self) -> bool or None:
  39. group_names = ('PARTNER-ADMIN')
  40. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  41. return True
  42. return False
  43. class ServiceTariffUpdateView(UserPassesTestMixin, UpdateView):
  44. model = Service
  45. form_class = ServiceTariffUpdateForm
  46. template_name = "SharixAdmin/service_tariff_form.html"
  47. def get_context_data(self, **kwargs):
  48. context = super().get_context_data(**kwargs)
  49. context.update(get_context(self.request, {
  50. 'title': 'Тарифы услуг',
  51. 'object': self.object,
  52. }))
  53. return context
  54. def get_success_url(self):
  55. return reverse('service_tariff')
  56. def test_func(self) -> bool or None:
  57. group_names = ('PARTNER-ADMIN')
  58. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  59. return True
  60. return False