diff --git a/AuthApp/funcs.py b/AuthApp/funcs.py index 139597f..c6c8403 100644 --- a/AuthApp/funcs.py +++ b/AuthApp/funcs.py @@ -1,2 +1,51 @@ +from django.template.loader import render_to_string + +def get_profile_page_content_html(request, page_name, data): + + if page_name == 'chat': + from ChatServiceApp.funcs import get_chat_page_content_html + return get_chat_page_content_html(request, data) + elif page_name == 'create_route_for_customer': + from RoutesApp.funcs import get_profile_new_route_page_html + return get_profile_new_route_page_html(request, {}) + elif page_name == 'create_route_for_mover': + from RoutesApp.funcs import get_profile_new_route_page_html + return get_profile_new_route_page_html(request, {}) + elif page_name == 'my_routes': + from RoutesApp.funcs import get_profile_my_routes_page_content_html + return get_profile_my_routes_page_content_html(request) + elif page_name == 'support': + return get_profile_support_page_content_html(request, data) + elif page_name == 'my_subscribe': + from SubscribesApp.funcs import get_profile_subscribe_page_content_html + return get_profile_subscribe_page_content_html(request) + elif page_name == 'change_profile': + return get_profile_change_page_content_html(request) + else: + return None +def get_profile_change_page_content_html(request): + Dict = { + } + + html = render_to_string('blocks/profile/b_profile.html', Dict, request=request) + return html + + +def get_profile_support_page_content_html(request, data=None): + if request.user.is_staff: + from ChatServiceApp.funcs import get_ticketsDict_for_staff + Dict = get_ticketsDict_for_staff(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).order_by('-modifiedDT') + + Dict = { + 'tickets': tickets, + } + tpl_name = 'blocks/profile/b_support_tickets.html' + + html = render_to_string(tpl_name, Dict, request=request) + return html \ No newline at end of file diff --git a/AuthApp/js_urls.py b/AuthApp/js_urls.py index c181a57..118b650 100644 --- a/AuthApp/js_urls.py +++ b/AuthApp/js_urls.py @@ -16,7 +16,7 @@ urlpatterns = [ path('my_routes/', my_routes_ajax, name='my_routes_ajax'), - path('subscribe/', subscribe_ajax, name='subscribe_ajax'), + # path('subscribe/', subscribe_ajax, name='subscribe_ajax'), path('chats/', chats_ajax, name='chats_ajax'), path('support_tickets/', support_tickets_ajax, name='support_tickets_ajax'), diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index 1824596..4084ab9 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -11,18 +11,19 @@ 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 * -@login_required(login_url='/profile/login/') -def subscribe_ajax(request): - if request.method != 'POST': - raise Http404 - - Dict = { - } - - html = render_to_string('blocks/profile/b_subscribe.html', Dict, request=request) - return JsonResponse({'html': html}, status=200) +# @login_required(login_url='/profile/login/') +# def subscribe_ajax(request): +# if request.method != 'POST': +# raise Http404 +# +# Dict = { +# } +# +# html = render_to_string('blocks/profile/b_subscribe.html', Dict, request=request) +# return JsonResponse({'html': html}, status=200) @login_required(login_url='/profile/login/') def chats_ajax(request): @@ -58,20 +59,8 @@ def support_tickets_ajax(request): if request.method != 'POST': raise Http404 - if request.user.is_staff: - from ChatServiceApp.funcs import get_ticketsDict_for_staff - Dict = get_ticketsDict_for_staff(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).order_by('-modifiedDT') + html = get_profile_support_page_content_html(request) - Dict = { - 'tickets': tickets, - } - tpl_name = 'blocks/profile/b_support_tickets.html' - - html = render_to_string(tpl_name, Dict, request=request) return JsonResponse({'html': html}, status=200) @@ -81,10 +70,7 @@ def change_profile_ajax(request): if request.method != 'POST': raise Http404 - Dict = { - } - - html = render_to_string('blocks/profile/b_profile.html', Dict, request=request) + html = get_profile_change_page_content_html(request) return JsonResponse({'html': html}, status=200) diff --git a/AuthApp/urls.py b/AuthApp/urls.py index 2adb0af..0a0c96c 100644 --- a/AuthApp/urls.py +++ b/AuthApp/urls.py @@ -9,11 +9,14 @@ urlpatterns = [ path('registration/', registration_View, name='registration_page'), path('', user_profile_View, name='user_profile'), - path('chat//', chat_w_user_View, name='chat_w_user'), - path('chat/', chat_w_user_View, name='chat_w_user_wo_user_id'), + # path('page/chat//', chat_w_user_View, name='chat_w_user'), + # path('page/chat/', chat_w_user_View, name='chat_w_user_wo_user_id'), - path('create_route_for_customer/', create_route_for_customer_View, name='create_route_for_customer_View'), - path('create_route_for_mover/', create_route_for_mover_View, name='create_route_for_mover_View'), + path('page//', profile_page_View, name='profile_page'), + path('page///', profile_page_View, name='profile_page_w_param'), + + # path('create_route_for_customer/', create_route_for_customer_View, name='create_route_for_customer_View'), + # path('create_route_for_mover/', create_route_for_mover_View, name='create_route_for_mover_View'), path('login/', login_View, name='login_profile'), path('logout/', logout_View, name='logout_profile'), diff --git a/AuthApp/views.py b/AuthApp/views.py index 88489fe..4aa510a 100644 --- a/AuthApp/views.py +++ b/AuthApp/views.py @@ -12,6 +12,7 @@ from BaseModels.mailSender import techSendMail from django.utils.translation import gettext as _ from datetime import datetime from django.contrib.auth.decorators import login_required +from .funcs import * def registration_View(request): @@ -22,47 +23,57 @@ def registration_View(request): return HttpResponse(t.render(Dict, request)) -def create_route_for_customer_View(request): - Dict = {} - t = loader.get_template('pages/profile/p_user_profile.html') - return HttpResponse(t.render(Dict, request)) - - -def create_route_for_mover_View(request): - Dict = {} - t = loader.get_template('pages/profile/p_user_profile.html') - return HttpResponse(t.render(Dict, request)) +# def create_route_for_customer_View(request): +# Dict = {} +# t = loader.get_template('pages/profile/p_user_profile.html') +# return HttpResponse(t.render(Dict, request)) +# +# +# def create_route_for_mover_View(request): +# Dict = {} +# t = loader.get_template('pages/profile/p_user_profile.html') +# return HttpResponse(t.render(Dict, request)) @login_required(login_url='/profile/login/') -def chat_w_user_View(request, user_id=None): - from ChatServiceApp.funcs import get_chat_page_content_Dict - - # receivers = get_chat_receivers_for_user(request.user) - - Dict = get_chat_page_content_Dict(request, user_id) - - # cur_chat_msgs = None - # - # try: - # cur_receiver = User.objects.get(id=user_id) - # if not cur_receiver in receivers: - # receivers.insert(0, cur_receiver) - # cur_chat_msgs = get_msgs_for_chat_w_users(request.user, cur_receiver) - # except User.DoesNotExist: - # cur_receiver = None - # - # - # Dict = { - # 'page': 'chat', - # 'cur_receiver': cur_receiver, - # 'receivers': receivers, - # 'messages':cur_chat_msgs - # } +def profile_page_View(request, page_name, id=None): + Dict = { + 'page_html': get_profile_page_content_html(request, page_name, id) + } t = loader.get_template('pages/profile/p_user_profile.html') return HttpResponse(t.render(Dict, request)) + +# @login_required(login_url='/profile/login/') +# def chat_w_user_View(request, user_id=None): +# from ChatServiceApp.funcs import get_chat_page_content_Dict +# +# # receivers = get_chat_receivers_for_user(request.user) +# +# Dict = get_chat_page_content_Dict(request, user_id) +# +# # cur_chat_msgs = None +# # +# # try: +# # cur_receiver = User.objects.get(id=user_id) +# # if not cur_receiver in receivers: +# # receivers.insert(0, cur_receiver) +# # cur_chat_msgs = get_msgs_for_chat_w_users(request.user, cur_receiver) +# # except User.DoesNotExist: +# # cur_receiver = None +# # +# # +# # Dict = { +# # 'page': 'chat', +# # 'cur_receiver': cur_receiver, +# # 'receivers': receivers, +# # 'messages':cur_chat_msgs +# # } +# +# t = loader.get_template('pages/profile/p_user_profile.html') +# return HttpResponse(t.render(Dict, request)) + @login_required(login_url='/profile/login/') def user_profile_View(request): diff --git a/ChatServiceApp/funcs.py b/ChatServiceApp/funcs.py index f8f2ead..5db51e9 100644 --- a/ChatServiceApp/funcs.py +++ b/ChatServiceApp/funcs.py @@ -211,6 +211,55 @@ def send_msg(data): +def get_create_route_for_customer_page_content_Dict(request): + from AuthApp.models import User + + msgs = [] + try: + cur_receiver = User.objects.get(id=receiver_id) + + msgs = get_msgs_for_chat_w_users(request.user, cur_receiver) + msgs.filter(receiver=request.user).update(status='seen') + + except User.DoesNotExist: + cur_receiver = None + + receivers, unread_msgs_count = get_chat_receivers_for_user(request.user) + + Dict = { + 'cur_receiver': cur_receiver, + 'messages': msgs, + 'receivers': receivers, + 'page': 'chat', + } + return Dict + + +def get_chat_page_content_html(request, receiver_id=None): + from AuthApp.models import User + + msgs = [] + try: + cur_receiver = User.objects.get(id=receiver_id) + + msgs = get_msgs_for_chat_w_users(request.user, cur_receiver) + msgs.filter(receiver=request.user).update(status='seen') + + except User.DoesNotExist: + cur_receiver = None + + receivers, unread_msgs_count = get_chat_receivers_for_user(request.user) + + Dict = { + 'cur_receiver': cur_receiver, + 'messages': msgs, + 'receivers': receivers, + 'page': 'chat', + } + tpl_name = 'blocks/profile/b_chats.html' + + html = render_to_string(tpl_name, Dict, request=request) + return html def get_chat_page_content_Dict(request, receiver_id=None): from AuthApp.models import User diff --git a/RoutesApp/funcs.py b/RoutesApp/funcs.py index ff9a7bd..3ad0c73 100644 --- a/RoutesApp/funcs.py +++ b/RoutesApp/funcs.py @@ -1,4 +1,88 @@ from .models import * +from .forms import * +from django.utils.translation import gettext as _ +from django.template.loader import render_to_string + +def get_profile_new_route_page_html(request, data): + + form = RouteForm() + Dict = { + 'form': form + } + try: + + errors_off = True + + if 'from_address_point' in data: + del data['from_address_point'] + if 'from_address_point_txt' in data: + del data['from_address_point_txt'] + + if 'to_address_point' in data: + del data['to_address_point'] + if 'to_address_point_txt' in data: + del data['to_address_point_txt'] + + if 'type_transport' in data: + if data['type_transport'] == 'avia': + transfer_location_choices = ( + ('airport', _('В аэропорту')), + ('city', _('По городу')), + ('other', _('По договоренности')) + ) + + cargo_type_choices = ( + ('passenger', _('Пассажир')), + ('cargo', _('Груз')), + ('parcel', _('Бандероль')), + ('package', _('Посылка')), + ('letter', _('Письмо\Документ')) + ) + + + else: + transfer_location_choices = ( + ('city', _('По городу')), + ('other', _('По договоренности')) + ) + + cargo_type_choices = ( + ('cargo', _('Груз')), + ('parcel', _('Бандероль')), + ('package', _('Посылка')), + ('letter', _('Письмо\Документ')) + ) + + form = RouteForm(data) + if not form.is_valid(): + pass + form = RouteForm(initial=form.cleaned_data) + + form.fields['from_place'].choices = transfer_location_choices + form.fields['to_place'].choices = transfer_location_choices + form.fields['cargo_type'].choices = cargo_type_choices + + form.base_fields['from_place'].choices = transfer_location_choices + form.base_fields['to_place'].choices = transfer_location_choices + form.base_fields['cargo_type'].choices = cargo_type_choices + + # form = CreateRouteForm(initial=data) + + # if not form.is_valid(): + # pass + + Dict = { + 'form': form, + 'errors_off': errors_off + } + + # print(form) + except Exception as e: + # form.errors.append({'__all__': f'Ошибка: {str(e)}'}) + print(str(e)) + + html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request) + return html def get_city_by_type_transport_and_address_point(type_transport, address_point): @@ -14,6 +98,18 @@ def get_city_by_type_transport_and_address_point(type_transport, address_point): print(msg) return None + +def get_profile_my_routes_page_content_html(request): + routes_Dict = get_routes_Dict(request.user) + if 'errors' in routes_Dict: + msg = f'get_my_routes_page_content_html errors = {str(routes_Dict)}' + print(msg) + return msg + + html = render_to_string('blocks/profile/b_my_routes.html', routes_Dict, request=request) + return html + + def get_routes_Dict(user=None, data=None): from ReferenceDataApp.models import Airport, Country, City diff --git a/RoutesApp/js_urls.py b/RoutesApp/js_urls.py index b959758..5132b11 100644 --- a/RoutesApp/js_urls.py +++ b/RoutesApp/js_urls.py @@ -10,7 +10,7 @@ urlpatterns = [ path('edit_route/', edit_route_ajax, name='edit_route_ajax'), - path('get_routes/', get_routes_ajax, name='get_routes_ajax'), + path('get_routes/', get_my_routes_ajax, name='get_my_routes_ajax'), path('find_routes/', find_routes_ajax, name='find_routes_ajax'), ] \ No newline at end of file diff --git a/RoutesApp/js_views.py b/RoutesApp/js_views.py index 71f8123..9baad0e 100644 --- a/RoutesApp/js_views.py +++ b/RoutesApp/js_views.py @@ -61,10 +61,10 @@ def new_route_view_ajax(request): if request.method != 'POST': raise Http404 - form = RouteForm() - Dict = { - 'form': form - } + # form = RouteForm() + # Dict = { + # 'form': form + # } try: errors_off = True @@ -74,75 +74,17 @@ def new_route_view_ajax(request): data = json.loads(request.body) # show_errors = False - if 'from_address_point' in data: - del data['from_address_point'] - if 'from_address_point_txt' in data: - del data['from_address_point_txt'] - - if 'to_address_point' in data: - del data['to_address_point'] - if 'to_address_point_txt' in data: - del data['to_address_point_txt'] - - if 'type_transport' in data: - if data['type_transport'] == 'avia': - transfer_location_choices = ( - ('airport', _('В аэропорту')), - ('city', _('По городу')), - ('other', _('По договоренности')) - ) - - cargo_type_choices = ( - ('passenger', _('Пассажир')), - ('cargo', _('Груз')), - ('parcel', _('Бандероль')), - ('package', _('Посылка')), - ('letter', _('Письмо\Документ')) - ) + html = get_profile_new_route_page_html(request, data) - else: - transfer_location_choices = ( - ('city', _('По городу')), - ('other', _('По договоренности')) - ) - - cargo_type_choices = ( - ('cargo', _('Груз')), - ('parcel', _('Бандероль')), - ('package', _('Посылка')), - ('letter', _('Письмо\Документ')) - ) - - form = RouteForm(data) - if not form.is_valid(): - pass - form = RouteForm(initial=form.cleaned_data) - - form.fields['from_place'].choices = transfer_location_choices - form.fields['to_place'].choices = transfer_location_choices - form.fields['cargo_type'].choices = cargo_type_choices - - form.base_fields['from_place'].choices = transfer_location_choices - form.base_fields['to_place'].choices = transfer_location_choices - form.base_fields['cargo_type'].choices = cargo_type_choices - - # form = CreateRouteForm(initial=data) - - # if not form.is_valid(): - # pass - - Dict = { - 'form': form, - 'errors_off': errors_off - } - - # print(form) except Exception as e: # form.errors.append({'__all__': f'Ошибка: {str(e)}'}) - print(str(e)) + msg = f'new_route_view_ajax Error = {str(e)}' + print(msg) + html = msg - html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request) + + # html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request) return JsonResponse({'html': html}, status=200) @@ -186,7 +128,7 @@ def find_routes_ajax(request): return JsonResponse(errors_Dict, status=400) -def get_routes_ajax(request): +def get_my_routes_ajax(request): if request.method != 'POST': diff --git a/SubscribesApp/funcs.py b/SubscribesApp/funcs.py new file mode 100644 index 0000000..4f07db3 --- /dev/null +++ b/SubscribesApp/funcs.py @@ -0,0 +1,35 @@ +from .models import * +from django.template.loader import render_to_string + +def get_profile_subscribe_page_content_html(request): + + try: + + # data = json.loads(request.body) + all_options = SubscribeOption.objects.filter(enable=True) + + subscribe_for_user = SubscribeForUser.objects.filter(user=request.user) + if not subscribe_for_user: + tpl_name = 'blocks/profile/b_subscribe_variants.html' + else: + tpl_name = 'blocks/profile/b_subscribe_current.html' + subscribe_for_user = subscribe_for_user[0] + subscribe_options_ids = subscribe_for_user.subscribe.options.values_list('id', flat=True) + subscribe_for_user.subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids) + + subscribes = Subscribe.objects.filter(enable=True) + for subscribe in subscribes: + subscribe_options_ids = subscribe.options.values_list('id', flat=True) + subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids) + + Dict = { + 'subscribe_for_user': subscribe_for_user, + 'subscribes': subscribes + } + + html = render_to_string(tpl_name, Dict, request=request) + return html + + except Exception as e: + msg = f'show_cur_subscribe_ajax Error = {str(e)}' + return msg \ No newline at end of file diff --git a/SubscribesApp/js_views.py b/SubscribesApp/js_views.py index ff8abf2..7deb9f4 100644 --- a/SubscribesApp/js_views.py +++ b/SubscribesApp/js_views.py @@ -11,13 +11,14 @@ 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 * +from .funcs import * import json from datetime import datetime, time, timedelta from channels.layers import get_channel_layer from asgiref.sync import async_to_sync + @login_required(login_url='/profile/login/') def subscribe_now_ajax(request): @@ -76,33 +77,36 @@ def show_cur_subscribe_ajax(request): if request.method != 'POST': raise Http404 - try: + html = get_profile_subscribe_page_content_html(request) + return JsonResponse({'html': html}, status=200) - # data = json.loads(request.body) - all_options = SubscribeOption.objects.filter(enable=True) - - subscribe_for_user = SubscribeForUser.objects.filter(user=request.user) - if not subscribe_for_user: - tpl_name = 'blocks/profile/b_subscribe_variants.html' - else: - tpl_name = 'blocks/profile/b_subscribe_current.html' - subscribe_for_user = subscribe_for_user[0] - subscribe_options_ids = subscribe_for_user.subscribe.options.values_list('id', flat=True) - subscribe_for_user.subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids) - - subscribes = Subscribe.objects.filter(enable=True) - for subscribe in subscribes: - subscribe_options_ids = subscribe.options.values_list('id', flat=True) - subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids) - - Dict = { - 'subscribe_for_user': subscribe_for_user, - 'subscribes': subscribes - } - - html = render_to_string(tpl_name, Dict, request=request) - return JsonResponse({'html': html}, status=200) - - except Exception as e: - msg = f'show_cur_subscribe_ajax Error = {str(e)}' - return JsonResponse({'error': msg}, status=400) \ No newline at end of file + # try: + # + # # data = json.loads(request.body) + # all_options = SubscribeOption.objects.filter(enable=True) + # + # subscribe_for_user = SubscribeForUser.objects.filter(user=request.user) + # if not subscribe_for_user: + # tpl_name = 'blocks/profile/b_subscribe_variants.html' + # else: + # tpl_name = 'blocks/profile/b_subscribe_current.html' + # subscribe_for_user = subscribe_for_user[0] + # subscribe_options_ids = subscribe_for_user.subscribe.options.values_list('id', flat=True) + # subscribe_for_user.subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids) + # + # subscribes = Subscribe.objects.filter(enable=True) + # for subscribe in subscribes: + # subscribe_options_ids = subscribe.options.values_list('id', flat=True) + # subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids) + # + # Dict = { + # 'subscribe_for_user': subscribe_for_user, + # 'subscribes': subscribes + # } + # + # html = render_to_string(tpl_name, Dict, request=request) + # return JsonResponse({'html': html}, status=200) + # + # except Exception as e: + # msg = f'show_cur_subscribe_ajax Error = {str(e)}' + # return JsonResponse({'error': msg}, status=400) \ No newline at end of file diff --git a/static/js/find_route.js b/static/js/find_route.js index 382ffc5..e5cdb6a 100644 --- a/static/js/find_route.js +++ b/static/js/find_route.js @@ -48,7 +48,7 @@ function open_chat (user_id){ event.preventDefault() let host = window.location.origin let user_id_ = user_id.toString() - let href = host + '/ru/profile/chat/' + user_id_ + let href = host + '/ru/profile/page/chat/' + user_id_ // window.location.href = host + '/profile/chat/' + user_id window.location.replace(href) } \ No newline at end of file diff --git a/templates/blocks/b_footer.html b/templates/blocks/b_footer.html index 2b00087..a25c69a 100644 --- a/templates/blocks/b_footer.html +++ b/templates/blocks/b_footer.html @@ -20,8 +20,8 @@
Информация
- +
diff --git a/templates/blocks/b_user_profile.html b/templates/blocks/b_user_profile.html index 6b65c12..22e34d3 100644 --- a/templates/blocks/b_user_profile.html +++ b/templates/blocks/b_user_profile.html @@ -48,10 +48,13 @@
- {% if not page %} + {% if not page_html %} {% include "blocks/profile/b_profile_first_page.html" %} - {% elif page == 'chat' %} - {% include "blocks/profile/b_chats.html" %} + {% else %} + {{ page_html|safe }} +{# {% include "blocks/profile/b_chats.html" %}#} +{# {% elif page == 'chat' %}#} +{# {% include "blocks/profile/b_chats.html" %}#} {% endif %}