Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 003 #105

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
85f0b61
Added localhost as allowed host
MatthewBL Nov 15, 2022
9fef2d8
Added branches
MatthewBL Nov 15, 2022
779873d
Fixed the Stripe connection, changed order table and added delivery o…
sergiomdza Nov 21, 2022
16f45de
Updated DB
sergiomdza Nov 21, 2022
3a2d4e4
Merge pull request #1 from lintoeli/sm-delivery-options
sergiomdza Nov 21, 2022
f3cc5b0
Merge branch 'master' into Task-007
Pabloguti01 Nov 21, 2022
4054366
Task-003 almost done
lintoeli Nov 21, 2022
475381b
Task-007 done
Pabloguti01 Nov 24, 2022
e738134
Frontend style changes
Nov 24, 2022
a094443
Merge pull request #2 from lintoeli/Task-001
MatthewBL Nov 24, 2022
a626eb6
Merge branch 'master' into Task-003
MatthewBL Nov 24, 2022
a0edc50
Merge pull request #3 from lintoeli/Task-003
MatthewBL Nov 24, 2022
0c0e298
Merge pull request #4 from lintoeli/Task-007
MatthewBL Nov 24, 2022
7853d88
search function and search result page
Nov 28, 2022
90c0cc8
Merge pull request #5 from lintoeli/master
MatthewBL Nov 28, 2022
637be0c
Contact e-mail added
MatthewBL Nov 28, 2022
7929336
stock fixed
MatthewBL Nov 28, 2022
dee66bd
Task-008
sergiomdza Nov 29, 2022
69244ce
Merge pull request #7 from lintoeli/Task-012
MatthewBL Nov 29, 2022
c4ceca4
search filter
Nov 29, 2022
18b541f
db.sqlite3 reverted
MatthewBL Nov 29, 2022
aaac47d
gitignore updated
MatthewBL Nov 29, 2022
d888250
Merge branch 'master' into Task-008
MatthewBL Nov 29, 2022
6b6d982
Merge pull request #6 from lintoeli/Task-008
MatthewBL Nov 29, 2022
15b1ec2
Search filter is working
sergiomdza Nov 29, 2022
76d7b58
DB in gitignore
sergiomdza Nov 29, 2022
ba3dc0a
updated search filter
Nov 29, 2022
70ccc3f
Fixed conflict
sergiomdza Nov 29, 2022
7e874fc
Fixed about us info
sergiomdza Nov 29, 2022
94786e8
db.sqlite3 reverted
MatthewBL Nov 29, 2022
b7fdffd
revert db.sqlite3
MatthewBL Nov 29, 2022
41dd678
Merge pull request #8 from lintoeli/Task-009
MatthewBL Nov 29, 2022
96a8d35
Merge pull request #10 from lintoeli/master
MatthewBL Nov 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ DB_PASSWORD=your-db-password
DB_HOST=localhost
STRIPE_LIVE_PUBLIC_KEY=your-live-public-key
STRIPE_LIVE_SECRET_KEY=your-live-secret-key
STRIPE_TEST_PUBLIC_KEY=your-test-public-key
STRIPE_TEST_SECRET_KEY=your-test-secret-key
STRIPE_TEST_PUBLIC_KEY=pk_test_51M6F30LGjE9fhQqPTS1xn299XD7lokUGfB28YhXT98EqRWpikN7nmKmm02G3Rhs3GzmzXBUAGB9U2wlj5GUF7mpA00MEZvJ96P
STRIPE_TEST_SECRET_KEY=sk_test_51M6F30LGjE9fhQqPY3kIzN9j6LmzUnrc9zy7viG4Iarpz7TvEZmr0etlIKpEUgaaSi3I3Db5C42QdnkXu2X2Qr8d00RbhctodS
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
.env
db.sqlite3
MANIFEST

# PyInstaller
Expand Down
8 changes: 8 additions & 0 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
('P', 'PayPal')
)

DELIVERY_CHOICES = (
('ST', 'Standard (+ 3.00$)'),
('EX', 'Express (+ 6.00$)')
)


class CheckoutForm(forms.Form):
shipping_address = forms.CharField(required=False)
Expand Down Expand Up @@ -37,6 +42,9 @@ class CheckoutForm(forms.Form):
payment_option = forms.ChoiceField(
widget=forms.RadioSelect, choices=PAYMENT_CHOICES)

delivery_option = forms.ChoiceField(
widget=forms.RadioSelect, choices=DELIVERY_CHOICES)


class CouponForm(forms.Form):
code = forms.CharField(widget=forms.TextInput(attrs={
Expand Down
18 changes: 18 additions & 0 deletions core/migrations/0005_order_delivery_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.14 on 2022-11-21 01:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0004_auto_20190630_1408'),
]

operations = [
migrations.AddField(
model_name='order',
name='delivery_option',
field=models.CharField(max_length=20, null=True),
),
]
23 changes: 23 additions & 0 deletions core/migrations/0006_auto_20221120_2004.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.14 on 2022-11-21 02:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0005_order_delivery_option'),
]

operations = [
migrations.AddField(
model_name='order',
name='deleteTag',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='order',
name='email',
field=models.CharField(max_length=50, null=True),
),
]
18 changes: 18 additions & 0 deletions core/migrations/0007_auto_20221125_1731.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.14 on 2022-11-25 17:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0006_auto_20221120_2004'),
]

operations = [
migrations.AlterField(
model_name='item',
name='category',
field=models.CharField(choices=[('A', 'Class A'), ('B', 'Class B'), ('C', 'Class C')], max_length=2),
),
]
18 changes: 18 additions & 0 deletions core/migrations/0007_order_totalorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.14 on 2022-11-24 10:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0006_auto_20221120_2004'),
]

operations = [
migrations.AddField(
model_name='order',
name='totalOrder',
field=models.FloatField(null=True),
),
]
19 changes: 19 additions & 0 deletions core/migrations/0008_item_stock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.14 on 2022-11-28 20:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0007_order_totalorder'),
]

operations = [
migrations.AddField(
model_name='item',
name='stock',
field=models.PositiveIntegerField(default=10),
preserve_default=False,
),
]
32 changes: 27 additions & 5 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@


CATEGORY_CHOICES = (
('S', 'Shirt'),
('SW', 'Sport wear'),
('OW', 'Outwear')
('A', 'Class A'),
('B', 'Class B'),
('C', 'Class C')
)

LABEL_CHOICES = (
Expand Down Expand Up @@ -37,11 +37,13 @@ def __str__(self):
class Item(models.Model):
title = models.CharField(max_length=100)
price = models.FloatField()
description = models.CharField(max_length=1000)
discount_price = models.FloatField(blank=True, null=True)
category = models.CharField(choices=CATEGORY_CHOICES, max_length=2)
label = models.CharField(choices=LABEL_CHOICES, max_length=1)
slug = models.SlugField()
description = models.TextField()
stock = models.PositiveIntegerField(default=0)
image = models.ImageField()

def __str__(self):
Expand Down Expand Up @@ -87,6 +89,10 @@ def get_final_price(self):
return self.get_total_discount_item_price()
return self.get_total_item_price()

def validate_stock(self):
if self.quantity > self.item.stock:
raise("Not enough stock for this item: ", self.item.title)


class Order(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,
Expand All @@ -108,6 +114,10 @@ class Order(models.Model):
received = models.BooleanField(default=False)
refund_requested = models.BooleanField(default=False)
refund_granted = models.BooleanField(default=False)
delivery_option = models.CharField(max_length=20, null=True)
email = models.CharField(max_length=50, null=True)
deleteTag = models.BooleanField(default=False)
totalOrder = models.FloatField(null=True)

'''
1. Item added to cart
Expand All @@ -127,10 +137,22 @@ def get_total(self):
total = 0
for order_item in self.items.all():
total += order_item.get_final_price()
if self.coupon:
total -= self.coupon.amount
if total < 50.0:
if self.delivery_option == 'ST':
total += 3
if self.delivery_option == 'EX':
total += 6

self.totalOrder = total
self.save()
return total

def standard_delivery(self):
self.totalOrder = self.get_total() + 3

def express_delivery(self):
self.totalOrder = self.get_total() + 6


class Address(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,
Expand Down
2 changes: 2 additions & 0 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
CheckoutView,
HomeView,
OrderSummaryView,
SearchResult,
add_to_cart,
remove_from_cart,
remove_single_item_from_cart,
Expand All @@ -16,6 +17,7 @@

urlpatterns = [
path('', HomeView.as_view(), name='home'),
path('search/', SearchResult.as_view(), name='search'),
path('checkout/', CheckoutView.as_view(), name='checkout'),
path('order-summary/', OrderSummaryView.as_view(), name='order-summary'),
path('product/<slug>/', ItemDetailView.as_view(), name='product'),
Expand Down
37 changes: 32 additions & 5 deletions core/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import random
import string

import stripe
from django.conf import settings
from django.contrib import messages
Expand All @@ -11,6 +10,7 @@
from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from django.views.generic import ListView, DetailView, View
from django.db.models import Q # New

from .forms import CheckoutForm, CouponForm, RefundForm, PaymentForm
from .models import Item, OrderItem, Order, Address, Payment, Coupon, Refund, UserProfile
Expand All @@ -28,6 +28,18 @@ def products(request):
}
return render(request, "products.html", context)

# Search Function


class SearchResult(ListView):
model = Item
template_name = 'search.html'

def get_queryset(self):
query = self.request.GET.get("query")
# new
return Item.objects.filter(Q(title__icontains=query) | Q(description__icontains=query) | Q(category__icontains=query))


def is_valid_form(values):
valid = True
Expand Down Expand Up @@ -191,6 +203,13 @@ def post(self, *args, **kwargs):
messages.info(
self.request, "Please fill in the required billing address fields")

delivery_option = form.cleaned_data.get(
'delivery_option')
order.delivery_option = delivery_option
order.save()
order.get_total()
print(order.delivery_option)

payment_option = form.cleaned_data.get('payment_option')

if payment_option == 'S':
Expand All @@ -213,7 +232,7 @@ def get(self, *args, **kwargs):
context = {
'order': order,
'DISPLAY_COUPON_FORM': False,
'STRIPE_PUBLIC_KEY' : settings.STRIPE_PUBLIC_KEY
'STRIPE_PUBLIC_KEY': settings.STRIPE_PUBLIC_KEY
}
userprofile = self.request.user.userprofile
if userprofile.one_click_purchasing:
Expand Down Expand Up @@ -290,6 +309,9 @@ def post(self, *args, **kwargs):
order_items = order.items.all()
order_items.update(ordered=True)
for item in order_items:
'''product = item.item
product.stock = product.stock - item.quantity
product.save()'''
item.save()

order.ordered = True
Expand Down Expand Up @@ -383,9 +405,14 @@ def add_to_cart(request, slug):
# check if the order item is in the order
if order.items.filter(item__slug=item.slug).exists():
order_item.quantity += 1
order_item.save()
messages.info(request, "This item quantity was updated.")
return redirect("core:order-summary")
if order_item.quantity > item.stock:
popUp = "Not enough stock for item: " + item.title
messages.error(request, popUp)
return redirect("core:order-summary")
else:
order_item.save()
messages.info(request, "This item quantity was updated.")
return redirect("core:order-summary")
else:
order.items.add(order_item)
messages.info(request, "This item was added to your cart.")
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
16 changes: 15 additions & 1 deletion djecommerce/settings/development.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .base import *

DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1']
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']

INSTALLED_APPS += [
'debug_toolbar'
Expand Down Expand Up @@ -45,3 +45,17 @@ def show_toolbar(request):

STRIPE_PUBLIC_KEY = config('STRIPE_TEST_PUBLIC_KEY')
STRIPE_SECRET_KEY = config('STRIPE_TEST_SECRET_KEY')

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {"class": "logging.StreamHandler"},
},
"loggers": {
"django": {
"handlers": ["console"],
"level": "INFO",
},
}
}
8 changes: 4 additions & 4 deletions static_in_env/css/mdb.min.css

Large diffs are not rendered by default.

39 changes: 37 additions & 2 deletions templates/account/login.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<style>

/* Sign In block */
.row.wow.fadeIn.animated {
margin-top: 60px!important;
}

/* Buttons */

.btn.forgot-password {
background: #b3b3b3!important;
color: #fff!important;
margin-left: 0!important;
margin-right: 0.375rem;
padding-left: 1.5rem;
padding-right: 1.5rem;
border-radius: 0.375rem;
}

.btn.sign-in {
background: #0071bc!important;
color: #fff!important;
margin-right: 0.375rem;
padding-left: 1.5rem;
padding-right: 1.5rem;
border-radius: 0.375rem;
}

</style>
</head>
</html>

{% extends "account/base.html" %}
{% load i18n %}
{% load account socialaccount %}
Expand Down Expand Up @@ -43,8 +78,8 @@ <h1>{% trans "Sign In" %}</h1>
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<a class="btn btn-default" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
<button class="btn btn-primary" type="submit">{% trans "Sign In" %}</button>
<a class="btn forgot-password" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
<button class="btn sign-in" type="submit">{% trans "Sign In" %}</button>
</form>
</div>
</div>
Expand Down
Loading