diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index be24233..ae62516 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -40,14 +40,23 @@ def support_tickets_ajax(request): if request.method != 'POST': raise Http404 - from ChatServiceApp.models import MsgGroup - tickets = MsgGroup.objects.filter(enable=True, owner=request.user) + if request.user.is_staff: + from ChatServiceApp.funcs import get_tickets_for_manager, get_tickets_wo_manager + Dict = { + 'tickets_wo_manager': get_tickets_wo_manager(), + 'tickets_for_manager': get_tickets_for_manager(request.user), + } + tpl_name = 'blocks/profile/b_support_chat.html' + else: + from ChatServiceApp.models import MsgGroup + tickets = MsgGroup.objects.filter(enable=True, owner=request.user) - Dict = { - 'tickets': tickets - } + Dict = { + 'tickets': tickets + } + tpl_name = 'blocks/profile/b_support_tickets.html' - html = render_to_string('blocks/profile/b_support_tickets.html', Dict, request=request) + html = render_to_string(tpl_name, Dict, request=request) return JsonResponse({'html': html}, status=200) diff --git a/ChatServiceApp/funcs.py b/ChatServiceApp/funcs.py new file mode 100644 index 0000000..6384bce --- /dev/null +++ b/ChatServiceApp/funcs.py @@ -0,0 +1,13 @@ +from .models import * + +def get_tickets_wo_manager(): + + tickets = MsgGroup.objects.filter(enable=True, manager=None) + + return tickets + +def get_tickets_for_manager(user): + + tickets = MsgGroup.objects.filter(enable=True, manager=user) + + return tickets \ No newline at end of file diff --git a/ChatServiceApp/js_urls.py b/ChatServiceApp/js_urls.py index 9641770..89e0918 100644 --- a/ChatServiceApp/js_urls.py +++ b/ChatServiceApp/js_urls.py @@ -9,6 +9,5 @@ from RoutesApp.js_views import new_route_view_ajax urlpatterns = [ path('support_create_ticket_form/', support_create_ticket_form_ajax, name='support_create_ticket_form_ajax'), path('create_ticket/', create_ticket_ajax, name='create_ticket_ajax'), - # path('create_/', registration_ajax, name='registration_ajax'), - + path('support_show_chat_by_ticket/', support_show_chat_by_ticket_ajax, name='support_show_chat_by_ticket_ajax'), ] \ No newline at end of file diff --git a/ChatServiceApp/js_views.py b/ChatServiceApp/js_views.py index 68f90e3..a7e000b 100644 --- a/ChatServiceApp/js_views.py +++ b/ChatServiceApp/js_views.py @@ -11,10 +11,33 @@ from django.utils.translation import gettext as _ from datetime import datetime from django.template.loader import render_to_string from django.urls import reverse +from .funcs import * +import json +@login_required(login_url='/profile/login/') +def support_show_chat_by_ticket_ajax(request): + if request.method != 'POST': + raise Http404 + try: + data = json.loads(request.body) + + obj = MsgGroup.objects.get(id=data['ticket_id']) + + Dict = { + 'ticket': obj + } + + tpl_name = 'blocks/profile/b_support_chat.html' + + html = render_to_string(tpl_name, Dict, request=request) + return JsonResponse({'html': html}, status=200) + + except Exception as e: + msg = f'support_show_chat_by_ticket_ajax Error = {str(e)}' + return JsonResponse({'error': msg}, status=400) @login_required(login_url='/profile/login/') @@ -24,11 +47,13 @@ def support_create_ticket_form_ajax(request): if request.method != 'POST': raise Http404 + Dict = { 'form': TicketForm() } + tpl_name = 'blocks/profile/b_create_ticket.html' - html = render_to_string('blocks/profile/b_create_ticket.html', Dict, request=request) + html = render_to_string(tpl_name, Dict, request=request) return JsonResponse({'html': html}, status=200) diff --git a/RoutesApp/js_views.py b/RoutesApp/js_views.py index 6707c84..b9ba100 100644 --- a/RoutesApp/js_views.py +++ b/RoutesApp/js_views.py @@ -177,7 +177,7 @@ def get_routes_ajax(request): -def create_or_change_route_ajax(request, route_id): +def create_or_change_route_ajax(request, route_id=None): if request.method != 'POST': raise Http404 diff --git a/templates/blocks/profile/b_support_chat.html b/templates/blocks/profile/b_support_chat.html index ce176f5..fd0ff40 100644 --- a/templates/blocks/profile/b_support_chat.html +++ b/templates/blocks/profile/b_support_chat.html @@ -5,39 +5,54 @@
- Название темы + {{ ticket.name }}
-
-
- - Сергейко Сергей + {% if user.is_staff or ticket.manager %} +
+
+ + {{ ticket.manager.last_name }} {{ ticket.manager.first_name }} +
+
+ + +
-
- - -
-
-
- {% include "widgets/w_message.html" %} - -
- \ No newline at end of file diff --git a/templates/widgets/w_tab_user.html b/templates/widgets/w_tab_user.html index 5dd0f22..e402ee4 100644 --- a/templates/widgets/w_tab_user.html +++ b/templates/widgets/w_tab_user.html @@ -6,8 +6,8 @@
- Сергейко Сергей - Текст сообщения + {{ ticket.owner.last_name }} {{ ticket.owner.first_name }} + {{ ticket.name }}