dodawanie komentarzy

This commit is contained in:
Jędrzej Klepacki 2021-01-03 12:26:35 +01:00
parent b2f2870fbe
commit e5c92127ea
5 changed files with 39 additions and 20 deletions

View File

@ -17,7 +17,7 @@
<!--================End Categories Banner Area =================--> <!--================End Categories Banner Area =================-->
<!--================Register Area =================--> <!--================Register Area =================-->
<form action="{% url 'login' %}" method="POST" enctype="multipart/form-data"> <form action="{% url 'add_comment' user_name %}" method="POST" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form.media }} {{ form.media }}
{{ form.as_p }} {{ form.as_p }}

View File

@ -159,7 +159,7 @@
<h3>Wolontariat</h3> <h3>Wolontariat</h3>
</div> </div>
<ul> <ul>
{% if wol_local%} {% if wol_local %}
<input type="checkbox" id="wolontariat" name="wolontariat" Checked> <input type="checkbox" id="wolontariat" name="wolontariat" Checked>
{% else %} {% else %}
<input type="checkbox" id="wolontariat" name="wolontariat" > <input type="checkbox" id="wolontariat" name="wolontariat" >

View File

@ -124,7 +124,7 @@ def filter(request):
usluga_local = request.POST['usluga'] usluga_local = request.POST['usluga']
przedmiot_local = request.POST['przedmiot'] przedmiot_local = request.POST['przedmiot']
wol_local = request.POST['wolontariat'] wol_local = request.POST['wolontariat']
if place_local != "": if place_local != "":
@ -145,7 +145,7 @@ def filter(request):
if usluga_local != "on" and przedmiot_local == "on": if usluga_local != "on" and przedmiot_local == "on":
zmienna = 2 zmienna = 2
all_product = all_product.filter(type=zmienna) all_product = all_product.filter(type=zmienna)
if wol_local == "on": if wol_local == "on":
all_product = all_product.filter(Wolontatriat=True) all_product = all_product.filter(Wolontatriat=True)
@ -162,6 +162,7 @@ def filter(request):
'potrzebuje_local': potrzebuje_local, 'potrzebuje_local': potrzebuje_local,
'usluga_local': usluga_local, 'usluga_local': usluga_local,
'przedmiot_local': przedmiot_local, 'przedmiot_local': przedmiot_local,
'wol_local': wol_local,
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
@ -441,15 +442,19 @@ def user_profile(request, user_name):
types = TYPE_T types = TYPE_T
types_o = TYPE_O types_o = TYPE_O
ocena = 5
suma = 1 if Ocena.objects.filter(user_iden = user_prof.id).exists():
for ocena_j in oceny: ocena = 0
print(ocena) suma = 0
ocena = ocena + ocena_j.ocena_jedn for ocena_j in oceny:
suma = suma + 1 print(ocena)
ocena = ocena / suma ocena = ocena + ocena_j.ocena_jedn
ocena = ocena * 10 suma = suma + 1
ocena = int (ocena) ocena = ocena / suma
ocena = ocena * 10
ocena = int (ocena)
else:
ocena = 5
context = { context = {
'all_product': all_product, 'all_product': all_product,
'all_oceny': oceny, 'all_oceny': oceny,
@ -459,12 +464,26 @@ def user_profile(request, user_name):
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
def add_comment(request, user_name): def add_comment(request, user_name):
User = get_user_model() if request.user.is_authenticated:
user_prof = User.objects.filter(username=user_name).first() User = get_user_model()
template = loader.get_template('homepage/add_comment.html') user_prof = User.objects.filter(email=user_name).first()
if request.method == 'POST':
volume_local = request.POST['volume']
script_local = request.POST['script']
instant = Ocena(
user_iden = user_prof,
comm = script_local,
ocena_jedn = int(volume_local)*2,
)
instant.save()
messages.success(request, 'Dodano komentarz')
return redirect(user_profile, user_name)
context = { context = {
'user_name': user_name, 'user_name': user_name,
} }
return HttpResponse(template.render(context, request)) template = loader.get_template('homepage/add_comment.html')
return HttpResponse(template.render(context, request))
else:
return redirect(login)