Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -15,7 +15,7 @@ urlpatterns = [
|
||||
|
||||
path('my_routes/', my_routes_ajax, name='my_routes_ajax'),
|
||||
path('subscribe/', subscribe_ajax, name='subscribe_ajax'),
|
||||
path('new_msg_to_user/', new_msg_to_user_ajax, name='new_msg_to_user' ),
|
||||
path('chats/', chats_ajax, name='chats_ajax'),
|
||||
|
||||
path('support_tickets/', support_tickets_ajax, name='support_tickets_ajax'),
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ def subscribe_ajax(request):
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
def new_msg_to_user_ajax(request):
|
||||
def chats_ajax(request):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
Dict = {
|
||||
}
|
||||
|
||||
html = render_to_string('blocks/profile/b_new_msg_to_user.html', Dict, request=request)
|
||||
html = render_to_string('blocks/profile/b_chats.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
|
||||
@@ -9,6 +9,8 @@ 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('login/', login_View, name='login_profile'),
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,34 @@ def registration_View(request):
|
||||
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_receivers_for_user, get_msgs_for_chat_w_users
|
||||
|
||||
receivers = get_chat_receivers_for_user(request.user)
|
||||
|
||||
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,
|
||||
'cur_chat_msgs':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):
|
||||
|
||||
|
||||
@@ -1,4 +1,27 @@
|
||||
from .models import *
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
def get_msgs_for_chat_w_users(user1, user2):
|
||||
|
||||
msgs = Message.objects.filter(
|
||||
Q(sender=user1) | Q(receiver=user1),
|
||||
Q(sender=user2) | Q(receiver=user2),
|
||||
group=None
|
||||
)
|
||||
return msgs
|
||||
|
||||
def get_chat_receivers_for_user(user):
|
||||
receivers = Message.objects.filter(
|
||||
Q(sender=user) | Q(receiver=user),
|
||||
group=None
|
||||
).order_by('-modifiedDT').values('sender', 'receiver')
|
||||
|
||||
receivers_list = []
|
||||
receivers_list.extend([item['sender'] for item in receivers if item['sender'] != user])
|
||||
receivers_list.extend([item['receiver'] for item in receivers if item['receiver'] != user])
|
||||
|
||||
return receivers_list
|
||||
|
||||
def get_messages_for_ticket(ticket):
|
||||
return ticket.rel_messages_for_group.filter(enable=True).order_by('-modifiedDT')
|
||||
|
||||
@@ -17,10 +17,12 @@ def get_msg_side(cur_user, ticket, msg):
|
||||
return 'right'
|
||||
else:
|
||||
return 'left'
|
||||
else:
|
||||
elif ticket:
|
||||
if ticket.owner == cur_user:
|
||||
return 'right'
|
||||
else:
|
||||
return 'left'
|
||||
else:
|
||||
return 'right'
|
||||
|
||||
# return 'left'
|
||||
@@ -31,20 +31,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="info_profile">
|
||||
<h1>Добро пожаловать: <span>{{ user.first_name }} {{ user.last_name }}</span> <span>({{ user.username }})</span></h1>
|
||||
<div class="profile_prof"><img class="avatar_profile" src="{{ user.user_profile.avatar }}" alt="">
|
||||
<div>
|
||||
<div>Статус: {{ user.user_profile.get_account_type_display }}</div>
|
||||
{# <div>#}
|
||||
{# <select name="" id="">#}
|
||||
{# <option>Перевозчик</option>#}
|
||||
{# <option>Отправитель</option>#}
|
||||
{# </select></div>#}
|
||||
</div>
|
||||
</div>
|
||||
<div>Если хотите отправить посылку - зарегистрируйтесь, как отправитель</div>
|
||||
<div>Если у Вас возникнут вопросы Вы можете связаться с нами: <a href="mailto:support@twb.com">support@twb.com</a></div>
|
||||
<div>У Вас <a href="#">три</a> новых сообщения. <a href="#">Посмотреть</a></div>
|
||||
<div>Хотите получать уведомление о появлении посылок? <a href="#">Заполните форму</a></div>
|
||||
{% if not page %}
|
||||
{% include "blocks/profile/b_profile_first_page.html" %}
|
||||
{% elif page == 'chat' %}
|
||||
{% include "blocks/profile/b_chats.html" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
15
templates/blocks/profile/b_profile_first_page.html
Normal file
15
templates/blocks/profile/b_profile_first_page.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<h1>Добро пожаловать: <span>{{ user.first_name }} {{ user.last_name }}</span> <span>({{ user.username }})</span></h1>
|
||||
<div class="profile_prof"><img class="avatar_profile" src="{{ user.user_profile.avatar }}" alt="">
|
||||
<div>
|
||||
<div>Статус: {{ user.user_profile.get_account_type_display }}</div>
|
||||
{# <div>#}
|
||||
{# <select name="" id="">#}
|
||||
{# <option>Перевозчик</option>#}
|
||||
{# <option>Отправитель</option>#}
|
||||
{# </select></div>#}
|
||||
</div>
|
||||
</div>
|
||||
<div>Если хотите отправить посылку - зарегистрируйтесь, как отправитель</div>
|
||||
<div>Если у Вас возникнут вопросы Вы можете связаться с нами: <a href="mailto:support@twb.com">support@twb.com</a></div>
|
||||
<div>У Вас <a href="#">три</a> новых сообщения. <a href="#">Посмотреть</a></div>
|
||||
<div>Хотите получать уведомление о появлении посылок? <a href="#">Заполните форму</a></div>
|
||||
Reference in New Issue
Block a user