diff --git a/SocialHelper/homepage/__pycache__/admin.cpython-37.pyc b/SocialHelper/homepage/__pycache__/admin.cpython-37.pyc index 9b3b46f..632d36a 100644 Binary files a/SocialHelper/homepage/__pycache__/admin.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/admin.cpython-37.pyc differ diff --git a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc index 63d74f4..613acf0 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 753de09..f17f72c 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/index.html b/SocialHelper/homepage/templates/homepage/index.html index f50936d..27c9c2b 100644 --- a/SocialHelper/homepage/templates/homepage/index.html +++ b/SocialHelper/homepage/templates/homepage/index.html @@ -51,18 +51,18 @@
-

{{ product.title }}

-
{{ product.user_iden }}
+

{{ product.title }}

+
{{ product.user_iden }}
{% if types.0.0 == product.type %} - Need + Potrzebuje {% else %} - Give + Oddam {% endif %} {% if types_o.0.0 == product.offer %} - Service + Usługe {% else %} - Items + Przedmiot {% endif %}
Location: {{ product.place }}
diff --git a/SocialHelper/homepage/templates/homepage/offer_page.html b/SocialHelper/homepage/templates/homepage/offer_page.html new file mode 100644 index 0000000..10ad80e --- /dev/null +++ b/SocialHelper/homepage/templates/homepage/offer_page.html @@ -0,0 +1,195 @@ +{% extends 'base.html' %} +{% load static %} +{% block content %} + + + + + + +
+
+
+ {% if offer.Wolontatriat %} +
Ogłoszenie Wolontariackie
+ {% endif %} +

{{ offer.title }}

+
{{ offer.user_iden }}


+ + {{ offer.create_date }} + {% if types.0.0 == offer.type %} + Potrzebuje + {% else %} + Oddam + {% endif %} + {% if types_o.0.0 == offer.offer %} + Usługe + {% else %} + Przedmiot + {% endif %} + {{ offer.description }} + {{ offer.place }} +
+ +
+

Wiadomości

+ {% if mess == 0 %} + Brak Wiadomości + {% else %} + +
+ {% for user in email_list %} + + {% 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 %} + +
+ +
+
+ + + + + + +
+
+ +
+
+ + + + + + + +{% endblock %} diff --git a/SocialHelper/homepage/urls.py b/SocialHelper/homepage/urls.py index a127bc7..3ccaf77 100644 --- a/SocialHelper/homepage/urls.py +++ b/SocialHelper/homepage/urls.py @@ -9,6 +9,8 @@ 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('', views.index, name='index'), path('contact', views.contact, name='contact'), diff --git a/SocialHelper/homepage/views.py b/SocialHelper/homepage/views.py index 277fa3a..b68c7ce 100644 --- a/SocialHelper/homepage/views.py +++ b/SocialHelper/homepage/views.py @@ -6,6 +6,7 @@ from django.urls import reverse 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 .models import Product, TYPE_T, TYPE_O, Places, Ocena, chat @@ -488,3 +489,62 @@ def add_comment(request, user_name): return HttpResponse(template.render(context, request)) else: return redirect(login) + +def offer(request, offer_id): + offer = Product.objects.filter(id = offer_id, active = True).first() + mess = 0 + + if chat.objects.filter(product_id = offer_id, author_id=request.user.id).exists(): + chat_fst = chat.objects.filter(product_id = offer_id, author_id=request.user.id) + else: + chat_fst = chat.objects.none() + mess = mess + 1 + + if chat.objects.filter(product_id = offer_id, sec_user_id=request.user.id).exists(): + chat_scd = chat.objects.filter(product_id = offer_id, sec_user_id=request.user.id) + else: + chat_scd = chat.objects.none() + mess = mess + 1 + + if mess == 2: + mess = 0 + user_list = 0 + 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) + + template = loader.get_template('homepage/offer_page.html') + types = TYPE_T + types_o = TYPE_O + context = { + 'offer': offer, + 'types': types, + 'types_o': types_o, + 'mess': mess, + 'user_list': user_list, + 'email_list': email_list, + } + return HttpResponse(template.render(context, request)) + +def send_message(request): + if request.user.is_authenticated: + if request.method == 'POST': + author_id = request.POST['author_id'] + sec_user_id = request.POST['sec_user_id'] + product_id = request.POST['product_id'] + text = request.POST['text'] + User = get_user_model() + massage = chat( + product_id = Product.objects.filter(id=product_id).first(), + author_id = User.objects.filter(id=author_id).first(), + sec_user_id = sec_user_id, + text = text, + pub_date = timezone.now(), + ) + massage.save() + return redirect(offer, product_id) + else: + return redirect(login)