This commit is contained in:
commit
2f51e6e24b
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"python.pythonPath": "C:\\ProgramData\\Anaconda3\\python.exe",
|
||||
"python.dataScience.jupyterServerURI": "local"
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
from django.contrib import admin
|
||||
from .models import User
|
||||
from .models import AuctionListing,Comment,Bids
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(User)
|
||||
admin.site.register(AuctionListing)
|
||||
admin.site.register(Comment)
|
||||
admin.site.register(Bids)
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AuctionsConfig(AppConfig):
|
||||
name = 'auctions'
|
|
@ -0,0 +1,82 @@
|
|||
# Generated by Django 3.0.8 on 2020-10-19 17:27
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0011_update_proxy_permissions'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
|
||||
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
|
||||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
|
||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'user',
|
||||
'verbose_name_plural': 'users',
|
||||
'abstract': False,
|
||||
},
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AuctionListing',
|
||||
fields=[
|
||||
('title', models.CharField(max_length=64, primary_key=True, serialize=False)),
|
||||
('price', models.DecimalField(decimal_places=2, max_digits=10)),
|
||||
('desc', models.CharField(max_length=1000)),
|
||||
('picture', models.URLField(default='https://www.riobeauty.co.uk/images/product_image_not_found.gif')),
|
||||
('category', models.CharField(choices=[('Fashion', 'Fashion'), ('Electronics', 'Electronics'), ('Home', 'Home'), ('Sports', 'Sports'), ('Toys', 'Toys'), ('Automobile', 'Automobile'), ('Books', 'Books'), ('Videogames', 'Videogames'), ('Other', 'Other')], max_length=64)),
|
||||
('date_added', models.DateTimeField(auto_now_add=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Comment',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('body', models.TextField()),
|
||||
('date_added', models.DateTimeField(auto_now_add=True)),
|
||||
('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='auctions.AuctionListing')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commited_user', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Bids',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('bid_value', models.DecimalField(decimal_places=2, max_digits=10)),
|
||||
('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bidding_listing', to='auctions.AuctionListing')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bidding_user', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='watchlist',
|
||||
field=models.ManyToManyField(blank=True, related_name='watchlists', to='auctions.AuctionListing'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.8 on 2020-10-21 11:57
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auctions', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='auctionlisting',
|
||||
name='closed',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,46 @@
|
|||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
|
||||
class User(AbstractUser):
|
||||
watchlist = models.ManyToManyField('AuctionListing',blank = True,related_name="watchlists")
|
||||
|
||||
class AuctionListing(models.Model):
|
||||
category_choices = (
|
||||
('Fashion','Fashion'),
|
||||
('Electronics','Electronics'),
|
||||
('Home','Home'),
|
||||
('Sports','Sports'),
|
||||
('Toys','Toys'),
|
||||
('Automobile','Automobile'),
|
||||
('Books','Books'),
|
||||
('Videogames','Videogames'),
|
||||
('Other','Other'),
|
||||
)
|
||||
title = models.CharField(max_length = 64,primary_key = True)
|
||||
user = models.ForeignKey(User,on_delete = models.CASCADE)
|
||||
price = models.DecimalField(max_digits = 10,decimal_places = 2)
|
||||
desc = models.CharField(max_length = 1000)
|
||||
picture = models.URLField(default="https://www.riobeauty.co.uk/images/product_image_not_found.gif")
|
||||
category = models.CharField(max_length = 64,choices=category_choices)
|
||||
date_added = models.DateTimeField(auto_now_add=True)
|
||||
closed = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title}: {self.price},{self.desc},{self.picture},{self.category},{self.date_added}"
|
||||
|
||||
|
||||
class Comment(models.Model):
|
||||
listing = models.ForeignKey(AuctionListing,on_delete = models.CASCADE,related_name="comments")
|
||||
user = models.ForeignKey(User,related_name="commited_user",on_delete=models.CASCADE)
|
||||
body = models.TextField()
|
||||
date_added = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return '%s - %s' % (self.listing.title, self.user)
|
||||
class Bids(models.Model):
|
||||
bid_value = models.DecimalField(max_digits = 10,decimal_places = 2)
|
||||
user = models.ForeignKey(User,on_delete = models.CASCADE, related_name="bidding_user")
|
||||
listing = models.ForeignKey(AuctionListing, on_delete= models.CASCADE, related_name="bidding_listing")
|
||||
|
||||
def __str__(self):
|
||||
return '%s - %s - %s' % (self.bid_value, self.user, self.listing)
|
|
@ -0,0 +1,3 @@
|
|||
body {
|
||||
padding: 10px;
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
{% extends "auctions/layout.html"%}
|
||||
|
||||
{% block body %}
|
||||
<h2>Listings under category "{{ cat_name }}"</h2>
|
||||
{% if listings %}
|
||||
<div class="row">
|
||||
|
||||
{% for list in listings %}
|
||||
<div class="col-sm-3">
|
||||
<a href="listing/{{list.title}}" style = "color:inherit;text-decoration: none;">
|
||||
<div class="card border-light" style="width: 18rem;">
|
||||
<div class="shadow p-2 mb-2 bg-white rounded">
|
||||
<img class="card-img-top" src="{{ list.picture }}" alt="Preview not found">
|
||||
|
||||
<hr>
|
||||
<div class="card-body">
|
||||
<h4>{{ list.title }}</h4><br>
|
||||
|
||||
|
||||
<p class="card-text" style="font-size: large;">
|
||||
<b>bid price</b> : ${{list.price}}<br>
|
||||
<b>created by</b>: {{list.user}}
|
||||
</p>
|
||||
<div class = "text-right">
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<form action="{% url 'watch' list.title %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{% if user not in list.watchlists.all %}
|
||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
||||
{% else %}
|
||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary btn-sm">Unwatch</button>
|
||||
{% endif %}
|
||||
<input type="hidden" name="previous" value="{{ request.path }}">
|
||||
</form>
|
||||
{% else %}
|
||||
<small>log in to watch this listing</small>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<center>
|
||||
<h3> Seems to be no listings in this category</h3>
|
||||
</center>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -0,0 +1,19 @@
|
|||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<div class="jumbotron jumbotron-fluid">
|
||||
<div class="container">
|
||||
<h1 class="display-4">Categories</h1>
|
||||
<p class="lead">Select category to browse through listings</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="list-group">
|
||||
<a href="#" class="list-group-item list-group-item-action active">
|
||||
Select any one of the following
|
||||
</a>
|
||||
{% for cat in categories %}
|
||||
<a href="category/{{cat}}" class="list-group-item list-group-item-action">{{cat}}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,34 @@
|
|||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
<h2>Create Listing</h2>
|
||||
|
||||
|
||||
<form action="{% url 'create' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<input class="form-control" autofocus type="text" name="title" placeholder="title">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="form-control" type="text" name="desc" placeholder="Description">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="form-control" type="number" name="starting_bid" placeholder="starting bid">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="form-control" type="url" name="photo" placeholder="Picture(Optional)">
|
||||
</div>
|
||||
<div class ="form-group">
|
||||
<select class="form-control" name = "category" placeholder = "Category">
|
||||
<option selected disabled>Select a Category</option>
|
||||
{% for cat in categories %}
|
||||
<option value="{{cat}}">{{cat}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<input class="btn btn-primary" type="submit" value="Create Listing">
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,80 @@
|
|||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<h2>Active Listings</h2>
|
||||
<div class="row">
|
||||
{% for listing in Listings %}
|
||||
<div class="col-lg-3 mb-10">
|
||||
<a href="listing/{{ listing.title}}" style = "color:inherit;text-decoration: none;">
|
||||
<div class="card border-light" style="width: 18rem;">
|
||||
<div class="shadow p-2 mb-2 bg-white rounded">
|
||||
<img class="card-img-top" src="{{ listing.picture }}" alt="Preview not found">
|
||||
|
||||
<hr>
|
||||
<div class="card-body">
|
||||
<h4>{{ listing.title }}</h4><br>
|
||||
|
||||
{% if not listing.closed %}
|
||||
<p class="card-text" style="font-size: medium;">
|
||||
{% for bidding in listing.bidding_listing.all %}
|
||||
<b>bid price</b> : ${{bidding.bid_value}}<br>
|
||||
<b>Last bid by</b>: {{bidding.user}}
|
||||
<br>
|
||||
<b>created by</b>: {{listing.user}}<br>
|
||||
{% endfor %}
|
||||
|
||||
<small class="text-muted"><i> created on {{listing.date_added}}</i> </small>
|
||||
</p>
|
||||
{% else %}
|
||||
<p class="card-text" style="font-size: medium;">
|
||||
<strong style="color:red;">CLOSED</strong>
|
||||
<br>
|
||||
This listing is over.
|
||||
<br>
|
||||
<br>
|
||||
{% for bidding in listing.bidding_listing.all %}
|
||||
{% if user == bidding.user %}
|
||||
<b>You won this listing!!!</b>
|
||||
{% else %}
|
||||
<b>This is won by <strong style="color:navy;font-size: large;">@{{ bidding.user }}</strong></b>
|
||||
for <strong>${{bidding.bid_value}}</strong>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div class = "text-right">
|
||||
{% if listing.closed %}
|
||||
|
||||
|
||||
{% elif user.is_authenticated %}
|
||||
|
||||
<form action="{% url 'watch' listing.title %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{% if user not in listing.watchlists.all %}
|
||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
||||
{% else %}
|
||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary btn-sm">Unwatch</button>
|
||||
{% endif %}
|
||||
|
||||
<input type="hidden" name="previous" value="{{ request.path }}">
|
||||
</form>
|
||||
{% else %}
|
||||
<small>log in to watch this listing</small>
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,61 @@
|
|||
{% load static %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{% block title %}Auctions{% endblock %}</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
|
||||
<link href="{% static 'auctions/styles.css' %}" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Auctions</h1>
|
||||
<div class = "text-right" style = "align-self: flex-end;">
|
||||
{% if user.is_authenticated %}
|
||||
Signed in as <strong>{{ user.username }}</strong>.
|
||||
{% else %}
|
||||
Not signed in.
|
||||
{% endif %}
|
||||
</div>
|
||||
<nav class="navbar navbar-expand-md navbar-light bg-light">
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarNavDropdown">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="{% url 'index' %}">Active Listings <span class="sr-only">(current)</span></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'categories' %}">Categories</a>
|
||||
</li>
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'watchlist' %}">WatchList <span class="badge badge-secondary">{{ user.watchlist.count }}</span></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'create' %}">Create Listing</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
|
||||
{% if not user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'login'%}">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'register' %}">Register</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
<hr>
|
||||
{% block body %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,99 @@
|
|||
|
||||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<h2>Listing : {{ Listing.title}}</h2>
|
||||
|
||||
<div class="text-right">
|
||||
{% if user.username|stringformat:"s" == Listing.user|stringformat:"s" %}
|
||||
|
||||
|
||||
|
||||
<a class="btn btn-danger" href="{% url 'close_bid' Listing.title %}" role="button" style="display:inline;">Close this Listing</a>
|
||||
{% endif %}
|
||||
<form action="{% url 'watch' Listing.title %}" method="POST" style="display:inline;" >
|
||||
{% csrf_token %}
|
||||
{% if user not in Listing.watchlists.all %}
|
||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary" >Watch</button>
|
||||
{% else %}
|
||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary">Unwatch</button>
|
||||
{% endif %}
|
||||
<input type="hidden" name="previous" value="{{ request.path }}">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<img src = "{{Listing.picture}}" width = "50%" height= "50%"></img>
|
||||
<hr>
|
||||
|
||||
<p style="font-size: large;">{{Listing.desc}}</p>
|
||||
|
||||
{% if Listing.closed %}
|
||||
<br>
|
||||
<h3 style="background-color:orangered;color:white;"><center>This listing is CLOSED</center></h3>
|
||||
<br>
|
||||
<h4>This Listing is won by <strong style="color:maroon;">@{{bids.user}}</strong> for <strong style="color:green;">${{bids.bid_value}}</strong></h4>
|
||||
{% else %}
|
||||
<h3 style="color:darkgreen;">${{bids.bid_value}} <small style = "color:black;">by</small> <small style="color:navy;">@{{bids.user}}</small></h3>
|
||||
|
||||
<br>
|
||||
{% if user.is_authenticated and user != Listing.user %}
|
||||
<form action="{% url 'bid' Listing.title %}" method = "POST">
|
||||
{% csrf_token %}
|
||||
{{ bid_form }}
|
||||
|
||||
<br/>
|
||||
<input class="btn btn-primary" type="submit" value="Place Bid">
|
||||
</form>
|
||||
{% elif user.is_authenticated and user == Listing.user%}
|
||||
<h5>You can't bid on your own Listing</h5>
|
||||
{% else %}
|
||||
<br>
|
||||
<strong>Log In to bid on this Listing</strong>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<br>
|
||||
<hr>
|
||||
<h4>Comments ...</h4>
|
||||
|
||||
{% if not Listing.comments.all %}
|
||||
No comments Yet....
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
{% else %}
|
||||
{% for comment in Listing.comments.all %}
|
||||
<strong style="color:maroon;">{{comment.user}} - {{comment.date_added}}</strong>
|
||||
<br/>
|
||||
{{ comment.body }}
|
||||
<br/>
|
||||
<hr>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% if not Listing.closed%}
|
||||
<h5>Add comment</h5>
|
||||
<p>
|
||||
<form action="{% url 'listing' Listing.title %}" method="POST">
|
||||
{% csrf_token %}
|
||||
<textarea class = "form-control" name="comment_body" rows="4" cols="50" placeholder="Comment here!"></textarea>
|
||||
<br>
|
||||
<input class="btn btn-primary" type="submit" value="Submit">
|
||||
</form>
|
||||
</p>
|
||||
{% elif not user.is_authenticated %}
|
||||
<br/>
|
||||
<hr>
|
||||
Log In to comment on this listing
|
||||
|
||||
{% else %}
|
||||
<br/>
|
||||
<hr>
|
||||
The Listing is <strong style="color:red;">CLOSED</strong> for comments
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -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 %}
|
|
@ -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 %}
|
|
@ -0,0 +1,53 @@
|
|||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<h2>WatchList </h2>
|
||||
{% if Watchlistings %}
|
||||
<div class="row">
|
||||
{% for listing in Watchlistings %}
|
||||
<div class="col-sm-3">
|
||||
<a href="listing/{{ listing.title}}" style = "color:inherit;text-decoration: none;">
|
||||
<div class="card border-light" style="width: 18rem;">
|
||||
<div class="shadow p-2 mb-2 bg-white rounded">
|
||||
<img class="card-img-top" src="{{ listing.picture }}" alt="Preview not found">
|
||||
|
||||
<hr>
|
||||
<div class="card-body">
|
||||
<h4>{{ listing.title }}</h4><br>
|
||||
|
||||
|
||||
<p class="card-text" style="font-size: large;">
|
||||
<b>bid price</b> : ${{listing.price}}<br>
|
||||
<b>created by</b>: {{listing.user}}<br>
|
||||
|
||||
<small><i> created at {{listing.date_added}}</i> </small>
|
||||
</p>
|
||||
<div class = "text-right">
|
||||
<form action = "{% url 'watch' listing.title %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{% if user not in listing.watchlists.all %}
|
||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
||||
{% else %}
|
||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary btn-sm">Unwatch</button>
|
||||
{% endif %}
|
||||
|
||||
<input type="hidden" name="previous" value="{{ request.path }}">
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<center><h3>There seems to be no listing you are watching !!
|
||||
</h3></center>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,19 @@
|
|||
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("watchlist", views.watchlist, name="watchlist"),
|
||||
path("create", views.create, name="create"),
|
||||
path("categories", views.category, name="categories"),
|
||||
path("category/<str:cat_name>",views.category,name="individual_categories"),
|
||||
path("listing/<str:title>",views.listing,name="listing"),
|
||||
path("category/listing/<str:title>",views.listing,name="listing"),
|
||||
path("watch/<str:title>",views.watch,name="watch"),
|
||||
path("bid/<str:title>",views.bid,name="bid"),
|
||||
path("close/<str:title>",views.close_bid,name="close_bid"),
|
||||
]
|
|
@ -0,0 +1,181 @@
|
|||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
from django.db import IntegrityError
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django import forms
|
||||
from .models import User,AuctionListing,Comment,Bids
|
||||
|
||||
|
||||
categories = ['Fashion','Electronics','Home','Sports','Toys','Automobile','Books','Videogames', 'Other']
|
||||
class Bid_Form(forms.Form):
|
||||
bid_value = 0.00
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Bid_Form, self).__init__(*args, **kwargs)
|
||||
self.fields['bid'].widget.attrs['min'] = 10
|
||||
|
||||
bid = forms.DecimalField(decimal_places=2)
|
||||
|
||||
def watch(request,title):
|
||||
if request.method =="POST":
|
||||
listing = AuctionListing.objects.get(title=title)
|
||||
if request.user in listing.watchlists.all():
|
||||
request.user.watchlist.remove(listing)
|
||||
else:
|
||||
request.user.watchlist.add(listing)
|
||||
previous_url = request.POST.get('previous','/')
|
||||
|
||||
return HttpResponseRedirect(previous_url)
|
||||
def watchlist(request):
|
||||
listings = request.user.watchlist.all()
|
||||
|
||||
return render(request,"auctions/watchlist.html",{
|
||||
"Watchlistings": listings
|
||||
})
|
||||
|
||||
def index(request):
|
||||
listings = AuctionListing.objects.all()
|
||||
|
||||
return render(request, "auctions/index.html",{
|
||||
"Listings":listings,
|
||||
|
||||
})
|
||||
|
||||
def listing(request,title):
|
||||
"""
|
||||
docstring
|
||||
"""
|
||||
listing = AuctionListing.objects.get(pk = title)
|
||||
bids = Bids.objects.get(listing = listing)
|
||||
if request.method == "POST":
|
||||
body = request.POST["comment_body"]
|
||||
comment = Comment(user=request.user,listing=listing,body = body)
|
||||
comment.save()
|
||||
|
||||
|
||||
|
||||
return render(request,"auctions/listing.html",{
|
||||
"Listing": listing,
|
||||
"bids" : bids,
|
||||
"bid_form":Bid_Form(bids.bid_value)
|
||||
})
|
||||
|
||||
def category(request,cat_name = None):
|
||||
"""
|
||||
docstring
|
||||
"""
|
||||
if( cat_name != None):
|
||||
if cat_name.capitalize() in categories:
|
||||
|
||||
listings = AuctionListing.objects.filter(category=cat_name.capitalize())
|
||||
print(listings)
|
||||
|
||||
return render(request, "auctions/category.html",{
|
||||
"listings":listings,
|
||||
"cat_name": cat_name
|
||||
|
||||
})
|
||||
|
||||
else:
|
||||
return render(request,"auctions/category_listing.html",{
|
||||
"categories": categories
|
||||
})
|
||||
|
||||
def login_view(request):
|
||||
if request.method == "POST":
|
||||
|
||||
# Attempt to sign user in
|
||||
username = request.POST["username"]
|
||||
password = request.POST["password"]
|
||||
user = authenticate(request, username=username, password=password)
|
||||
|
||||
# Check if authentication successful
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
return HttpResponseRedirect(reverse("index"))
|
||||
else:
|
||||
return render(request, "auctions/login.html", {
|
||||
"message": "Invalid username and/or password."
|
||||
})
|
||||
else:
|
||||
return render(request, "auctions/login.html")
|
||||
|
||||
|
||||
def logout_view(request):
|
||||
logout(request)
|
||||
return HttpResponseRedirect(reverse("index"))
|
||||
|
||||
|
||||
def register(request):
|
||||
if request.method == "POST":
|
||||
username = request.POST["username"]
|
||||
email = request.POST["email"]
|
||||
|
||||
# Ensure password matches confirmation
|
||||
password = request.POST["password"]
|
||||
confirmation = request.POST["confirmation"]
|
||||
if password != confirmation:
|
||||
return render(request, "auctions/register.html", {
|
||||
"message": "Passwords must match."
|
||||
})
|
||||
|
||||
# Attempt to create new user
|
||||
try:
|
||||
user = User.objects.create_user(username, email, password)
|
||||
user.save()
|
||||
except IntegrityError:
|
||||
return render(request, "auctions/register.html", {
|
||||
"message": "Username already taken."
|
||||
})
|
||||
login(request, user)
|
||||
return HttpResponseRedirect(reverse("index"))
|
||||
else:
|
||||
return render(request, "auctions/register.html")
|
||||
def create(request):
|
||||
"""
|
||||
docstring
|
||||
"""
|
||||
if request.method == "POST":
|
||||
title = request.POST["title"]
|
||||
desc = request.POST["desc"]
|
||||
starting_bid = request.POST["starting_bid"]
|
||||
photo_url = request.POST["photo"]
|
||||
if photo_url == "":
|
||||
photo_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/No_image_available_600_x_450.svg/1280px-No_image_available_600_x_450.svg.png"
|
||||
category = request.POST["category"]
|
||||
listing_obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category)
|
||||
listing_obj.save()
|
||||
bid_obj = Bids(bid_value = starting_bid, listing = listing_obj, user = request.user)
|
||||
bid_obj.save()
|
||||
return render(request,"auctions/index.html",{
|
||||
"Listings" : AuctionListing.objects.all()
|
||||
})
|
||||
else:
|
||||
return render(request,"auctions/create_listing.html",{
|
||||
"categories":categories
|
||||
})
|
||||
def bid(request, title):
|
||||
listing = AuctionListing.objects.get(title=title)
|
||||
bid = Bids.objects.get(listing = listing)
|
||||
new_bid_value = request.POST["bid"]
|
||||
bid.bid_value = new_bid_value
|
||||
bid.user = request.user
|
||||
return render(request,"auctions/listing.html",{
|
||||
"Listing": listing,
|
||||
"bids" : bid,
|
||||
"bid_form":Bid_Form(bid.bid_value)
|
||||
})
|
||||
def close_bid(request,title):
|
||||
listing = AuctionListing.objects.get(title=title)
|
||||
listing.closed = True
|
||||
listing.save()
|
||||
previous_url = request.POST.get('previous','/')
|
||||
print(previous_url)
|
||||
|
||||
|
||||
return HttpResponseRedirect(previous_url)
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
ASGI config for commerce project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'commerce.settings')
|
||||
|
||||
application = get_asgi_application()
|
|
@ -0,0 +1,122 @@
|
|||
"""
|
||||
Django settings for commerce project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 3.0.2.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.0/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = '6ps8j!crjgrxt34cqbqn7x&b3y%(fny8k8nh21+qa)%ws3fh!q'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'auctions',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'commerce.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'commerce.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
AUTH_USER_MODEL = 'auctions.User'
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
|
@ -0,0 +1,22 @@
|
|||
"""commerce URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("", include("auctions.urls"))
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for commerce project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'commerce.settings')
|
||||
|
||||
application = get_wsgi_application()
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'commerce.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue