Switch to dockerized postgres
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
# base image
|
||||
FROM python:3.8
|
||||
FROM python:3.9
|
||||
# setup environment variable
|
||||
ENV DockerHOME=/home/app/webapp
|
||||
|
||||
|
@ -2,5 +2,10 @@ django ~= 4.0
|
||||
authlib ~= 1.0
|
||||
python-dotenv ~= 0.19
|
||||
requests ~= 2.27
|
||||
pymongo ~= 3.11
|
||||
dnspython
|
||||
psycopg2
|
||||
#pymongo ~= 3.6
|
||||
#dnspython
|
||||
#mongoengine
|
||||
#djongo
|
||||
#pytz
|
||||
#django-utils-six
|
||||
|
Binary file not shown.
@ -1,6 +1,90 @@
|
||||
from django.shortcuts import render
|
||||
#from django.shortcuts import render
|
||||
#from django.http import HttpResponse
|
||||
|
||||
# Create your views here.
|
||||
|
||||
#def index(request):
|
||||
# return HttpResponse("<h1>Hello and welcome to my first <u>Django App</u> project!</h1>")
|
||||
|
||||
|
||||
import json
|
||||
from authlib.integrations.django_client import OAuth
|
||||
from django.conf import settings
|
||||
from django.shortcuts import redirect, render, redirect
|
||||
from django.urls import reverse
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
import os
|
||||
|
||||
from pymongo.mongo_client import MongoClient
|
||||
from pymongo.server_api import ServerApi
|
||||
from dotenv import load_dotenv, find_dotenv
|
||||
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
|
||||
|
||||
ENV_FILE = find_dotenv()
|
||||
if ENV_FILE:
|
||||
load_dotenv(ENV_FILE)
|
||||
|
||||
MONGO_DB_USERNAME = os.environ.get("MONGO_DB_USERNAME")
|
||||
MONGO_DB_PASSWORD = os.environ.get("MONGO_DB_PASSWORD")
|
||||
MONGO_DB_HOST = os.environ.get("MONGO_DB_HOST")
|
||||
|
||||
#uri = 'mongodb+srv://'+MONGO_DB_USERNAME+':'+MONGO_DB_PASSWORD+'@'+MONGO_DB_HOST+'/?retryWrites=true&w=majority'
|
||||
#client = MongoClient(uri)
|
||||
|
||||
# Send a ping to confirm a successful connection
|
||||
#try:
|
||||
# client.admin.command('ping')
|
||||
# print("Pinged your deployment. You successfully connected to MongoDB!")
|
||||
#except Exception as e:
|
||||
# print(e)
|
||||
|
||||
# AUTH0
|
||||
oauth = OAuth()
|
||||
|
||||
oauth.register(
|
||||
"auth0",
|
||||
client_id=settings.AUTH0_CLIENT_ID,
|
||||
client_secret=settings.AUTH0_CLIENT_SECRET,
|
||||
client_kwargs={
|
||||
"scope": "openid profile email",
|
||||
},
|
||||
server_metadata_url=f"https://{settings.AUTH0_DOMAIN}/.well-known/openid-configuration",
|
||||
)
|
||||
|
||||
def login(request):
|
||||
return oauth.auth0.authorize_redirect(
|
||||
request, request.build_absolute_uri(reverse("callback"))
|
||||
)
|
||||
|
||||
def callback(request):
|
||||
token = oauth.auth0.authorize_access_token(request)
|
||||
request.session["user"] = token
|
||||
return redirect(request.build_absolute_uri(reverse("index")))
|
||||
|
||||
def logout(request):
|
||||
request.session.clear()
|
||||
|
||||
return redirect(
|
||||
f"https://{settings.AUTH0_DOMAIN}/v2/logout?"
|
||||
+ urlencode(
|
||||
{
|
||||
"returnTo": request.build_absolute_uri(reverse("index")),
|
||||
"client_id": settings.AUTH0_CLIENT_ID,
|
||||
},
|
||||
quote_via=quote_plus,
|
||||
),
|
||||
)
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("<h1>Hello and welcome to my first <u>Django App</u> project!</h1>")
|
||||
return render(
|
||||
request,
|
||||
"index.html",
|
||||
context={
|
||||
"session": request.session.get("user"),
|
||||
"pretty": json.dumps(request.session.get("user"), indent=4),
|
||||
},
|
||||
)
|
||||
|
@ -14,6 +14,24 @@ import os
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv, find_dotenv
|
||||
|
||||
# Needed to use mongodb as default 'DATABASES'
|
||||
#import mongoengine, djongo
|
||||
#from pymongo.mongo_client import MongoClient
|
||||
#from pymongo.server_api import ServerApi
|
||||
|
||||
ENV_FILE = find_dotenv()
|
||||
if ENV_FILE:
|
||||
load_dotenv(ENV_FILE)
|
||||
|
||||
#MONGO_DB_USERNAME = os.environ.get("MONGO_DB_USERNAME")
|
||||
#MONGO_DB_PASSWORD = os.environ.get("MONGO_DB_PASSWORD")
|
||||
#MONGO_DB_HOST = os.environ.get("MONGO_DB_HOST")
|
||||
|
||||
#uri = 'mongodb+srv://'+MONGO_DB_USERNAME+':'+MONGO_DB_PASSWORD+'@'+MONGO_DB_HOST+'/?retryWrites=true&w=majority'
|
||||
#mongoengine.connect(db="default", host=uri)
|
||||
#client = MongoClient(uri)
|
||||
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
@ -33,7 +51,7 @@ ALLOWED_HOSTS = ['docker-django', 'localhost', 'seatstock.duckdns.org']
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'djangoapp',
|
||||
'django_mongo',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
@ -88,9 +106,35 @@ WSGI_APPLICATION = 'seatstock_django.wsgi.application'
|
||||
#}
|
||||
|
||||
|
||||
ENV_FILE = find_dotenv()
|
||||
if ENV_FILE:
|
||||
load_dotenv(ENV_FILE)
|
||||
#DATABASES = {
|
||||
# 'default': {
|
||||
# 'ENGINE' : 'djongo',
|
||||
# 'NAME' : 'seatstock',
|
||||
# 'ENFORCE_SCHEMA': False,
|
||||
# 'CLIENT': {
|
||||
# 'host': "mongodb+srv://seatstock:3MSiYdBhf43gPvBa@cluster0.7s1vitu.mongodb.net/?retryWrites=true&w=majority"
|
||||
# }
|
||||
# }
|
||||
#}
|
||||
|
||||
DB_NAME = os.environ.get("DB_NAME")
|
||||
DB_USER = os.environ.get("DB_USER")
|
||||
DB_PASSWORD = os.environ.get("DB_PASSWORD")
|
||||
DB_HOST = os.environ.get("DB_HOST")
|
||||
DB_PORT = os.environ.get("DB_PORT")
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': DB_NAME,
|
||||
'USER': DB_USER,
|
||||
'PASSWORD': DB_PASSWORD,
|
||||
'HOST': DB_HOST,
|
||||
'PORT': DB_PORT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
|
||||
|
@ -21,8 +21,8 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path("",include('django_mongo.urls')),
|
||||
# path("", views.index, name="index"),
|
||||
# path("",include('django_mongo.urls')),
|
||||
path("", views.index, name="index"),
|
||||
path("login", views.login, name="login"),
|
||||
path("logout", views.logout, name="logout"),
|
||||
path("callback", views.callback, name="callback"),
|
||||
|
Reference in New Issue
Block a user