From e5c92127ea3c7a609f2e28c375ebc87f6e31cc34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Klepacki?= Date: Sun, 3 Jan 2021 12:26:35 +0100 Subject: [PATCH] dodawanie komentarzy --- .../homepage/__pycache__/views.cpython-37.pyc | Bin 10467 -> 10850 bytes .../__pycache__/0001_initial.cpython-37.pyc | Bin 1356 -> 1623 bytes .../templates/homepage/add_comment.html | 2 +- .../homepage/templates/homepage/index.html | 2 +- SocialHelper/homepage/views.py | 55 ++++++++++++------ 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc index 078b274f2ccec1b4c7d8b35cf2add24443348281..d6c3c7504e3a6913dce74ff980b5cf8c2d614c3a 100644 GIT binary patch delta 1654 zcmZvcU2IfE6oBuU`?L3NcW-yMp_EoCyDeRjVrWJ2CxKD~LEAuEstu&sbeh1n-7T|M zAkADFQ<0!FHBKLS*nLwTOw96P(kEl$lSU0M_DxMlcrd96?|RN{11RohzBzNw{G6G4 z&iUia?_;UKWYX2}_x+cDO|2gNI#qL1NgR^y7`ED=T6OcrXCPd4&+T8*$`*HbYLP8< z?#=2Vlu%|U`zsKEG4eiJa9qBFuXcD9=J*i7Wn$nU9Y4gk-C-OsA zvbraIsWsR#jB3T~@K_N<8$QEg_F{E@W}&2RTS@hk*Y8hySF3Z?N>~z?N{ab~ENu7_ zTbdA6VbKxo>blwEZ8$h_YOXq6no}eG5G2)_-^;|H`oIT|u#-Q1q>|>@lio2*%x)n~StLbZSOl_toVOX6G4kW}N+Qdn9GdOOZLh-Kp zIk*6))Pa^yyfHGR2;=IzmgDeS)6J|xahNo_2)hZd6OI#(5Z)r3Ae>a+W?#Uq{>;7! zZ>xQ|nR6qgrl{Fk6mNZ&h6dpb;WUB#6{CbBgck|%mh>Lt4Z^#G*uio2AXhBJPVFUS z2jLuHg76+;`;z^wz3{MkzV)=(8h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D58wSUpCH{iqL^KN=LHCq+r`_UYc91RqJ!%BA>zEOV1{^c9=0%W)m#UUS>WsSm80yeG7m9 diff --git a/SocialHelper/homepage/migrations/__pycache__/0001_initial.cpython-37.pyc b/SocialHelper/homepage/migrations/__pycache__/0001_initial.cpython-37.pyc index f887f0fdb5dfe56d7f2710f1d55a8ee9c7cddf10..6af8b47f2054961745ad087140e726bfdbfe8b49 100644 GIT binary patch delta 755 zcmZ`#zi-n(6wcX~A9fSh`PnutO$!ui34z4GR#7!lR0hCOgODnr$oO4cTaJyK3ltV4 zMx+dp#m>UO!pO?Rh7cRlO{`3a|A2Q%2vsF~^67ow``-87y)XLrqH$0v=^6Zfz5Cr8 zYZK$mQWeoY{=>Iq@?meM02=6HrLVve(}N-`u%|+CtS}mAP?~(Jzcesi0s_lpf?{)u z=p2<18JHtbf$CVrd<~gpW(MV;0(EFi8>}E#g;iMd6l~L+a_duW11_B5Hjz6s2(%=& zv1DsL>GnCn#X0_)zl6BP>OmvWgOy;F<$^q1mhHUa;!QjFrbk!K8C^xZ_HPC7e5H z$m1uX@GK5`QilQ>IRhqgeV>Ie6nQ&|VdQd=b6oB}WfnV&bwJ91*wK4G&p4Buyx zLu`>8rZzol-@>qPX7qd9KIyw4MtB7~p<9$Ex``#V*GW4t)>)EU>;4-h@PF|I+ahJ)Xs^JMg zg>G-lv_p>14)*;i8kPIO)XwDz@^N>Lu_F19NMxpqJ zjUhA9QG#;cQyJ*-fu8uO9}d9eKSLFDfsXn`U-!rS5>5FkOeLe-3`}>3D;||$W?!&o zV{ONCnH_mS>mXM5SOD#M#2r%0r|f#*Oi^OXEH1O&) zWCngmtOSljnMGI;Ra?by7(U&!T^ms;F=%`2l0wr9qF9N%s6pT75M#C9t~c$AlLl?M z(J6nFR!y8Qx9ld3Q;tU)5bjzPUY2ipPu^0r19}nh4|%~1&gl2s!+U|%a2%`g4P`%9 o#WYQ1$&h7{kOF^DOpPhYbsAgbugYd+IWZ?>(Ds|H@ugJt3#{CO$N&HU diff --git a/SocialHelper/homepage/templates/homepage/add_comment.html b/SocialHelper/homepage/templates/homepage/add_comment.html index 52b627d..925e1a8 100644 --- a/SocialHelper/homepage/templates/homepage/add_comment.html +++ b/SocialHelper/homepage/templates/homepage/add_comment.html @@ -17,7 +17,7 @@ -
+ {% csrf_token %} {{ form.media }} {{ form.as_p }} diff --git a/SocialHelper/homepage/templates/homepage/index.html b/SocialHelper/homepage/templates/homepage/index.html index 2e7a5e6..4349c0f 100644 --- a/SocialHelper/homepage/templates/homepage/index.html +++ b/SocialHelper/homepage/templates/homepage/index.html @@ -159,7 +159,7 @@

Wolontariat

    - {% if wol_local%} + {% if wol_local %} {% else %} diff --git a/SocialHelper/homepage/views.py b/SocialHelper/homepage/views.py index fbb5d66..854a730 100644 --- a/SocialHelper/homepage/views.py +++ b/SocialHelper/homepage/views.py @@ -124,7 +124,7 @@ def filter(request): usluga_local = request.POST['usluga'] przedmiot_local = request.POST['przedmiot'] wol_local = request.POST['wolontariat'] - + if place_local != "": @@ -145,7 +145,7 @@ def filter(request): if usluga_local != "on" and przedmiot_local == "on": zmienna = 2 all_product = all_product.filter(type=zmienna) - + if wol_local == "on": all_product = all_product.filter(Wolontatriat=True) @@ -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)