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

@ -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,8 +442,10 @@ 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():
ocena = 0
suma = 0
for ocena_j in oceny: for ocena_j in oceny:
print(ocena) print(ocena)
ocena = ocena + ocena_j.ocena_jedn ocena = ocena + ocena_j.ocena_jedn
@ -450,6 +453,8 @@ def user_profile(request, user_name):
ocena = ocena / suma ocena = ocena / suma
ocena = ocena * 10 ocena = ocena * 10
ocena = int (ocena) 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):
if request.user.is_authenticated:
User = get_user_model() User = get_user_model()
user_prof = User.objects.filter(username=user_name).first() user_prof = User.objects.filter(email=user_name).first()
template = loader.get_template('homepage/add_comment.html') 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,
} }
template = loader.get_template('homepage/add_comment.html')
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
else:
return redirect(login)