duplicate me50 branch to personal one
This commit is contained in:
parent
d250afdcc9
commit
83aea28eee
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,89 @@
|
|||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<h2>All Listings</h2>
|
||||
{% if Listings %}
|
||||
<div class="row">
|
||||
{% for listing in Listings %}
|
||||
<div class="col md-3 mb-4">
|
||||
<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> : <strong style="color:darkgreen;">${{bidding.bid_value}}</strong><br>
|
||||
<b>Last bid by</b>: <strong style="color:navy;">{{ bidding.user }}</strong>
|
||||
<br>
|
||||
<b>Description</b>: {{ listing.desc }}<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>
|
||||
{% else %}
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<center>
|
||||
<h3> Seems to be no listings in this Auction!!</h3>
|
||||
</center>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,88 @@
|
|||
{% 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 md-3 mb-4">
|
||||
<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>
|
||||
{% if not list.closed %}
|
||||
<p class="card-text" style="font-size: medium;">
|
||||
{% for bidding in list.bidding_listing.all %}
|
||||
<b>bid price</b> : ${{bidding.bid_value}}<br>
|
||||
<b>Last bid by</b>: {{bidding.user}}
|
||||
<br>
|
||||
<b>created by</b>: {{list.user}}<br>
|
||||
{% endfor %}
|
||||
|
||||
<small class="text-muted"><i> created on {{list.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 list.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 list.closed %}
|
||||
|
||||
|
||||
{% elif 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,72 @@
|
|||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<h2>Active Listings</h2>
|
||||
{% if Listings %}
|
||||
<div class="row">
|
||||
{% for listing in Listings %}
|
||||
{% if not listing.closed %}
|
||||
<div class="col md-3 mb-4">
|
||||
<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: medium;">
|
||||
{% for bidding in listing.bidding_listing.all %}
|
||||
<b>bid price</b> : <strong style="color:darkgreen;">${{bidding.bid_value}}</strong><br>
|
||||
<b>Last bid by</b>: <strong style="color:navy;">{{ bidding.user }}</strong>
|
||||
<br>
|
||||
<b>Description</b>: {{ listing.desc }}<br>
|
||||
{% endfor %}
|
||||
|
||||
<small class="text-muted"><i> created on {{listing.date_added}}</i> </small>
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class = "text-right">
|
||||
|
||||
{% if 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>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<center>
|
||||
<h3> Seems to be no listings in this Auction!!</h3>
|
||||
</center>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,62 @@
|
|||
{% 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">
|
||||
|
||||
<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 'all_listings' %}">All Listings</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>
|
||||
|
||||
</nav>
|
||||
<hr>
|
||||
{% block body %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,97 @@
|
|||
|
||||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<h2>Listing : {{ Listing.title}}</h2>
|
||||
|
||||
<div class="text-right">
|
||||
{% if user.username|stringformat:"s" == Listing.user|stringformat:"s" and not Listing.closed %}
|
||||
|
||||
<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,85 @@
|
|||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<h2>WatchList </h2>
|
||||
{% if Watchlistings %}
|
||||
<div class="row">
|
||||
{% for listing in Watchlistings %}
|
||||
<div class="col md-3 mb-4">
|
||||
<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>
|
||||
{% 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,20 @@
|
|||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("all",views.all_listings,name="all_listings"),
|
||||
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,227 @@
|
|||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.db import IntegrityError
|
||||
from django.http import 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 BidForm(forms.Form):
|
||||
bid_value = 0.00
|
||||
|
||||
def __init__(self, bid_value,*args,**kwargs ):
|
||||
super().__init__(*args,**kwargs)
|
||||
self.bid_value = bid_value + 1
|
||||
self.fields['bid'].widget.attrs['min'] = self.bid_value
|
||||
|
||||
bid = forms.DecimalField(decimal_places=2)
|
||||
|
||||
def watch(request,title):
|
||||
"""
|
||||
Used to assign watchlist and unwatch for a user
|
||||
|
||||
"""
|
||||
if request.method =="POST":
|
||||
listing_obj = AuctionListing.objects.get(title=title)
|
||||
if request.user in listing_obj.watchlists.all():
|
||||
request.user.watchlist.remove(listing_obj)
|
||||
else:
|
||||
request.user.watchlist.add(listing_obj)
|
||||
previous_url = request.POST.get('previous','/')
|
||||
|
||||
return HttpResponseRedirect(previous_url)
|
||||
|
||||
def watchlist(request):
|
||||
"""
|
||||
Used to display the page Watchlist
|
||||
|
||||
"""
|
||||
listings = request.user.watchlist.all()
|
||||
|
||||
return render(request,"auctions/watchlist.html",{
|
||||
"Watchlistings": listings
|
||||
})
|
||||
|
||||
def index(request):
|
||||
"""
|
||||
Used to Display the homepage
|
||||
"""
|
||||
listings = AuctionListing.objects.all()
|
||||
|
||||
return render(request, "auctions/index.html",{
|
||||
"Listings":listings,
|
||||
|
||||
})
|
||||
def all_listings(request):
|
||||
"""
|
||||
Used to display all the listings
|
||||
"""
|
||||
listings = AuctionListing.objects.all()
|
||||
|
||||
return render(request,"auctions/all_listings.html",{
|
||||
"Listings":listings
|
||||
})
|
||||
|
||||
def listing(request,title):
|
||||
"""
|
||||
Used to display the listing page and commenting
|
||||
|
||||
"""
|
||||
listing_obj = AuctionListing.objects.get(pk = title)
|
||||
bids = Bids.objects.get(listing = listing_obj)
|
||||
if request.method == "POST":
|
||||
body = request.POST["comment_body"]
|
||||
comment = Comment(user=request.user,listing=listing_obj,body = body)
|
||||
comment.save()
|
||||
|
||||
return render(request,"auctions/listing.html",{
|
||||
"Listing": listing_obj,
|
||||
"bids" : bids,
|
||||
"bid_form":BidForm(bids.bid_value)
|
||||
})
|
||||
|
||||
def category(request,cat_name = None):
|
||||
"""
|
||||
Used to dispaly the category page
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
Used to authenticate a user
|
||||
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
Used to log out a user
|
||||
"""
|
||||
logout(request)
|
||||
return HttpResponseRedirect(reverse("index"))
|
||||
|
||||
|
||||
def register(request):
|
||||
"""
|
||||
Used to register a user
|
||||
"""
|
||||
|
||||
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):
|
||||
"""
|
||||
Used to create a Listing
|
||||
"""
|
||||
if request.method == "POST":
|
||||
title = request.POST["title"]
|
||||
desc = request.POST["desc"]
|
||||
starting_bid = request.POST["starting_bid"]
|
||||
photo_url = request.POST["photo"]
|
||||
|
||||
# alternate photo to display
|
||||
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_value = request.POST["category"]
|
||||
listing_obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category_value)
|
||||
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):
|
||||
"""
|
||||
Used to bid on a listing
|
||||
"""
|
||||
listing_value = AuctionListing.objects.get(title=title)
|
||||
bid_obj = Bids.objects.get(listing = listing_value)
|
||||
form = BidForm(bid_obj.bid_value,request.POST)
|
||||
if form.is_valid():
|
||||
new_bid_value = form.cleaned_data["bid"]
|
||||
bid_obj.bid_value = float("{0:.2f}".format(new_bid_value))
|
||||
bid_obj.user = request.user
|
||||
bid_obj.save()
|
||||
|
||||
return render(request,"auctions/listing.html",{
|
||||
"Listing": listing_value,
|
||||
"bids" : bid_obj,
|
||||
"bid_form":BidForm(bid_obj.bid_value)
|
||||
})
|
||||
def close_bid(request,title):
|
||||
"""
|
||||
Used to end the listing and declare a winner
|
||||
"""
|
||||
listing_value = AuctionListing.objects.get(title=title)
|
||||
listing_value.closed = True
|
||||
listing_value.save()
|
||||
|
||||
# get a hidden input to return back to same page
|
||||
|
||||
previous_url = request.POST.get('previous','/')
|
||||
return HttpResponseRedirect(previous_url)
|
||||
|
||||
|
||||
|
||||
|
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