-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ad936f9
Showing
38 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
|
||
from .models import User, Listing | ||
|
||
admin.site.register(User) | ||
admin.site.register(Listing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AuctionsConfig(AppConfig): | ||
name = 'auctions' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 4.1.5 on 2023-01-31 19:09 | ||
|
||
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', '0012_alter_user_first_name_max_length'), | ||
] | ||
|
||
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=150, 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='Listing', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=64)), | ||
('description', models.CharField(max_length=256)), | ||
('seller', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='listings', to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.contrib.auth.models import AbstractUser | ||
from django.db import models | ||
|
||
|
||
class User(AbstractUser): | ||
pass | ||
|
||
|
||
class Listing(models.Model): | ||
name = models.CharField(max_length=64) | ||
description = models.CharField(max_length=256) | ||
seller = models.ForeignKey(User, on_delete=models.CASCADE, related_name="listings") | ||
|
||
def __str__(self): | ||
return f"{self.name}, {self.description}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
padding: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "auctions/layout.html" %} | ||
|
||
{% block body %} | ||
<h2>Active Listings</h2> | ||
|
||
<ul> | ||
{% for listing in listings %} | ||
<li>Listing {{ listing.id }}: {{ listing.name }} - {{ listing.description }}, made by {{ listing.seller }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% 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> | ||
{% 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> | ||
{% if user.is_authenticated %} | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% extends "auctions/layout.html" %} | ||
|
||
{% block body %} | ||
|
||
<h2>Login</h2> | ||
|
||
{% if message %} | ||
<div>{{ message }}</div> | ||
{% endif %} | ||
|
||
<form action="{% url 'login' %}" method="post"> | ||
{% csrf_token %} | ||
<div class="form-group"> | ||
<input autofocus class="form-control" type="text" name="username" placeholder="Username"> | ||
</div> | ||
<div class="form-group"> | ||
<input class="form-control" type="password" name="password" placeholder="Password"> | ||
</div> | ||
<input class="btn btn-primary" type="submit" value="Login"> | ||
</form> | ||
|
||
Don't have an account? <a href="{% url 'register' %}">Register here.</a> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% extends "auctions/layout.html" %} | ||
|
||
{% block body %} | ||
|
||
<h2>Register</h2> | ||
|
||
{% if message %} | ||
<div>{{ message }}</div> | ||
{% endif %} | ||
|
||
<form action="{% url 'register' %}" method="post"> | ||
{% csrf_token %} | ||
<div class="form-group"> | ||
<input class="form-control" autofocus type="text" name="username" placeholder="Username"> | ||
</div> | ||
<div class="form-group"> | ||
<input class="form-control" type="email" name="email" placeholder="Email Address"> | ||
</div> | ||
<div class="form-group"> | ||
<input class="form-control" type="password" name="password" placeholder="Password"> | ||
</div> | ||
<div class="form-group"> | ||
<input class="form-control" type="password" name="confirmation" placeholder="Confirm Password"> | ||
</div> | ||
<input class="btn btn-primary" type="submit" value="Register"> | ||
</form> | ||
|
||
Already have an account? <a href="{% url 'login' %}">Log In here.</a> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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") | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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 .models import User, Listing | ||
|
||
|
||
def index(request): | ||
return render(request, "auctions/index.html", { | ||
"listings": Listing.objects.all() | ||
}) | ||
|
||
|
||
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") |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Oops, something went wrong.