service_tariff.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. from django.utils.translation import gettext as _
  10. class ServiceTariffCreate(UserPassesTestMixin, CreateView):
  11. model = Service
  12. form_class = ServiceTariffCreateForm
  13. template_name = "SharixAdmin/service_tariff_form.html"
  14. def get_context_data(self, **kwargs):
  15. context = super().get_context_data(**kwargs)
  16. context.update(get_context(self.request, {
  17. 'title': _('Service rates'),
  18. 'object': self.object,
  19. }))
  20. return context
  21. def get_success_url(self):
  22. return reverse('service_tariff')
  23. def test_func(self) -> bool or None:
  24. group_names = ('PARTNER-ADMIN')
  25. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  26. return True
  27. return False
  28. class ServiceTariffListView(UserPassesTestMixin, SingleTableView):
  29. table_class = ServiceTariffTable
  30. queryset = Service.objects.all()
  31. template_name = 'SharixAdmin/service_tariff.html'
  32. def get_context_data(self, **kwargs):
  33. context = super().get_context_data(**kwargs)
  34. context.update(get_context(self.request, {
  35. 'title': _('Performers'),
  36. 'object_list': context['object_list'],
  37. }))
  38. return context
  39. def test_func(self) -> bool or None:
  40. group_names = ('PARTNER-ADMIN')
  41. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  42. return True
  43. return False
  44. class ServiceTariffUpdateView(UserPassesTestMixin, UpdateView):
  45. model = Service
  46. form_class = ServiceTariffUpdateForm
  47. template_name = "SharixAdmin/service_tariff_form.html"
  48. def get_context_data(self, **kwargs):
  49. context = super().get_context_data(**kwargs)
  50. context.update(get_context(self.request, {
  51. 'title': _('Service rates'),
  52. 'object': self.object,
  53. }))
  54. return context
  55. def get_success_url(self):
  56. return reverse('service_tariff')
  57. def test_func(self) -> bool or None:
  58. group_names = ('PARTNER-ADMIN')
  59. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  60. return True
  61. return False