Skip to content

Commit

Permalink
[Refactor] Django config and dependency updates for API Rewrite
Browse files Browse the repository at this point in the history
Changes completed in this commit are as follows -
1. Updated Pipfile.lock to update the major dependency versions
2. Removed extra dependencies (will add them as and when required)
3. Updated config files with adherence to the current Django version
4. Removed existing Django code to enable a complete API rewrite
5. Upgraded pre-commit hook versions to their latest tags/refs
6. Added `.env.example` file

Signed-off-by: Saurav Shrivastav <[email protected]>
  • Loading branch information
Saurav-Shrivastav committed Nov 11, 2021
1 parent 8bc5df8 commit f94dfb4
Show file tree
Hide file tree
Showing 150 changed files with 256 additions and 2,890 deletions.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For development
SECRET_KEY=<your-secret-key>
DEBUG=True

# For production
EMAIL_HOST_USER=<host-email>
EMAIL_HOST_PASSWORD=<host-password>
# If GCloud Storage is being used:
GS_BUCKET_NAME=<bucket-name>
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/prettier/prettier
rev: 1.19.1
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.4.1
hooks:
- id: prettier
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.10b0
hooks:
- id: black
language_version: python3.8
10 changes: 0 additions & 10 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@ verify_ssl = true

[packages]
django = "*"
django-cleanup = "*"
django-cors-headers = "*"
django-environ = "*"
django-filter = "*"
djangorestframework = "*"
markdown = "*"
pillow = "*"
pre-commit = "*"
requests = "*"
protobuf = "*"
google-cloud-storage = "*"
django-storages = {extras = ["google"], version = "1.10.1"}

[requires]
python_version = "3.8"
611 changes: 181 additions & 430 deletions Pipfile.lock

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions manage.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

if __name__ == "__main__":
os.environ["DJANGO_SETTINGS_MODULE"] = "officialWebsite.config.settings"

def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "officialWebsite.config.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -13,3 +16,7 @@
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
Empty file removed officialWebsite/__init__.py
Empty file.
Empty file.
6 changes: 0 additions & 6 deletions officialWebsite/achievement/admin.py

This file was deleted.

5 changes: 0 additions & 5 deletions officialWebsite/achievement/apps.py

This file was deleted.

40 changes: 0 additions & 40 deletions officialWebsite/achievement/migrations/0001_initial.py

This file was deleted.

Empty file.
14 changes: 0 additions & 14 deletions officialWebsite/achievement/models.py

This file was deleted.

14 changes: 0 additions & 14 deletions officialWebsite/achievement/serializers.py

This file was deleted.

3 changes: 0 additions & 3 deletions officialWebsite/achievement/tests.py

This file was deleted.

7 changes: 0 additions & 7 deletions officialWebsite/achievement/urls.py

This file was deleted.

11 changes: 0 additions & 11 deletions officialWebsite/achievement/views.py

This file was deleted.

16 changes: 16 additions & 0 deletions officialWebsite/config/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for officialWebsite 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", "officialWebsite.config.settings")

application = get_asgi_application()
60 changes: 31 additions & 29 deletions officialWebsite/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
import os
from pathlib import Path
import environ
import os

env = environ.Env()

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


environ.Env.read_env(env_file=os.path.join(BASE_DIR, "../.env"))

SECRET_KEY = env(
"SECRET_KEY",
default="secret-key-of-at-least-50-characters-to-pass-check-deploy",
default="really-secret-secret-key-but-who-cares?",
)

DEBUG = env.bool("DEBUG", default=True)

ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# 3rd Party Applications
"corsheaders",
"rest_framework",
"rest_framework.authtoken",
"django_cleanup",
# Backend Apps
"officialWebsite.achievement",
"officialWebsite.contact",
"officialWebsite.events",
"officialWebsite.faq",
"officialWebsite.members",
"officialWebsite.projects",
"officialWebsite.sponsor",
"officialWebsite.team",
"officialWebsite.resources",
"officialWebsite.podcast",
]

MIDDLEWARE = [
Expand All @@ -51,16 +39,14 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
]

ROOT_URLCONF = "officialWebsite.config.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [TEMPLATE_DIR],
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand All @@ -76,13 +62,20 @@
WSGI_APPLICATION = "officialWebsite.config.wsgi.application"


# Database
# https://docs.djangoproject.com/en/3.2/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/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
Expand All @@ -98,6 +91,10 @@
},
]


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

LANGUAGE_CODE = "en-us"

TIME_ZONE = "Asia/Kolkata"
Expand All @@ -106,7 +103,8 @@

USE_L10N = True

USE_TZ = False
USE_TZ = True


if DEBUG:
STATIC_URL = "/static/"
Expand All @@ -115,9 +113,10 @@
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
else:
DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
STATICFILES_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
GS_BUCKET_NAME = env("GS_BUCKET_NAME")
# cloud storage settings
# DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
# STATICFILES_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
# GS_BUCKET_NAME = env("GS_BUCKET_NAME")
STATIC_ROOT = "static/"
MEDIA_ROOT = "media/"

Expand All @@ -131,4 +130,7 @@
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")


CORS_ORIGIN_ALLOW_ALL = 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"
Loading

0 comments on commit f94dfb4

Please sign in to comment.