diff --git a/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc b/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc index 4584a4d..8248d3a 100644 Binary files a/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc and b/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc differ diff --git a/SocialHelper/SocialHelper/settings.py b/SocialHelper/SocialHelper/settings.py index baa6bc0..fbc6b78 100644 --- a/SocialHelper/SocialHelper/settings.py +++ b/SocialHelper/SocialHelper/settings.py @@ -118,6 +118,7 @@ USE_L10N = True USE_TZ = True +X_FRAME_OPTIONS = 'SAMEORIGIN' # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.1/howto/static-files/ diff --git a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc index 613acf0..9d4d0b1 100644 Binary files a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc differ diff --git a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc index f17f72c..534ec63 100644 Binary files a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc differ 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))