wyswietlanie oceny i komentarzy

This commit is contained in:
Jędrzej Klepacki 2021-01-01 18:42:53 +01:00
parent fcf5db8bb8
commit 799b05b2a2
8 changed files with 254 additions and 7 deletions

View File

@ -1,5 +1,6 @@
from django.contrib import admin from django.contrib import admin
from .models import Product, Places from .models import Product, Places, Ocena
admin.site.register(Product) admin.site.register(Product)
admin.site.register(Places) admin.site.register(Places)
admin.site.register(Ocena)

View File

@ -47,17 +47,19 @@
<div class="col-lg-8 col-md-6"> <div class="col-lg-8 col-md-6">
<div class="c_product_text"> <div class="c_product_text">
<h1>{{ product.title }}</h1> <h1>{{ product.title }}</h1>
<h6><a href="user_profile/{{ product.user_iden }}">{{ product.user_iden }}</a></h6>
<h5>
{% if types.0.0 == product.type %} {% if types.0.0 == product.type %}
<h5>Potrzebuje Potrzebuje
{% else %} {% else %}
<h5>Oddam Oddam
{% endif %} {% endif %}
{% if types_o.0.0 == product.offer %} {% if types_o.0.0 == product.offer %}
Usługa</h5> Usługa
{% else %} {% else %}
Przedmiot</h5> Przedmiot
{% endif %} {% endif %}</h5>
<h6>Z miejscowości: <span>{{ product.place }}</span></h6> <h6>Z miejscowości: <span>{{ product.place }}</span></h6>
<p>{{ product.description }}</p> <p>{{ product.description }}</p>

View File

@ -0,0 +1,216 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
<body>
<!--================Categories Banner Area =================-->
<section class="solid_banner_area">
<div class="container">
<div class="solid_banner_inner">
<h3>Profil użytkownika</h3>
<h5>{{ name }}</h5>
<labe>Neutralne</label><br>
<label>Niepolecany<input type="range" id="volume" name="volume" min="0" max="100" value = "{{ ocena }}" disabled="True" color="Blue">Polecany</label>
</div>
</div>
</section>
<!--================End Categories Banner Area =================-->
<!--================Categories Product Area =================-->
<section class="categories_product_main p_80">
<div class="container">
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#1zakladka" role="tab" data-toggle="tab">Produkty</a></li>
<li><a href="#2zakladka" role="tab" data-toggle="tab">Oceny</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="1zakladka">
<div class="categories_main_inner">
<div class="row row_disable">
<div class="col-lg-9 float-md-right">
<div class="c_product_grid_details">
{% if all_product %}
{% for product in all_product %}
<div class="c_product_item">
<div class="row">
<div class="col-lg-4 col-md-6">
<div class="c_product_img">
<img class="img-fluid" src="{{ product.picture.url }}">
</div>
</div>
<div class="col-lg-8 col-md-6">
<div class="c_product_text">
<h1>{{ product.title }}</h1>
{% if types.0.0 == product.type %}
<h5>Potrzebuje
{% else %}
<h5>Oddam
{% endif %}
{% if types_o.0.0 == product.offer %}
Usługa</h5>
<a href="{{ product.id }}/delete_offer"><button type="button" class="btn btn-danger pull-right">Zakończ</button></a>
<a href="{{ product.id }}/edit_offer"><button type="button" class="btn btn-primary pull-right">Edytuj</button></a>
{% else %}
Przedmiot</h5>
<a href="{{ product.id }}/delete_offer"><button type="button" class="btn btn-danger pull-right">Zakończ</button></a>
<a href="{{ product.id }}/edit_offer"><button type="button" class="btn btn-primary pull-right">Edytuj</button></a>
{% endif %}
<h6>Z miejscowości: <span>{{ product.place }}</span></h6>
<p>{{ product.description }}</p>
</div>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p>No polls are available.</p>
{% endif %}
</div>
</div>
<form action="{% url 'filter' %}" method="post">
{% csrf_token %}
<input type="hidden" name="place" value="">
<input type="hidden" name="Oddam" value="">
<input type="hidden" name="Potrzebuje" value="">
</form>
</div>
</div>
</div>
<div class="tab-pane" id="2zakladka">
<div class="categories_main_inner">
<div class="row row_disable">
<div class="col-lg-9 float-md-right">
<div class="c_product_grid_details">
{% if all_oceny %}
{% for ocen_jed in all_oceny %}
<div class="c_product_item">
<div class="row">
{{ocen_jed.comm}}
{{ocen_jed.ocena_jedn}}
</div>
</div>
{% endfor %}
{% else %}
<p>No polls are available.</p>
{% endif %}
</div>
</div>
<form action="{% url 'filter' %}" method="post">
{% csrf_token %}
<input type="hidden" name="place" value="">
<input type="hidden" name="Oddam" value="">
<input type="hidden" name="Potrzebuje" value="">
</form>
</div>
</div>
</div>
</div></div>
</section>
<!--================End Categories Product Area =================-->
<!--================Footer Area =================-->
<footer class="footer_area">
<div class="container">
<div class="footer_widgets">
<div class="row">
<div class="col-lg-4 col-md-4 col-6">
<aside class="f_widget f_about_widget">
<img src="img/logo.png" alt="">
<p>Persuit is a Premium PSD Template. Best choice for your online store. Let purchase it to enjoy now</p>
<h6>Social:</h6>
<ul>
<li><a href="#"><i class="social_facebook"></i></a></li>
<li><a href="#"><i class="social_twitter"></i></a></li>
<li><a href="#"><i class="social_pinterest"></i></a></li>
<li><a href="#"><i class="social_instagram"></i></a></li>
<li><a href="#"><i class="social_youtube"></i></a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_info_widget">
<div class="f_w_title">
<h3>Information</h3>
</div>
<ul>
<li><a href="#">About us</a></li>
<li><a href="#">Delivery information</a></li>
<li><a href="#">Terms & Conditions</a></li>
<li><a href="#">Help Center</a></li>
<li><a href="#">Returns & Refunds</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_service_widget">
<div class="f_w_title">
<h3>Customer Service</h3>
</div>
<ul>
<li><a href="#">My account</a></li>
<li><a href="#">Ordr History</a></li>
<li><a href="#">Wish List</a></li>
<li><a href="#">Newsletter</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_extra_widget">
<div class="f_w_title">
<h3>Extras</h3>
</div>
<ul>
<li><a href="#">Brands</a></li>
<li><a href="#">Gift Vouchers</a></li>
<li><a href="#">Affiliates</a></li>
<li><a href="#">Specials</a></li>
</ul>
</aside>
</div>
<div class="col-lg-2 col-md-4 col-6">
<aside class="f_widget link_widget f_account_widget">
<div class="f_w_title">
<h3>My Account</h3>
</div>
<ul>
<li><a href="#">My account</a></li>
<li><a href="#">Ordr History</a></li>
<li><a href="#">Wish List</a></li>
<li><a href="#">Newsletter</a></li>
</ul>
</aside>
</div>
</div>
</div>
<div class="footer_copyright">
<h5>© <script>document.write(new Date().getFullYear());</script> <!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
Copyright &copy;<script>document.write(new Date().getFullYear());</script> All rights reserved | This template is made with <i class="fa fa-heart-o" aria-hidden="true"></i> by <a href="https://colorlib.com" target="_blank">Colorlib</a>. Downloaded from <a href="https://themeslab.org/" target="_blank">Themeslab</a>
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
</h5>
</div>
</div>
</footer>
<!--================End Footer Area =================-->
</body>
</html>
{% endblock %}

View File

@ -25,5 +25,6 @@ urlpatterns = [
path('logout_user', views.logout_user, name='logout_user'), path('logout_user', views.logout_user, name='logout_user'),
path('<int:user_id>/delete_user', views.delete_user, name='delete_user'), path('<int:user_id>/delete_user', views.delete_user, name='delete_user'),
path('edit_user', views.edit_user, name='edit_user'), path('edit_user', views.edit_user, name='edit_user'),
path('user_profile/<str:user_name>', views.user_profile, name='user_profile'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -7,7 +7,7 @@ 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 .models import Product, TYPE_T, TYPE_O, Places from .models import Product, TYPE_T, TYPE_O, Places, Ocena
from django.utils import timezone from django.utils import timezone
from datetime import timedelta from datetime import timedelta
@ -424,3 +424,30 @@ def logout_user(request):
auth.logout(request) auth.logout(request)
messages.success(request, 'Zostałeś wylogowany!') messages.success(request, 'Zostałeś wylogowany!')
return redirect( index) return redirect( index)
def user_profile(request, user_name):
User = get_user_model()
user_prof = User.objects.filter(username=user_name).first()
all_product = Product.objects.filter(active = True, user_iden = user_prof.id)
oceny = Ocena.objects.filter(user_iden = user_prof.id)
template = loader.get_template('homepage/user_profile.html')
types = TYPE_T
types_o = TYPE_O
ocena = 5
suma = 1
for ocena_j in oceny:
print(ocena)
ocena = ocena + ocena_j.ocena_jedn
suma = suma + 1
ocena = ocena / suma
ocena = ocena * 10
ocena = int (ocena)
context = {
'all_product': all_product,
'all_oceny': oceny,
'ocena': ocena,
'name': user_prof.email,
}
return HttpResponse(template.render(context, request))