123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- from django_tables2 import SingleTableView
- from django.views.generic.edit import UpdateView, CreateView, DeleteView
- from SharixAdmin.tables import CommentsTable
- from django.contrib.auth.mixins import UserPassesTestMixin
- from SharixAdmin.forms import CommentsCreateForm, ServiceTypeUpdateForm
- from dbsynce.models import Comments
- from django.urls import reverse
- from django.utils.translation import gettext as _
- from SharixAdmin.utils import group_required
- from django.contrib.auth.decorators import login_required
- from django.http import JsonResponse
-
-
- class CommentsCreate(UserPassesTestMixin, CreateView):
- model = Comments
- form_class = CommentsCreateForm
- template_name = "SharixAdmin/tech_support_form.html"
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': _('Техническая поддержка'),
- 'object': self.object,
- "current_page": "tech_support"
- })
- return context
-
- def get_success_url(self):
- return reverse('tech_support')
-
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
- return True
- return False
-
-
-
- class CommentsListView(UserPassesTestMixin, SingleTableView):
- table_class = CommentsTable
- queryset = Comments.objects.all()
- template_name = 'SharixAdmin/comments.html'
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': 'Комментарии',
- 'object_list': context['object_list'],
- "current_page": "comments"
- })
- return context
-
- def testing(self, queryset, is_descending):
- queryset = queryset.annotate.order_by("-" if is_descending else "")
- return (queryset, True)
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
- class CommentsUpdateView(UserPassesTestMixin, UpdateView):
- model = Comments
- form_class = CommentsCreateForm
- template_name = "SharixAdmin/tech_support_form.html"
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': _('Комментарии'),
- 'object': self.object,
- "current_page": "tech_support"
- })
- return context
-
-
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
- return True
- return False
-
- def get_success_url(self):
- return reverse('tech_support')
- class CommentsDelete(UserPassesTestMixin, DeleteView):
- model = Comments
- template_name = "SharixAdmin/comments_delete.html"
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': 'Комментарии',
- 'object': self.object,
- "current_page": "comments"
- })
- return context
-
- def get_success_url(self):
- return reverse('comments')
-
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
- @login_required
- @group_required('METASERVICE-ADMIN')
- def change_comments_status(request):
- if request.method == 'POST':
- comments_id = request.POST.get('comments_id')
- new_status = request.POST.get('new_status')
- comments = Comments.objects.get(pk=comments_id)
- comments.status = new_status
- comments.save()
- return JsonResponse({'status': 'success'})
- else:
- return JsonResponse({'status': 'error'})
|