From 9aad7d46fde570fb924a3171955108dd03045fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Klepacki?= Date: Fri, 8 Jan 2021 16:22:46 +0100 Subject: [PATCH] chat --- .../__pycache__/settings.cpython-37.pyc | Bin 2567 -> 2604 bytes SocialHelper/SocialHelper/settings.py | 1 + .../homepage/__pycache__/urls.cpython-37.pyc | Bin 1278 -> 1356 bytes .../homepage/__pycache__/views.cpython-37.pyc | Bin 12217 -> 13240 bytes .../homepage/templates/homepage/chating.html | 38 ++++++++++ .../templates/homepage/offer_page.html | 66 ++++++++++-------- SocialHelper/homepage/urls.py | 2 + SocialHelper/homepage/views.py | 50 ++++++++++++- 8 files changed, 123 insertions(+), 34 deletions(-) create mode 100644 SocialHelper/homepage/templates/homepage/chating.html diff --git a/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc b/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc index 4584a4dd4dd97b359b0be842e6d99d35197d2575..8248d3a435249d9adb2128336820b3eb4cddfab2 100644 GIT binary patch delta 174 zcmZn{StG*h#LLUY00cd0KjM`p@=7u>FizAsWtE~EC7#Nd#k4>ol`TbYAybqjoTm@u zNu?M>Ny9}97c!+YM#-cw1v6+GZPs91$i@@J73}Ei>L29k?&&xAB)bKp>|`d6e**jw z@oqstiFp5j5Kn)<;K~0vyahCY))#?@U)HWxF#$!BBRE|dGbYdDOyFi>VP#?DW8!0E GVFCahvMV0| delta 136 zcmZ1@(k{a5#LLUY00d{we2izB$ScY8hhd_|DYI0@ET#qGscb2_3z?!M;5J6CWcB69Bq9JnH9MkSCL(0^+5M zr*fpSWyz+p31rEosP;06GepU!s0A}C)cyMiY2o zB>1Yj>i4f-|G)pMn!m{Yd@+7F77M%JXW_~}vp;$0dOXFRxxVwIii?Mf+qG0C#a!IQ zBgIZ_M`j1~qdZpZ(z-L&^6PeVIP3Khv)bWCln!RBYEeG9A>97YDVW%n=-$9XUBgLZ=V z^8sil`5+&Hc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q5QwkdtzExjn2TD1;n9Z!}yeOznQEq8S z-r!8zj}m8!SwknkZazcnw@jT&+Is@|yxiPyd=>blJ!aX+rhS_Swd^HB#2(q@3wmAt zePS28EvF`bdXS_+&!*LvN`*2UPgR_{4L4n#wkKCI4DlM!T#r0e;@M(p=yJ)>q3;ma z#Z5UgHC!XV(q&17X)D>AVx6o+R%n&hx6vpegmHw2HgfJ%zvJ+mxJ99V3ufsMO1;a_ zop#14(UcQZyC;#jIYhFYXHX^3;P=v-Ox0coD!A^P4=Uh;-(mQf2Oxwj*D708DvUF( z+)>uu8?LIt-Bq{can>uYRqv|GJ+SB7aEYUzT(5eH9k{x#!MmP{n|rsp8s4ut4Ae~q zx0)Ehdez&&!25s!jK0f?xR1iXPc2@oc-H+D?*>~BaBYKC-4$guh~iyV?lKV~z9H@h zMFMbEnEN+KF=JB$IB2zPa~{0Is;brgs;la&_()HchhR;!BI{8e2IhXNqZ+U}tHFv= z2~>g=cSWseyzL#e8nU`7{`KxksN&jCUS;t2uKhX8G|H2>{O$C}PE0Xac>@MJXzDr2 zSLj&;#+|LLl`m#E{;_)#>7eOdhQE1`pKr=kYAUQcWxXHv#E`s@8rq-iY3^bv?zSNX zg(e-1X={6mrJ`3EYiOPkk)dSvQ}oH7d_&F!6N+vaJXI@`B+|f4DGljcn?WdT>2uQcQGo;M*(FcR zCDm^uzeV}Z!UrAjr=$eex9Rx16E@^e7Q1S;hT&r6p?t+)O{5UEBg`W#AS@zKzcYrj z;|SR3iVFxj!VLtx9mOjMRFAMYI01)ZG!zr^TH9Wbs$9_bgD+j?etBi7iz)Jr KrKCHqP5u`R|9+4F diff --git a/SocialHelper/homepage/templates/homepage/chating.html b/SocialHelper/homepage/templates/homepage/chating.html new file mode 100644 index 0000000..53e7db8 --- /dev/null +++ b/SocialHelper/homepage/templates/homepage/chating.html @@ -0,0 +1,38 @@ +{% load static %} +{% block content %} + + + + + + + + {% for messages in mess %} + {% if user_get_id == messages.author_id.id %} +

+ {{messages.author_id}}:
+ {{messages.text}} +

+ {% else %} +

+ {{messages.author_id}}:
+ {{messages.text}} +

+ {% endif %} + {% endfor %} +

{{ last_date.pub_date }}

+ + + +{% endblock %} diff --git a/SocialHelper/homepage/templates/homepage/offer_page.html b/SocialHelper/homepage/templates/homepage/offer_page.html index 10ad80e..5fe1b25 100644 --- a/SocialHelper/homepage/templates/homepage/offer_page.html +++ b/SocialHelper/homepage/templates/homepage/offer_page.html @@ -32,41 +32,45 @@
-

Wiadomości

- {% if mess == 0 %} - Brak Wiadomości - {% else %} -
+

Wiadomości

+
+ {% if user_get_id == offer.user_iden.id %} +
+
{% for user in email_list %} - +

+ {% endfor %} +
+
+
+ {% for user in email_list %} +
+ +
+ {% csrf_token %} + + + + + +
+
{% endfor %}
- - {% for user in user_list %} -
- {% for chat in mess %} - {% if user == chat.author_id.id or user == chat.sec_user_id %} - -

{{ chat.pub_date }}

-

{{ chat.author_id }}: {{ chat.text }}

- ----- - {% endif %} - {% endfor %} -
- {% csrf_token %} - - - - - - -
- -
- {% endfor %} - {% endif %} - + {% else %} +
+ +
+ {% csrf_token %} + + + + + +
+
+ {% endif %}
diff --git a/SocialHelper/homepage/urls.py b/SocialHelper/homepage/urls.py index 3ccaf77..148bcd4 100644 --- a/SocialHelper/homepage/urls.py +++ b/SocialHelper/homepage/urls.py @@ -9,8 +9,10 @@ urlpatterns = [ path('product', views.index_product, name='index_product'), path('offer', views.index_offer, name='index_offer'), path('all', views.index, name='index'), + path('offer_details/', views.offer, name='offer'), path('send_message', views.send_message, name='send_message'), + path('chating///', views.chating, name='chating'), path('', views.index, name='index'), path('contact', views.contact, name='contact'), diff --git a/SocialHelper/homepage/views.py b/SocialHelper/homepage/views.py index b68c7ce..e1048a4 100644 --- a/SocialHelper/homepage/views.py +++ b/SocialHelper/homepage/views.py @@ -7,7 +7,8 @@ from django.template import loader from django.contrib.auth import get_user_model from django.contrib import messages, auth from django.utils import timezone - +from django.views.decorators.clickjacking import xframe_options_exempt +from django.db.models import Q from .models import Product, TYPE_T, TYPE_O, Places, Ocena, chat from django.utils import timezone @@ -490,7 +491,9 @@ def add_comment(request, user_name): else: return redirect(login) + def offer(request, offer_id): + user_get_id = request.user.id offer = Product.objects.filter(id = offer_id, active = True).first() mess = 0 @@ -507,14 +510,18 @@ def offer(request, offer_id): mess = mess + 1 if mess == 2: - mess = 0 - user_list = 0 + mess = chat.objects.none() + user_list = chat.objects.none() + email_list = chat.objects.none() else: mess = chat_fst.union(chat_scd).order_by('pub_date') if offer.user_iden == request.user: user_list = chat.objects.values_list('author_id', flat=True).distinct('author_id').filter(product_id = offer_id, sec_user_id = request.user.id).exclude(author_id = request.user.id) User = get_user_model() email_list = User.objects.filter(id__in = user_list) + else: + user_list = chat.objects.none() + email_list = chat.objects.none() template = loader.get_template('homepage/offer_page.html') types = TYPE_T @@ -526,6 +533,7 @@ def offer(request, offer_id): 'mess': mess, 'user_list': user_list, 'email_list': email_list, + 'user_get_id': user_get_id, } return HttpResponse(template.render(context, request)) @@ -548,3 +556,39 @@ def send_message(request): return redirect(offer, product_id) else: return redirect(login) + +def chating(request, offer_id, au_id, ad_id): + scd_user_get_id = ad_id + User = get_user_model() + user_prof = User.objects.filter(id=au_id).first() + mess = 0 + user_get_id = request.user.id + if chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id ).exists(): + chat_fst = chat.objects.filter(product_id = offer_id, author_id=user_prof.id , sec_user_id = ad_id) + else: + chat_fst = chat.objects.none() + mess = mess + 1 + user_prof_2 = User.objects.filter(id=ad_id).first() + if chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id).exists(): + chat_scd = chat.objects.filter(product_id = offer_id, author_id = user_prof_2.id ,sec_user_id=au_id) + else: + chat_scd = chat.objects.none() + mess = mess + 1 + + if mess == 2: + mess = chat.objects.none() + user_list = chat.objects.none() + email_list = chat.objects.none() + else: + mess = chat_fst.union(chat_scd).order_by('pub_date') + + last_date = chat_fst.union(chat_scd).order_by('pub_date') + last_date = chat.objects.filter(Q(product_id = offer_id), Q(author_id=user_prof.id) | Q(author_id=user_prof_2.id), Q(sec_user_id=ad_id) | Q(sec_user_id=au_id)).order_by('pub_date').last() + context ={ + 'mess': mess, + 'user_get_id': user_get_id, + 'scd_user_get_id': scd_user_get_id, + 'last_date': last_date + } + template = loader.get_template('homepage/chating.html') + return HttpResponse(template.render(context, request))