This commit is contained in:
Jędrzej Klepacki 2021-01-08 16:22:46 +01:00
parent 95db90b813
commit 9aad7d46fd
8 changed files with 123 additions and 34 deletions

View File

@ -118,6 +118,7 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
X_FRAME_OPTIONS = 'SAMEORIGIN'
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/ # https://docs.djangoproject.com/en/2.1/howto/static-files/

View File

@ -0,0 +1,38 @@
{% load static %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
<style>
.squareblue{
background-color: #0084ff;
border-radius: 10px / 10px;
}
.greclass{
background-color: #e4e6eb;
border-radius: 10px / 10px;
}
</style>
<head>
<meta http-equiv="refresh" content="5">
</head>
<body style="background-color:white;">
{% for messages in mess %}
{% if user_get_id == messages.author_id.id %}
<p style="text-align:right;" class="squareblue">
{{messages.author_id}}:<br>
{{messages.text}}
</p>
{% else %}
<p style="text-align:left;" class="greclass">
{{messages.author_id}}:<br>
{{messages.text}}
</p>
{% endif %}
{% endfor %}
<p style="text-align:right;"><span style="font-size:10px">{{ last_date.pub_date }}</span></p>
</body>
</html>
{% endblock %}

View File

@ -32,41 +32,45 @@
</div> </div>
<div class="solid_banner_inner"> <div class="solid_banner_inner">
<h3>Wiadomości</h3>
{% if mess == 0 %}
Brak Wiadomości
{% else %}
<h3>Wiadomości</h3>
<div class="row">
{% if user_get_id == offer.user_iden.id %}
<div class="col-lg-4 col-md-6">
<div class="tab"> <div class="tab">
{% for user in email_list %} {% for user in email_list %}
<button class="tablinks" onclick="openCity(event, '{{ user.id }}')">{{ user.email }}</button> <button onclick="openCity(event, '{{ user.id }}')" width="200">{{ user.email }}</button><p></p>
{% endfor %} {% endfor %}
</div> </div>
</div>
{% for user in user_list %} <div class="col-lg-8 col-md-6">
<div id="{{ user }}" class="tabcontent"> {% for user in email_list %}
{% for chat in mess %} <div id="{{ user.id }}" class="tabcontent">
{% if user == chat.author_id.id or user == chat.sec_user_id %} <iframe src="/homepage/chating/{{offer.id}}/{{offer.user_iden.id}}/{{user.id}}" width="770", height="500"></iframe>
<p>{{ chat.pub_date }}</p>
<p>{{ chat.author_id }}: {{ chat.text }}</p>
-----
{% endif %}
{% endfor %}
<form action="{% url 'send_message' %}" method="post"> <form action="{% url 'send_message' %}" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="author_id" value="{{ offer.user_iden.id }}"> <input type="hidden" name="author_id" value="{{ offer.user_iden.id }}">
<input type="hidden" name="sec_user_id" value="{{ user }}"> <input type="hidden" name="sec_user_id" value="{{ user.id }}">
<input type="hidden" name="product_id" value="{{ offer.id }}"> <input type="hidden" name="product_id" value="{{ offer.id }}">
<textarea class="form-control" id="order" rows="3" name="text", placeholder="Napisz Wiadomość"></textarea> <textarea class="form-control" id="order" rows="3" name="text", placeholder="Napisz Wiadomość"></textarea>
<input type="submit" class="btn btn-primary update_btn" value="Wyślij Wiadomość"> <input type="submit" class="btn btn-primary update_btn" value="Wyślij Wiadomość">
</form> </form>
</div> </div>
{% endfor %} {% endfor %}
</div>
{% else %}
<div class="col-lg-8 col-md-6">
<iframe src="/homepage/chating/{{offer.id}}/{{user_get_id}}/{{offer.user_iden.id}}" width="770", height="500"></iframe>
<form action="{% url 'send_message' %}" method="post">
{% csrf_token %}
<input type="hidden" name="author_id" value="{{user_get_id}}">
<input type="hidden" name="sec_user_id" value="{{offer.user_iden.id}}">
<input type="hidden" name="product_id" value="{{ offer.id }}">
<textarea class="form-control" id="order" rows="3" name="text", placeholder="Napisz Wiadomość"></textarea>
<input type="submit" class="btn btn-primary update_btn" value="Wyślij Wiadomość">
</form>
</div>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -9,8 +9,10 @@ urlpatterns = [
path('product', views.index_product, name='index_product'), path('product', views.index_product, name='index_product'),
path('offer', views.index_offer, name='index_offer'), path('offer', views.index_offer, name='index_offer'),
path('all', views.index, name='index'), path('all', views.index, name='index'),
path('offer_details/<int:offer_id>', views.offer, name='offer'), path('offer_details/<int:offer_id>', views.offer, name='offer'),
path('send_message', views.send_message, name='send_message'), path('send_message', views.send_message, name='send_message'),
path('chating/<int:offer_id>/<int:au_id>/<int:ad_id>', views.chating, name='chating'),
path('', views.index, name='index'), path('', views.index, name='index'),
path('contact', views.contact, name='contact'), path('contact', views.contact, name='contact'),

View File

@ -7,7 +7,8 @@ from django.template import loader
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib import messages, auth from django.contrib import messages, auth
from django.utils import timezone 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 .models import Product, TYPE_T, TYPE_O, Places, Ocena, chat
from django.utils import timezone from django.utils import timezone
@ -490,7 +491,9 @@ def add_comment(request, user_name):
else: else:
return redirect(login) return redirect(login)
def offer(request, offer_id): def offer(request, offer_id):
user_get_id = request.user.id
offer = Product.objects.filter(id = offer_id, active = True).first() offer = Product.objects.filter(id = offer_id, active = True).first()
mess = 0 mess = 0
@ -507,14 +510,18 @@ def offer(request, offer_id):
mess = mess + 1 mess = mess + 1
if mess == 2: if mess == 2:
mess = 0 mess = chat.objects.none()
user_list = 0 user_list = chat.objects.none()
email_list = chat.objects.none()
else: else:
mess = chat_fst.union(chat_scd).order_by('pub_date') mess = chat_fst.union(chat_scd).order_by('pub_date')
if offer.user_iden == request.user: 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_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() User = get_user_model()
email_list = User.objects.filter(id__in = user_list) 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') template = loader.get_template('homepage/offer_page.html')
types = TYPE_T types = TYPE_T
@ -526,6 +533,7 @@ def offer(request, offer_id):
'mess': mess, 'mess': mess,
'user_list': user_list, 'user_list': user_list,
'email_list': email_list, 'email_list': email_list,
'user_get_id': user_get_id,
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
@ -548,3 +556,39 @@ def send_message(request):
return redirect(offer, product_id) return redirect(offer, product_id)
else: else:
return redirect(login) 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))