Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DBHOST=postgres
DBPORT=5432
SECRET_KEY=django-insecure-ys)is-uls_$yaa(f%iyy^^7pe4a@ql)3thr9loszz#!8l4m4fk
PRODUCTION=false
WEBSITE_HOSTNAME=""
ALLOWED_HOSTS=""

# Celery env
CACHELOCATION=redis://redis:6379/0
Expand Down
3 changes: 0 additions & 3 deletions api/admin.py

This file was deleted.

1 change: 0 additions & 1 deletion api/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import math

from django.contrib.auth.models import User
Expand Down
3 changes: 0 additions & 3 deletions api/tests.py

This file was deleted.

1 change: 0 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.db.models import F, Max
from django.shortcuts import get_object_or_404
from rest_framework import generics, permissions, status
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.views import APIView
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion core/asgi.py → config/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

application = get_asgi_application()
File renamed without changes.
50 changes: 35 additions & 15 deletions core/settings.py → config/django/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

import os
from pathlib import Path
from config.env import env

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -21,20 +21,19 @@
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("SECRET_KEY")
SECRET_KEY = env.str("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["localhost", "127.0.0.1", ".ngrok-free.app", "*"]
ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
"api",
"corsheaders",
"django_celery_results",
"rest_framework",
"knox",
"django.contrib.admin",
Expand Down Expand Up @@ -71,7 +70,7 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "core.urls"
ROOT_URLCONF = "config.urls"

TEMPLATES = [
{
Expand All @@ -89,29 +88,30 @@
},
]

WSGI_APPLICATION = "core.wsgi.application"
WSGI_APPLICATION = "config.wsgi.application"


# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
# Configure Postgres database based on connection string of the libpq Keyword/Value form
# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING

DATABASES = {
"default": {
"ENGINE": os.environ.get("DBENGINE"),
"NAME": os.environ.get("DBNAME"),
"HOST": os.environ.get("DBHOST"),
"USER": os.environ.get("DBUSER"),
"PASSWORD": os.environ.get("DBPASS"),
"PORT": os.environ.get("DBPORT"),
"ENGINE": env.str("DBENGINE"),
"NAME": env.str("DBNAME"),
"HOST": env.str("DBHOST"),
"USER": env.str("DBUSER"),
"PASSWORD": env.str("DBPASS"),
}
}


CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": os.environ.get("CACHELOCATION"),
"LOCATION": env.str("CACHELOCATION"),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"COMPRESSOR": "django_redis.compressors.zlib.ZlibCompressor",
},
}
}
Expand Down Expand Up @@ -158,3 +158,23 @@
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "app"},
},
"root": {
"handlers": ["console"],
"level": "INFO",
},
"formatters": {
"app": {
"format": (
"%(asctime)s [%(levelname)-8s] " "(%(module)s.%(funcName)s) %(message)s"
),
"datefmt": "%Y-%m-%d %H:%M:%S",
},
},
}
11 changes: 11 additions & 0 deletions config/django/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .base import * # noqa
from config.env import env

DEBUG = False

# Configure the domain name using the environment variable
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS") + [
"127.0.0.1"
] # localhost required for docker health checks

CSRF_TRUSTED_ORIGINS = [f"https://{host}/" for host in ALLOWED_HOSTS]
3 changes: 3 additions & 0 deletions config/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import environ

env = environ.Env()
File renamed without changes.
2 changes: 1 addition & 1 deletion core/wsgi.py → config/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

application = get_wsgi_application()
61 changes: 0 additions & 61 deletions core/production.py

This file was deleted.

4 changes: 2 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def main():
# If Website is hosted, use the production settings
if os.environ.get("PRODUCTION") == "true":
logging.info("Production settings loaded")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.production")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.django.production")
else:
logging.info("Development settings loaded")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.django.base")

try:
from django.core.management import execute_from_command_line
Expand Down
91 changes: 4 additions & 87 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,101 +1,18 @@
amqp==5.2.0
asgiref==3.7.2
billiard==4.2.0
celery==5.3.6
click==8.1.7
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.3.0
conditional==1.5
Django==5.0.1
django-celery-results==2.5.1
django-clone==5.3.3
django-cors-headers==4.3.1
django-redis==5.4.0
djangorestframework==3.14.0
kombu==5.3.5
prompt-toolkit==3.0.43
psycopg==3.1.17
psycopg2-binary==2.9.9
pyngrok==7.1.0
python-dateutil==2.8.2
python-dotenv==1.0.1
pytz==2023.3.post1
PyYAML==6.0.1
redis==5.0.1
six==1.16.0
sqlparse==0.4.4
typing_extensions==4.9.0
tzdata==2023.4
vine==5.1.0
wcwidth==0.2.13
amqp==5.2.0
asgiref==3.7.2
async-timeout==4.0.3
billiard==4.2.0
celery==5.3.6
click==8.1.7
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.3.0
conditional==1.5
Django==5.0.1
django-celery-results==2.5.1
django-clone==5.3.3
django-cors-headers==4.3.1
django-redis==5.4.0
djangorestframework==3.14.0
gunicorn==21.2.0
kombu==5.3.5
packaging==24.0
prompt-toolkit==3.0.43
psycopg==3.1.17
psycopg2-binary==2.9.9
pyngrok==7.1.0
python-dateutil==2.8.2
python-dotenv==1.0.1
pytz==2023.3.post1
PyYAML==6.0.1
redis==5.0.1
six==1.16.0
sqlparse==0.4.4
typing_extensions==4.9.0
tzdata==2023.4
vine==5.1.0
wcwidth==0.2.13
amqp==5.2.0
asgiref==3.7.2
async-timeout==4.0.3
billiard==4.2.0
celery==5.3.6
click==8.1.7
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.3.0
conditional==1.5
Django==5.0.1
django-celery-results==2.5.1
django-clone==5.3.3
django-cors-headers==4.3.1
django-environ==0.12.0
django-health-check==3.18.3
django-redis==5.4.0
django-rest-knox==5.0.2
djangorestframework==3.14.0
gunicorn==21.2.0
kombu==5.3.5
packaging==24.0
prompt-toolkit==3.0.43
psycopg==3.1.17
psycopg2-binary==2.9.9
pyngrok==7.1.0
python-dateutil==2.8.2
python-dotenv==1.0.1
pytz==2023.3.post1
PyYAML==6.0.1
redis==5.0.1
setuptools==72.1.0
six==1.16.0
sqlparse==0.4.4
typing_extensions==4.9.0
tzdata==2023.4
vine==5.1.0
wcwidth==0.2.13
django-rest-knox==5.0.2
django-health-check==3.18.3
5 changes: 2 additions & 3 deletions tasks/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from celery import Celery

if os.environ.get("PRODUCTION") == "true":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.production")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.django.production")
broker_url = os.getenv("BROKERLOCATION")
else:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.django.base")
broker_url = os.getenv("BROKERLOCATION")


Expand All @@ -17,7 +17,6 @@
app = Celery("tasks")
app.conf.timezone = "Asia/Kolkata"
app.conf.broker_url = broker_url
app.conf.result_backend = "django-db"


@app.task
Expand Down