Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
7 changes: 7 additions & 0 deletions Django/Bidding app/auctions/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Listing, Bid, Comments
# Register your models here.

admin.site.register(Listing)
admin.site.register(Bid)
admin.site.register(Comments)
5 changes: 5 additions & 0 deletions Django/Bidding app/auctions/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AuctionsConfig(AppConfig):
name = 'auctions'
7 changes: 7 additions & 0 deletions Django/Bidding app/auctions/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .models import Listing
from django.forms import ModelForm

class ListingForm(ModelForm):
class Meta:
model = Listing
exclude = ['closed', 'date', 'user']
Empty file.
43 changes: 43 additions & 0 deletions Django/Bidding app/auctions/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

from django.contrib.auth.models import AbstractUser
from django.db import models
import datetime

category_choice =(
('Electronics', 'Electronics'),
('Fashion','Fashion'),
('Homedecor', 'Homedecor'),
('Automobiles', 'Automobiles'),
('Sports equipment', 'Sports equipment'),
('Music equipment', 'Music equipment'),
('Books', 'Books'),
('Miscallenous', 'Miscallenous')
)

class User(AbstractUser, ):
watchlist = models.ManyToManyField('Listing', related_name="w")


class Listing(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="owner")
title = models.CharField(max_length=20)
description = models.TextField()
startbid = models.IntegerField()
image_link = models.URLField( blank = True)
category = models.CharField(max_length=63, blank=True, null=True, choices=category_choice)
closed =models.BooleanField(default=False)
date = models.DateTimeField(default=datetime.datetime.now)

def __str__(self):
return f"{self.id}:{self.title}{self.description}{self.startbid}{self.category}"

class Bid(models.Model):
amount = models.IntegerField()
bidder = models.ForeignKey(User,on_delete=models.CASCADE, related_name="bider")
bid = models.ForeignKey(Listing, on_delete = models.CASCADE, related_name= "bidamt")

class Comments(models.Model):
comment = models.TextField()
commenter = models.ForeignKey(User,on_delete=models.CASCADE, related_name="commenterr")
d = models.DateTimeField(default=datetime.datetime.now)
rlist = models.ForeignKey(Listing, on_delete = models.CASCADE, related_name="currentcomment")
3 changes: 3 additions & 0 deletions Django/Bidding app/auctions/static/auctions/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
padding: 10px;
}
9 changes: 9 additions & 0 deletions Django/Bidding app/auctions/templates/auctions/category.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "auctions/layout.html" %}

{% block body %}

{% for i in clist %}
<button type="button" onclick="location.href='{% url 'category' cat=i %}'" name="button">{{i}}</button>
{% endfor %}

{% endblock %}
34 changes: 34 additions & 0 deletions Django/Bidding app/auctions/templates/auctions/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "auctions/layout.html" %}

{% block body %}
<h2>Active Listings</h2>

{% if present == 0 and user.is_authenticated %}
<b><h1 style="margin:auto;width:50%;border:3px solid green;padding:10px;">No such listing</h1></b>
{% endif %}
<ul>
{% for i,a in List %}
<div class="card" style="width: 18rem;">
<img src="{{i.image_link}}" class="card-img-top" alt="...">
<div style="background-color:#669900;" class="card-body">
<h5 class="card-title">{{i.title}}</h5>
<p class="card-text"><ul>
<li>
{{i.description}}
</li>
<li>
CurrentPrice:{{a}}
</li>
<br><br>
<small>Created on {{i.date}}</small>
</ul></p>
<a href="{% url 'listview' item=i.id %}" class="btn btn-primary">View Listing</a>
</div>
</div>
{% endfor %}

</ul>


TODO
{% endblock %}
69 changes: 69 additions & 0 deletions Django/Bidding app/auctions/templates/auctions/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}Auctions{% endblock %}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link href="{% static 'auctions/styles.css' %}" rel="stylesheet">

<style>
body {
background-image: url('https://www.freecodecamp.org/news/content/images/size/w2000/2020/04/w-qjCHPZbeXCQ-unsplash.jpg');
background-repeat: no-repeat;
background-attachment: scroll;
background-size: cover;
}

.nav-item{
border: 3px solid #9900cc;
border-radius: 4px;
}
.extra{
background-image: url("https://mcdn.wallpapersafari.com/medium/71/27/xc81hK.jpg");
}
</style>
</head>
<body>
<div class="extra">

<h1 style="color:#000099;text-shadow: 0 0 3px #FF0000, 0 0 5px #0000FF;" >Auctions</h1>
<div style="text-decoration:underline;">
{% if user.is_authenticated %}
Signed in as <strong>{{ user.username }}</strong>.
{% else %}
Not signed in.
{% endif %}
</div>
</div>
<ul style="background-color:black;" class="list-group list-group-horizontal">
<li class="nav-item">
<a class="nav-link" href="{% url 'index' %}">Active Listings</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'category' cat=" " %}">Categories</a>
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Log Out</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'show_watchlist' %}">Watchlist</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'createlist' %}">create listing</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'login' %}">Log In</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'register' %}">Register</a>
</li>
{% endif %}
</ul>
<hr>
{% block body %}
{% endblock %}
</body>
</html>
17 changes: 17 additions & 0 deletions Django/Bidding app/auctions/templates/auctions/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "auctions/layout.html" %}
{% block body %}
<div>
{% if error %}
<div class="alert alert-warning" role="alert">
Form info was invalid. please fill the form again
</div>
{% endif %}
</div>

<form action="{% url 'createlist' %}" id="lform" method="post">
{% csrf_token %}
{{form.as_p}}
<input type="submit" name="Create Listing" class="btn btn-info" value="Create Listing">
</form>

{% endblock %}
79 changes: 79 additions & 0 deletions Django/Bidding app/auctions/templates/auctions/listing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{% extends "auctions/layout.html" %}

{% block body %}
<h2>{{listing.title}}</h2>
{% if wlist %}
<button type="submit" onclick="location.href='{% url 'watchlist' list=listing.id remove=1 %}'" class="btn btn-primary">Remove from watchlist</button>
{% else %}
<button type="submit" onclick="location.href='{% url 'watchlist' list=listing.id remove=0 %}'" class="btn btn-primary">Add to watchlist</button>
{% endif %}
<br>
<img style="width: 400px;height: 400px;" src="{{listing.image_link}}" alt="{{listing.title}}">
<br>
<small style="background-color:#ffffcc">created on {{listing.date}}</small>
<br><br><br><br>
<div>
{{listing.description}}
</div>
{% if not listing.closed %}
<div>
{% if amount == listing.startbid %}
<b>Current bid:</b><i style="color:green">NO BID</i>
{% else %}
<b>Current bid:</b> <i style="color:green">{{amount}}</i>
{% endif %}
<br>
<b>Startbid:</b><i style="color:blue"> {{listing.startbid}}</i>

</div>
<div>
<form action="{% url 'bid' i=listing.id %}" method="post">
{% csrf_token %}
<input type="number" id="price" name="quantity" min="{{amount}}" value = "{{amount}}">
<input type="submit" name="Place Bid" value="Place Bid">
</form>
</div>
<div>
<br><br>
{% if listing in own %}
<button type="button" onclick="location.href='{% url 'close' list=listing.id %}'" class="btn btn-danger">Close Auction</button>
{% endif %}
<br><br>
<form action="{% url 'comment' li=listing.id %}" method="post">
{% csrf_token %}
<<textarea id="comment" name="name" rows="1" cols="40"></textarea>
<input type="submit" name="comment" value="comment">
</form>
</div>
<br><br><br><br>
<h3 style="text-decoration:underline;">Comments</h3>
<br><br>
{% for c in comments %}
<a href="#" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h5 style="background-color:#ffff66;text-decoration:underline" class="mb-1">{{c.commenter.username}}</h5>
<small class="text-muted">{{c.d}}</small>
</div>
<p style="border-left: 6px solid red;background-color: lightgrey;" class="mb-1">{{c.comment}}</p>
</a>
{% endfor %}
{% else %}
{% if r %}
<p><a href="#" class="text-success">Congratulations! You have won this auction</a></p>
{% endif %}
<div class="alert alert-danger" role="alert">
This auction has been closed
</div>
<br>
<br>
{% for c in comments %}
<a href="#" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{c.commmenter.username}}</h5>
<small class="text-muted">{{c.d}}</small>
</div>
<p class="mb-1">{{c.comment}}</p>
</a>
{% endfor %}
{% endif %}
{% endblock %}
24 changes: 24 additions & 0 deletions Django/Bidding app/auctions/templates/auctions/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "auctions/layout.html" %}

{% block body %}

<h2>Login</h2>

{% if message %}
<div>{{ message }}</div>
{% endif %}

<form action="{% url 'login' %}" method="post">
{% csrf_token %}
<div class="form-group">
<input autofocus class="form-control" type="text" name="username" placeholder="Username">
</div>
<div class="form-group">
<input class="form-control" type="password" name="password" placeholder="Password">
</div>
<input class="btn btn-primary" type="submit" value="Login">
</form>

Don't have an account? <a href="{% url 'register' %}">Register here.</a>

{% endblock %}
30 changes: 30 additions & 0 deletions Django/Bidding app/auctions/templates/auctions/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "auctions/layout.html" %}

{% block body %}

<h2>Register</h2>

{% if message %}
<div>{{ message }}</div>
{% endif %}

<form action="{% url 'register' %}" method="post">
{% csrf_token %}
<div class="form-group">
<input class="form-control" autofocus type="text" name="username" placeholder="Username">
</div>
<div class="form-group">
<input class="form-control" type="email" name="email" placeholder="Email Address">
</div>
<div class="form-group">
<input class="form-control" type="password" name="password" placeholder="Password">
</div>
<div class="form-group">
<input class="form-control" type="password" name="confirmation" placeholder="Confirm Password">
</div>
<input class="btn btn-primary" type="submit" value="Register">
</form>

Already have an account? <a href="{% url 'login' %}">Log In here.</a>

{% endblock %}
34 changes: 34 additions & 0 deletions Django/Bidding app/auctions/templates/auctions/watchlist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "auctions/layout.html" %}

{% block body %}
<h2>Watchlist</h2>

{% if present == 0 and user.is_authenticated %}
<b><h1 style="margin:auto;width:50%;border:3px solid green;padding:10px;">Watchlist is empty &#128555;</h1></b>
{% endif %}
<ul>
{% for i,a in List %}
<div class="card" style="width: 18rem;">
<img src="{{i.image_link}}" class="card-img-top" alt="...">
<div style="background-color:#669900;" class="card-body">
<h5 class="card-title">{{i.title}}</h5>
<p class="card-text"><ul>
<li>
{{i.description}}
</li>
<li>
CurrentPrice:{{a}}
</li>
<br><br>
<small>Created on {{i.date}}</small>
</ul></p>
<a href="{% url 'listview' item=i.id %}" class="btn btn-primary">View Listing</a>
</div>
</div>
{% endfor %}

</ul>


TODO
{% endblock %}
3 changes: 3 additions & 0 deletions Django/Bidding app/auctions/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
18 changes: 18 additions & 0 deletions Django/Bidding app/auctions/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.urls import path

from . import views

urlpatterns = [
path("", views.index, name="index"),
path("login", views.login_view, name="login"),
path("logout", views.logout_view, name="logout"),
path("register", views.register, name="register"),
path("createlist", views.createlist, name="createlist"),
path("listview/<int:item>", views.listview, name="listview"),
path("watchlist/<int:list>/<int:remove>", views.watchlist, name="watchlist"),
path("show_watchlist", views.show_watchlist, name="show_watchlist"),
path("bid/<int:i>", views.bid, name="bid"),
path("comment/<int:li>", views.comment, name="comment"),
path("close/<int:list>", views.close, name="close"),
path("category/<str:cat>", views.category, name="category")
]
Loading