intial push

This commit is contained in:
Priyatham-sai-chand 2020-10-15 22:48:39 +05:30
commit 9cc4e8f240
55 changed files with 653 additions and 0 deletions

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"python.pythonPath": "C:\\Users\\bncha\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe",
"python.dataScience.jupyterServerURI": "local"
}

0
auctions/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

9
auctions/admin.py Normal file
View File

@ -0,0 +1,9 @@
from django.contrib import admin
from .models import User
from .models import AuctionListing
from .models import Comments
# Register your models here.
admin.site.register(User)
admin.site.register(AuctionListing)
admin.site.register(Comments)

5
auctions/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class AuctionsConfig(AppConfig):
name = 'auctions'

View File

@ -0,0 +1,64 @@
# Generated by Django 3.0.8 on 2020-10-11 16:42
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(null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Comments',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('comment', models.CharField(max_length=1000)),
('title', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='auction_title', to='auctions.AuctionListing')),
],
),
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.8 on 2020-10-11 17:53
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('auctions', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='auctionlisting',
name='user',
field=models.ForeignKey(default=' ', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.8 on 2020-10-11 18:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auctions', '0002_auto_20201011_2323'),
]
operations = [
migrations.AlterField(
model_name='auctionlisting',
name='picture',
field=models.ImageField(null=True, upload_to=''),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.8 on 2020-10-13 03:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auctions', '0003_auto_20201012_0007'),
]
operations = [
migrations.AlterField(
model_name='auctionlisting',
name='picture',
field=models.URLField(null=True),
),
]

View File

22
auctions/models.py Normal file
View File

@ -0,0 +1,22 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
pass
class AuctionListing(models.Model):
title = models.CharField(max_length = 64,primary_key = True)
user = models.ForeignKey(User,on_delete = models.CASCADE,default = " ")
price = models.DecimalField(max_digits = 10,decimal_places = 2)
desc = models.CharField(max_length = 1000)
picture = models.URLField(null=True)
def __str__(self):
return f"{self.title}: {self.price},{self.desc},{self.picture}"
class Comments(models.Model):
title = models.ForeignKey(AuctionListing,on_delete = models.CASCADE,related_name="auction_title")
comment = models.CharField(max_length = 1000)

View File

@ -0,0 +1,3 @@
body {
padding: 10px;
}

View File

@ -0,0 +1,37 @@
{% 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>
<option value="automobiles">Automobiles</option>
<option value="books">Books</option>
<option value="household_appliances">Household Appliances</option>
<option value="gardening">Gardening</option>
<option value="electronics">Electronics</option>
<option value="other">Other</option>
</select>
</div>
<input class="btn btn-primary" type="submit" value="Create Listing">
</form>
{% endblock %}

View File

@ -0,0 +1,29 @@
{% extends "auctions/layout.html" %}
{% block body %}
<h2>Active Listings</h2>
<div class="row">
{% for listing in Listings %}
<div class="col-sm-3">
<a href="" style = "color:inherit;text-decoration: none;">
<div class="card" style="width: 18rem;">
<div class="shadow p-3 mb-5 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>starting price</b> : ${{listing.price}}<br>
<b>created by</b>: {{listing.user}}
</p>
<a href="">click for more</a>
</div>
</div>
</div>
</a>
</div>
{% endfor %}
</div>
{% endblock %}

View File

@ -0,0 +1,49 @@
{% 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 style = "align-self: flex-end;">
{% if user.is_authenticated %}
Signed in as <strong>{{ user.username }}</strong>.
{% else %}
Not signed in.
{% endif %}
</div>
<ul class="nav">
<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 'categories' %}">Categories</a>
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'wishlist' %}">WishList</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'create' %}">Create Listing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Log Out</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>

View File

@ -0,0 +1,16 @@
{% extends "auctions/layout.html" %}
{% block body %}
<h2>Listing:{Listing.title}</h2>
<img src = "{Listing.picture}"></img>
<p>{Listing.desc}</p>
<h3>${Listing.price}</h3>
bids so far
<div class="form-group">
<input class="form-control" autofocus type="number" name="bid" placeholder="Bid">
</div>
<input class="btn btn-primary" type="submit" value="Create Listing">
{% endblock %}

View File

@ -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 %}

View File

@ -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 %}

3
auctions/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

13
auctions/urls.py Normal file
View File

@ -0,0 +1,13 @@
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("wishlist", views.register, name="wishlist"),
path("create", views.create, name="create"),
path("categories", views.register, name="categories")
]

92
auctions/views.py Normal file
View File

@ -0,0 +1,92 @@
from django.contrib.auth import authenticate, login, logout
from django.db import IntegrityError
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
from django.core.files import File
from django.core.files.temp import NamedTemporaryFile
from django.core.files.base import ContentFile
import requests
from .models import User,AuctionListing,Comments
def index(request):
listings = AuctionListing.objects.all()
return render(request, "auctions/index.html",{
"Listings":listings
})
def listing(request,title):
"""
docstring
"""
listing = AuctionListing.objects.get(title)
return render(request,"acutions/listing.html",{
"Listing": listing
})
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"]
obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url)
obj.save()
return render(request,"auctions/index.html")
else:
return render(request,"auctions/create_listing.html")

0
commerce/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
commerce/asgi.py Normal file
View File

@ -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()

122
commerce/settings.py Normal file
View File

@ -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/'

22
commerce/urls.py Normal file
View File

@ -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"))
]

16
commerce/wsgi.py Normal file
View File

@ -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()

BIN
db.sqlite3 Normal file

Binary file not shown.

BIN
google Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
google_9q82OQA Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
image_google Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
image_google_sTknGkm Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

21
manage.py Normal file
View File

@ -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()