From 5d72299c24361f8c1ef930a46e5c12c3bf7869a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Klepacki?= Date: Sun, 6 Dec 2020 16:13:09 +0100 Subject: [PATCH] filtrowanie --- .../__pycache__/settings.cpython-37.pyc | Bin 2351 -> 2512 bytes .../homepage/__pycache__/urls.cpython-37.pyc | Bin 269 -> 298 bytes .../homepage/__pycache__/views.cpython-37.pyc | Bin 633 -> 1381 bytes .../homepage/templates/homepage/index.html | 31 +++++++++++-- SocialHelper/homepage/urls.py | 1 + SocialHelper/homepage/views.py | 42 +++++++++++++++++- 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc b/SocialHelper/SocialHelper/__pycache__/settings.cpython-37.pyc index 954a6f7fe75cc697d6c963ca54578f970f393f0a..dcd951fa98684826e13b7c63642bd7dfd590270b 100644 GIT binary patch delta 251 zcmZ24bU~QciI)E8^08>Sw^uHmn4>CCRcIjLm2v1!om5;nTa_bsW}Cy zMNrWw*4)&T%)}~oeK4)BDKoi<{a*k}R(@vQE$-kD#}H5F_#l7(kXu|(PH2$NEddDI z&C|yS=$t@hdj7gI(al~@)F|sfTu<$Vg E065A_ng9R* delta 90 zcmca0yk3aciI(0w`K)9pQU)4Oq&!)c)0Z)7ayDly043cR2><{9 diff --git a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc index d5f7a60b0457d334b57b3b3e5985ee4c27ff7a66..aac91339febabf3245795d00b94611ab97741e1c 100644 GIT binary patch delta 132 zcmeBWTE(R9#LLUY00e2z&crVT(vLwL7+?c39DumkW}>>LL@Hwndn$7lYYKY`TQ74u zQxsbYM=*mX=fo%-?pthWnK>n?MShy>6FU{9i#UL~ZgH0u{9B=>t delta 103 zcmZ3*)XSvq#LLUY00g^rPR17l>Bk@r46p(j4nSP2H&I=aE1fZlHHAHxL6c)*h7Plz qCfmgMiek68ON(*}5=%-_i}H$BG8BOfE8?1X+m(X_$l_t-VFm!|_Y~v+ diff --git a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc index 159b7bf8a981c9d4efa7e480bc97aa0654d7cbdf..2558a532828f415bd84b65352be3173f24d966f5 100644 GIT binary patch literal 1381 zcmZvcJCEEp5P(Tal(Z}D-5P$yNUC%Kg0o?`3IZc=V8Ch42j4Xo4p_({bGvKm;Stx5 zgSN6;cPRtJF8we31MEM**44ExQ)Nb4FYW-7;BbaRQXI}l-J49t49mY?Kg~V|jC~>F zTM?-Ij;%dLp_t-^l|196$OI=_7_am*zm%EmZO;T{n1#LWo2VRRBh;k|%(#rRxJoAwEw$(|JUQg$A2Cl*2N+>5434CTr|Fgd;EN%U$lG8D<}KF>16E> zC>W3UnEOK&f)6zka07kYY*1|5Yx3o?R_KV_s&8#EkAYUsUb)Iq?r39v(T_Q{m)8 z;=zp%wj@A|7n5@M2|Fk1>Wm&MBJUGTKtQLm&oX=`w`tr11ea)W@Ylj1D?LAOxgROD zo!1I}M5AX2j{%FyodAytCM=Ko!4NCm2H9Uphw-s8{ZuN7{jq8`nJO> zFf9;cZg(?r`xN?T6qL2nIE7FgUJ()6pZQ!IeMA(Di+;leE2HnyAEl*Rner)5uuerZ F{U1kQN|XQq literal 633 zcmY*Wy>1jS5cbdh-Q_|;@)X+~5)~kX5K*MiL=l%JtCLR4dUQYXt`~a_60}!^cc7t2 zN*;uQS8$suuRz6kb%|iC8GrM6ni8dvj+>;QN3!k1@qt+GrPWjkNXjVNcV&S z;~5|Fh-X5O+e2bb^I@^CR%J6cW4ACCt2Me_pWoTi3;L8^w%^+_k3#!dliDcIu78Vu e)c)dL^grQ%n)&QC)vh(X2|wq;)FU3&zW56STc0KX diff --git a/SocialHelper/homepage/templates/homepage/index.html b/SocialHelper/homepage/templates/homepage/index.html index 808f59d..bc41fae 100644 --- a/SocialHelper/homepage/templates/homepage/index.html +++ b/SocialHelper/homepage/templates/homepage/index.html @@ -119,6 +119,14 @@ + +
+ {% csrf_token %} + + + + +
@@ -137,16 +149,27 @@

Typ

    - + {% if oddam_local %} + + {% else %} + + {% endif %}

    - + {% if potrzebuje_local %} + + {% else %} + + {% endif %}
- +
+
+ + diff --git a/SocialHelper/homepage/urls.py b/SocialHelper/homepage/urls.py index 6e21aeb..44852e0 100644 --- a/SocialHelper/homepage/urls.py +++ b/SocialHelper/homepage/urls.py @@ -3,4 +3,5 @@ from . import views urlpatterns = [ path('', views.index, name='index'), + path('filter', views.filter, name='filter'), ] diff --git a/SocialHelper/homepage/views.py b/SocialHelper/homepage/views.py index b7c498d..bc69e6e 100644 --- a/SocialHelper/homepage/views.py +++ b/SocialHelper/homepage/views.py @@ -1,15 +1,53 @@ -from django.shortcuts import render -from django.http import HttpResponse +from django.shortcuts import get_object_or_404, render +from django.http import HttpResponse, HttpResponseRedirect +from django.urls import reverse from django.template import loader from .models import Product, TYPE_T def index(request): all_product = Product.objects.all template = loader.get_template('homepage/index.html') + types = TYPE_T + place_local = "" + oddam_local = "" + potrzebuje_local = "" + context = { + 'all_product': all_product, + 'types': types, + 'place_local': place_local, + 'oddam_local': oddam_local, + 'potrzebuje_local': potrzebuje_local, + } + return HttpResponse(template.render(context, request)) + +def filter(request): + + all_product = Product.objects.filter(create_date__contains = "2") + template = loader.get_template('homepage/index.html') + if request.method == 'POST': + place_local = request.POST['place'] + oddam_local = request.POST['Oddam'] + potrzebuje_local = request.POST['Potrzebuje'] + + if place_local != "": + all_product = all_product.filter(place=place_local) + + if oddam_local == "on" and potrzebuje_local != "on": + zmienna = 2 + all_product = all_product.filter(type=zmienna) + + if oddam_local != "on" and potrzebuje_local == "on": + zmienna = 1 + all_product = all_product.filter(type=zmienna) + + types = TYPE_T print(types) context = { 'all_product': all_product, 'types': types, + 'place_local': place_local, + 'oddam_local': oddam_local, + 'potrzebuje_local': potrzebuje_local, } return HttpResponse(template.render(context, request))