Skip to content

Commit

Permalink
added rest-api tried
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh committed Apr 29, 2024
1 parent e330715 commit f6c4cfb
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 11 deletions.
Binary file modified main/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified main/__pycache__/views.cpython-312.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
path('user/<str:user_name>',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"),
]
8 changes: 8 additions & 0 deletions main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
10 changes: 7 additions & 3 deletions static/js/description.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
function myFunction() {
alert("Hello iam desciption");
}
function show(){
document.getElementById("descriptionpop").style.display = "block";
}

function hide(){
document.getElementById("descriptionpop").style.display = "none";
}
8 changes: 8 additions & 0 deletions static/js/index.js
Original file line number Diff line number Diff line change
@@ -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);
});
39 changes: 39 additions & 0 deletions static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ button:hover {
color: #fff;
}

.product_description_upload {
height: 250px;
width: 100%;
}
/* auctions */

.filter_box {
Expand Down Expand Up @@ -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;
}
16 changes: 14 additions & 2 deletions templates/auction.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
{% block title %}
Auction-site
{% endblock title %}
{% load static %}

{% load static %}

{% block js %}
<script src={% static "js/description.js" %}></script>
{% endblock js %}

{% block content %}
<div class="auction_main">
<h1>Product ID:</h1>
Expand All @@ -18,7 +24,13 @@ <h3>{{data.product_id}}</h3>
<h1>User_name</h1>
<a href="#"><h3>{{data.user_name}}</h3></a>
</div>
<button class="info_button" id="description" onclick="myFunction()">Description</button>
<button class="info_button" id="description" onclick="show()">Description</button>
<div id="descriptionpop">
<div class="modal-content">
<span class="close" onclick="hide()">&times;</span>
<h2>{{data.product_description}}</h2>
</div>
</div>
</div>
<div class="bid_box">
<div class="current_bid_details">
Expand Down
4 changes: 3 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
</title>
<link rel="icon" href={% static "logo/icon.jpg" %}>
<link rel="stylesheet" href={% static "styles.css" %}>
<script src={% static "js/description.js" %}></script>
{% block js %}

{% endblock js %}
</head>
<body>
<header>
Expand Down
8 changes: 4 additions & 4 deletions templates/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ <h1>upload your product</h1>
<form class="product_upload" method="POST" action="/user/upload/done" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="product_image" id="image" placeholder="image" required><br>
<input type="text" name="product_name" placeholder="name for product" required><br>
<input type="text" name="product_description" placeholder="Description" required><br>
<input type="text" name="product_price" placeholder="price" required><br>
<input type="submit" value="Upload">
<input type="text" name="product_name" placeholder="Name for product" required><br>
<input type="text" name="product_price" placeholder="Price" required><br>
<input type="text" name="product_description" placeholder="Description" required class="product_description_upload"><br>
<input type="submit" value="Upload" align="center">
</form>
</div>
</div>
Expand Down

0 comments on commit f6c4cfb

Please sign in to comment.