Skip to content

Commit

Permalink
Finished project
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfreire committed Feb 10, 2021
1 parent 77822cb commit 5c4cfa4
Show file tree
Hide file tree
Showing 20 changed files with 619 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,6 @@ django_tutorial/media/

.pytest_cache/

.env
.env

ngrok
Binary file modified db.sqlite3
Binary file not shown.
16 changes: 16 additions & 0 deletions djstripetut/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for djstripetut 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.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djstripetut.settings')

application = get_asgi_application()
35 changes: 21 additions & 14 deletions djstripetut/settings.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
"""
Django settings for djstripetut project.
Generated by 'django-admin startproject' using Django 2.2.2.
Generated by 'django-admin startproject' using Django 3.1.6.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'd=tim8=1l-af!hj_vq+vg*1q3!3422z76)j+g0*olu&$1vs3js'
SECRET_KEY = 'xy7vyv5c4tk+-d8i7-em61gm-tm0(=t0(0i%(lizeu2nhu_5ow'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -37,6 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'products'
]

MIDDLEWARE = [
Expand All @@ -54,7 +55,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -71,18 +72,18 @@


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -99,9 +100,11 @@
},
]

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

Expand All @@ -115,6 +118,10 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

STRIPE_PUBLIC_KEY = ""
STRIPE_SECRET_KEY = ""
STRIPE_WEBHOOK_SECRET = ""
29 changes: 14 additions & 15 deletions djstripetut/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
"""djstripetut URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/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 path
from products.views import (
CreateCheckoutSessionView,
ProductLandingPageView,
SuccessView,
CancelView,
stripe_webhook,
StripeIntentView
)

urlpatterns = [
path('admin/', admin.site.urls),
path('create-payment-intent/<pk>/', StripeIntentView.as_view(), name='create-payment-intent'),
path('webhooks/stripe/', stripe_webhook, name='stripe-webhook'),
path('cancel/', CancelView.as_view(), name='cancel'),
path('success/', SuccessView.as_view(), name='success'),
path('', ProductLandingPageView.as_view(), name='landing-page'),
path('create-checkout-session/<pk>/', CreateCheckoutSessionView.as_view(), name='create-checkout-session')
]
2 changes: 1 addition & 1 deletion djstripetut/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""

import os
Expand Down
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djstripetut.settings')
try:
from django.core.management import execute_from_command_line
Expand Down
Empty file added products/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions products/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Product


admin.site.register(Product)
5 changes: 5 additions & 0 deletions products/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ProductsConfig(AppConfig):
name = 'products'
22 changes: 22 additions & 0 deletions products/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.1.6 on 2021-02-10 09:36

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('price', models.IntegerField(default=0)),
],
),
]
24 changes: 24 additions & 0 deletions products/migrations/0002_auto_20210210_1400.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.1.6 on 2021-02-10 14:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('products', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='product',
name='file',
field=models.FileField(blank=True, null=True, upload_to='product_files/'),
),
migrations.AddField(
model_name='product',
name='url',
field=models.URLField(default='https://google.com'),
preserve_default=False,
),
]
Empty file added products/migrations/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions products/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.db import models


class Product(models.Model):
name = models.CharField(max_length=100)
price = models.IntegerField(default=0) # cents
file = models.FileField(upload_to="product_files/", blank=True, null=True)
url = models.URLField()

def __str__(self):
return self.name

def get_display_price(self):
return "{0:.2f}".format(self.price / 100)
3 changes: 3 additions & 0 deletions products/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Loading

0 comments on commit 5c4cfa4

Please sign in to comment.