profile static pages
This commit is contained in:
SDE
2023-09-04 12:08:25 +03:00
parent 436cd9aa58
commit 7dd1fe5dfe
14 changed files with 354 additions and 173 deletions

View File

@@ -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

View File

@@ -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'),

View File

@@ -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)

View File

@@ -9,11 +9,14 @@ urlpatterns = [
path('registration/', registration_View, name='registration_page'),
path('', user_profile_View, name='user_profile'),
path('chat/<int:user_id>/', chat_w_user_View, name='chat_w_user'),
path('chat/', chat_w_user_View, name='chat_w_user_wo_user_id'),
# path('page/chat/<int:user_id>/', 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/<str:page_name>/', profile_page_View, name='profile_page'),
path('page/<str:page_name>/<int:id>/', 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'),

View File

@@ -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):

View File

@@ -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

View File

@@ -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

View File

@@ -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'),
]

View File

@@ -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':

35
SubscribesApp/funcs.py Normal file
View File

@@ -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

View File

@@ -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)
# 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)

View File

@@ -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)
}

View File

@@ -20,8 +20,8 @@
<div>Информация</div>
<div>
<div>
<div><a href="{% url 'create_route_for_mover_View' %}">Перевезти посылку</a></div>
<div><a href="{% url 'create_route_for_customer_View' %}">Отправить посылку</a></div>
<div><a href="{% url 'profile_page' 'create_route_for_mover' %}">Перевезти посылку</a></div>
<div><a href="{% url 'profile_page' 'create_route_for_customer' %}">Отправить посылку</a></div>
<div><a href="{% url 'static_page' 'for_movers' %}">Для отправителя</a></div>
<div><a href="{% url 'static_page' 'for_customers' %}">Для перевозчика</a></div>
</div>
@@ -48,7 +48,10 @@
</div>
</div>
<div class="fifth-column"><a href="#">Регистрация</a><a href="#">Войти</a></div>
<div class="fifth-column">
<a href="{% url "registration_page" %}">Регистрация</a>
<a href="{% url "login_profile" %}">Войти</a>
</div>
</div>
<div class="clear-both"></div>

View File

@@ -48,10 +48,13 @@
</div>
</div>
<div class="info_profile">
{% 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 %}
</div>
<div class="clear_both"></div>