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 =================-->
<!--================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 %}
{{ form.media }}
{{ form.as_p }}

View File

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

View File

@ -162,6 +162,7 @@ def filter(request):
'potrzebuje_local': potrzebuje_local,
'usluga_local': usluga_local,
'przedmiot_local': przedmiot_local,
'wol_local': wol_local,
}
return HttpResponse(template.render(context, request))
@ -441,15 +442,19 @@ def user_profile(request, user_name):
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)
if Ocena.objects.filter(user_iden = user_prof.id).exists():
ocena = 0
suma = 0
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)
else:
ocena = 5
context = {
'all_product': all_product,
'all_oceny': oceny,
@ -459,12 +464,26 @@ def user_profile(request, user_name):
return HttpResponse(template.render(context, request))
def add_comment(request, user_name):
User = get_user_model()
user_prof = User.objects.filter(username=user_name).first()
template = loader.get_template('homepage/add_comment.html')
if request.user.is_authenticated:
User = get_user_model()
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 = {
'user_name': user_name,
context = {
'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)