Skip to content

Commit

Permalink
Updated: backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvind-4 committed Dec 31, 2022
1 parent 11e0140 commit 2b10b6f
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 0 deletions.
Empty file added backend/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions backend/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for backend 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.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

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

application = get_asgi_application()
Empty file added backend/db/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions backend/db/postgres_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from decouple import config

DJANGO_PG_DATABASE = config('DJANGO_PG_DATABASE', cast=str)
DJANGO_PG_USER = config('DJANGO_PG_USER', cast=str)
DJANGO_PG_PASSWORD = config('DJANGO_PG_PASSWORD', cast=str)
DJANGO_PG_HOST = config('DJANGO_PG_HOST', cast=str)
DJANGO_PG_PORT = config('DJANGO_PG_PORT', cast=str, default='')


DB_IS_AVAILABLE = all([
DJANGO_PG_DATABASE,
DJANGO_PG_USER,
DJANGO_PG_PASSWORD,
DJANGO_PG_HOST,
DJANGO_PG_PORT,
])

if DB_IS_AVAILABLE:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': DJANGO_PG_DATABASE,
'USER': DJANGO_PG_USER,
'PASSWORD': DJANGO_PG_PASSWORD,
'HOST': DJANGO_PG_HOST,
'PORT': DJANGO_PG_PORT,
}
}

DATABASES['default']['CONN_MAX_AGE'] = None
DATABASES['default']['ATOMIC_REQUESTS'] = True
9 changes: 9 additions & 0 deletions backend/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from decouple import config

DJANGO_LIVE = config('DJANGO_LIVE', cast=bool)

if DJANGO_LIVE:
from .production import *

else:
from .local import *
107 changes: 107 additions & 0 deletions backend/settings/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""
Django settings for sd project.
Generated by 'django-admin startproject' using Django 3.2.6.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path
from django.contrib.messages import constants as messages

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent

MESSAGE_TAGS = {
messages.DEBUG: 'alert-secondary',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'landing',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'backend.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'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 = 'backend.wsgi.application'

# Password validation
# https://docs.djangoproject.com/en/3.2/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.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Kolkata'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
32 changes: 32 additions & 0 deletions backend/settings/local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from decouple import config

from .base import *

SECRET_KEY = "secret_key"

DEBUG = True

ALLOWED_HOSTS = ['*']

ADMIN_URL = "admin/"

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

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}

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

STATIC_URL = '/static/'

STATICFILES_DIRS = [
BASE_DIR / 'static'
]

STATIC_ROOT = BASE_DIR / 'staticfiles_build' / 'static'
21 changes: 21 additions & 0 deletions backend/settings/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from decouple import config

from .base import *

SECRET_KEY = config('DJANGO_SECRET_KEY', cast=str)

DEBUG = config('DJANGO_DEBUG', cast=bool)

ALLOWED_HOSTS = ['*']

ADMIN_URL = config('DJANGO_ADMIN_URL', cast=str)

STATIC_URL = '/static/'

STATICFILES_DIRS = [
BASE_DIR / 'static'
]

STATIC_ROOT = BASE_DIR / 'staticfiles_build' / 'static'

from backend.db.postgres_db import * # noqa
25 changes: 25 additions & 0 deletions backend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""backend URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.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 django.conf import settings

from landing.views import HomeView

urlpatterns = [
path(str(settings.ADMIN_URL), admin.site.urls),
path('', HomeView.as_view()),
]
16 changes: 16 additions & 0 deletions backend/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for backend 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.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()

0 comments on commit 2b10b6f

Please sign in to comment.