From f6c4cfbf7d4b8bdae0e8821896c8ed435e0025be Mon Sep 17 00:00:00 2001 From: dinesh Date: Mon, 29 Apr 2024 11:03:27 +0530 Subject: [PATCH] added rest-api tried --- main/__pycache__/urls.cpython-312.pyc | Bin 1372 -> 1462 bytes main/__pycache__/views.cpython-312.pyc | Bin 10815 -> 11261 bytes main/urls.py | 4 ++- main/views.py | 8 +++++ static/js/description.js | 10 +++++-- static/js/index.js | 8 +++++ static/styles.css | 39 +++++++++++++++++++++++++ templates/auction.html | 16 ++++++++-- templates/base.html | 4 ++- templates/upload.html | 8 ++--- 10 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 static/js/index.js diff --git a/main/__pycache__/urls.cpython-312.pyc b/main/__pycache__/urls.cpython-312.pyc index f8216195c14271c115fde70bc1801cf5af0ba0aa..b260fe504f0093ea45e954acec007ff1e64f4b4f 100644 GIT binary patch delta 191 zcmcb^wT)Z-G%qg~0}$+O(Mii=W?*;>;=q6ql=0bPqq;1U0TV+iV~T7lbCwcJ0fJ7E zTf?>*s2>E<`J#j>Ko`M7G&y|7N-`)0~xnCU@SjP;mK2&>zIm! zC-bv-aLWKSGXilj3*+P@mUprbSvW3mO3!ee?>EzL1J@N6>ksk*{7jA9MN&XT09I%y Ax&QzG delta 103 zcmdnSeTPf^G%qg~0}ya^u8hon pnnIIrFxO3vW^v_~1}bC(;^NN?lUK96@E;JFoAnK{xt6=`%e$x}T~7A4|0LOEqvktGs1Ee(fB5HLbQ zfKj3VR+BJbj6?uyNEEP^R0GCI46u&W0M?UQzy>0bxY0P=DEo4lLaf`nYt1rDRf9#SYe78rFtNFC2qpAk>(OQ1fv(4KB!$2wFeO=zT3|GAfZ2*_u zG>PLbgcShH4UkMGX*aG!E6~jCs!g)WC%Y0n+G6tazUYcoC|nJ&V2|ym`e>F}I;AO) zb?_U$&9Yhw`ahTD7{3?*U6I|K&c4R&B$W9(?2l6ABb<}?QIE3#Cp1VuZLDHui?_tS?_VKagthx+^Jdj3^J zD?Ws)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w$7oy^}iQ`G! zn=h)%TF%rg+J{R;+^Z6WY?`PW%r`tjr`)qkht9!N7JlZt?2lN2eb@FHC^p@ltkCFZ zvfzIA0X*x0>JGtQaR?9Wh~h{(Q-TK^vPD~S2z}x1g*+j7W0}sv+kbe*;l>#e zGg~U?sO{L(XjQ#y}WH&V;iddUPqUFmW5IyTCK>% z)q+!_t6lr*`z#)eJxSbcV$Z^Bt0}kH@>il>Ro zMI8&VKaOJ}WtaoSyDvxe4Co536x7fqT9BkM$@GGWc@vLauWj{V&5@F!(Mz!ILw0Lm zrz-C|gSTvXQw*uyV?z5XOn9@`ZR{RX^JW(J2>P|YgY?B`Z@1fE)p1XijLE%L$x?OE zcLe`_2|jQ3XAv)}bHQI+%k6HYC7Au1bq{~hjIvO=+4#uG7oG=GWS;v;0c21*vRE>f z?8?NL&',views.user_inspect,name="user_inspect"), path('user/login/',views.user_login), path('user/register/',views.user_register), - path('404/',views.error,name="error") + path('404/',views.error,name="error"), + + path('u/0/api/user_api',views.user_api,name="user_api"), ] \ No newline at end of file diff --git a/main/views.py b/main/views.py index c80e565..8cc759e 100644 --- a/main/views.py +++ b/main/views.py @@ -4,6 +4,7 @@ from . import models from django.conf import settings from django.http import JsonResponse +from django.views.decorators.csrf import csrf_exempt # Create your views here. def index(request): logged_in = True if settings.LOGGED_IN else False @@ -202,3 +203,10 @@ def my_products(request): 'data' : total_set, } return HttpResponse(template.render(context,request)) + + + +@csrf_exempt +def user_api(request): + items = models.users.objects.all().values() + return JsonResponse(list(items), safe=False) \ No newline at end of file diff --git a/static/js/description.js b/static/js/description.js index a4ac5a1..674bae3 100644 --- a/static/js/description.js +++ b/static/js/description.js @@ -1,3 +1,7 @@ -function myFunction() { - alert("Hello iam desciption"); - } \ No newline at end of file +function show(){ + document.getElementById("descriptionpop").style.display = "block"; +} + +function hide(){ + document.getElementById("descriptionpop").style.display = "none"; +} \ No newline at end of file diff --git a/static/js/index.js b/static/js/index.js new file mode 100644 index 0000000..6f84cc8 --- /dev/null +++ b/static/js/index.js @@ -0,0 +1,8 @@ +fetch('/u/0/api/user_api') + .then(response => response.json()) + .then(data => { + console.log(data); + }) + .catch(error => { + console.error('Error:', error); + }); diff --git a/static/styles.css b/static/styles.css index 620b2b1..8f2ce78 100644 --- a/static/styles.css +++ b/static/styles.css @@ -190,6 +190,10 @@ button:hover { color: #fff; } +.product_description_upload { + height: 250px; + width: 100%; +} /* auctions */ .filter_box { @@ -498,4 +502,39 @@ button:hover { height: 200px; width: 200px; border-radius: 10px 10px 0px 0px; +} + +/*description -pop */ +#descriptionpop { + display: none; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgba(0, 0, 0, 0.5); +} + +.modal-content { + background-color: #fefefe; + margin: 20% auto; + padding: 20px; + border: 1px solid #888; + width: 80%; +} + +.close { + color: #aaa; + float: right; + font-size: 28px; + font-weight: bold; +} + +.close:hover, +.close:focus { + color: black; + text-decoration: none; + cursor: pointer; } \ No newline at end of file diff --git a/templates/auction.html b/templates/auction.html index 39f0d46..b84c191 100644 --- a/templates/auction.html +++ b/templates/auction.html @@ -2,7 +2,13 @@ {% block title %} Auction-site {% endblock title %} -{% load static %} + +{% load static %} + + {% block js %} + + {% endblock js %} + {% block content %}

Product ID:

@@ -18,7 +24,13 @@

{{data.product_id}}

User_name

{{data.user_name}}

- + +
+ +
diff --git a/templates/base.html b/templates/base.html index 17c8a95..243b734 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,7 +8,9 @@ - + {% block js %} + + {% endblock js %}
diff --git a/templates/upload.html b/templates/upload.html index 825f192..d096361 100644 --- a/templates/upload.html +++ b/templates/upload.html @@ -10,10 +10,10 @@

upload your product

{% csrf_token %}
-
-
-
- +
+
+
+