Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Django settings for registrationapps project.
- Generated by 'django-admin startproject' using Django 4.2.2.
- For more information on this file, see
- https://docs.djangoproject.com/en/4.2/topics/settings/
- For the full list of settings and their values, see
- https://docs.djangoproject.com/en/4.2/ref/settings/
- """
- import os
- from pathlib import Path
- from dotenv import load_dotenv
- from django.urls import reverse_lazy
- # Build paths inside the project like this: BASE_DIR / 'subdir'.
- BASE_DIR = Path(__file__).resolve().parent.parent
- # Initialise environment variables
- load_dotenv(BASE_DIR / ".env")
- # Quick-start development settings - unsuitable for production
- # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
- # SECURITY WARNING: keep the secret key used in production secret!
- SECRET_KEY = os.environ.get("SECRET_KEY")
- # SECURITY WARNING: don't run with debug turned on in production!
- DEBUG = os.environ.get("DEBUG", False) in ["1"]
- if DEBUG:
- ALLOWED_HOSTS = []
- else:
- ALLOWED_HOSTS = [
- "https://cloudgeeks.azurewebsites.net",
- "cloudgeeks.azurewebsites.net",
- ]
- CSRF_TRUSTED_ORIGINS = ["https://cloudgeeks.azurewebsites.net"]
- SECURE_SSL_REDIRECT = True
- SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
- # Application definition
- INSTALLED_APPS = [
- "jazzmin",
- "django.contrib.admin",
- "django.contrib.auth",
- "django.contrib.contenttypes",
- "django.contrib.sessions",
- "django.contrib.messages",
- "django.contrib.staticfiles",
- "studentregistration.apps.StudentregistrationConfig",
- "users.apps.UsersConfig",
- "crispy_forms",
- "crispy_bootstrap4",
- "rest_framework",
- "drf_yasg",
- "storages",
- ]
- 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",
- # our custom middleware has to come after AuthenticationMiddleware
- "registrationapps.middleware.RedirectLoggedInMiddleware",
- "django.contrib.messages.middleware.MessageMiddleware",
- "django.middleware.clickjacking.XFrameOptionsMiddleware",
- ]
- ROOT_URLCONF = "registrationapps.urls"
- TEMPLATES = [
- {
- "BACKEND": "django.template.backends.django.DjangoTemplates",
- "DIRS": [],
- "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 = "registrationapps.wsgi.application"
- # Database
- # https://docs.djangoproject.com/en/4.2/ref/settings/#databases
- if DEBUG:
- DATABASES = {
- "default": {
- "ENGINE": "django.db.backends.sqlite3",
- "NAME": BASE_DIR / "db.sqlite3",
- }
- }
- else:
- DATABASES = {
- "default": {
- "ENGINE": "django.db.backends.mysql",
- "NAME": os.environ.get("AZURE_DB_NAME"),
- "HOST": os.environ.get("AZURE_DB_HOST"),
- "PORT": os.environ.get("AZURE_DB_PORT"),
- "USER": os.environ.get("AZURE_DB_USER"),
- "PASSWORD": os.environ.get("AZURE_DB_PASSWORD"),
- }
- }
- # Password validation
- # https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/
- LANGUAGE_CODE = "en-us"
- TIME_ZONE = "UTC"
- USE_I18N = True
- USE_TZ = True
- # Static files (CSS, JavaScript, Images)
- # https://docs.djangoproject.com/en/4.2/howto/static-files/
- if DEBUG:
- STATIC_URL = "static/"
- MEDIA_ROOT = BASE_DIR / "media"
- MEDIA_URL = "/media/"
- else:
- MEDIA_URL = (
- f"https://{os.environ.get('AZURE_SA_NAME')}.blob.core.windows.net/media/"
- )
- STATIC_URL = (
- f"https://{os.environ.get('AZURE_SA_NAME')}.blob.core.windows.net/static/"
- )
- DEFAULT_FILE_STORAGE = "registrationapps.storages.AzureMediaStorage"
- STATICFILES_STORAGE = "registrationapps.storages.AzureStaticStorage"
- AZURE_SA_NAME = os.environ.get("AZURE_SA_NAME")
- AZURE_SA_KEY = os.environ.get("AZURE_SA_KEY")
- STATIC_ROOT = BASE_DIR / "staticfiles"
- MEDIA_ROOT = BASE_DIR / "mediafiles"
- # Default primary key field type
- # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
- DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
- # django-crispy-forms
- # https://django-crispy-forms.readthedocs.io/en/latest/
- CRISPY_ALLOWED_TEMPLATE_PACK = "bootstrap4"
- CRISPY_TEMPLATE_PACK = "bootstrap4"
- # Jazzmin Configuration
- # https://django-jazzmin.readthedocs.io/installation/
- JAZZMIN_SETTINGS = {
- "site_title": "CloudGeeks Admin",
- "site_brand": "Cloud Geeks Admin",
- "site_header": "Cloud Geeks Admin",
- "welcome_sign": "Welcome to Cloud Geeks University",
- "copyright": "Cloud Geeks",
- }
- JAZZMIN_UI_TWEAKS = {
- "theme": "flatly",
- "dark_mode_theme": "solar",
- }
- # Redirect to the student dashboard after login
- LOGIN_REDIRECT_URL = "dashboard"
- # Required to redirect user when they hit login_required page
- LOGIN_URL = reverse_lazy("login")
- # Email Settings
- # https://docs.djangoproject.com/en/4.2/topics/email/
- EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
- EMAIL_HOST = "smtp.gmail.com"
- EMAIL_PORT = 587
- EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
- EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
- EMAIL_USE_TLS = True
- RECIPIENTS = [
- EMAIL_HOST_USER,
- "themaleem@gmail.com",
- "charityodoh75@gmail.com",
- ]
- # Google Books API
- GOOGLE_BOOKS_API_URL = os.environ.get("GOOGLE_BOOKS_API_URL")
- GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
- from storages.backends.azure_storage import AzureStorage
- from .settings import AZURE_SA_KEY, AZURE_SA_NAME
- class AzureMediaStorage(AzureStorage):
- """
- Custom storage backend for Azure Blob Storage tailored for media files.
- This class is intended to handle the storage of uploaded media files such as
- profile pictures on Azure Blob Storage.
- Attributes:
- - account_name: The name of the Azure Blob Storage account.
- - account_key: The authentication key for the Azure Blob Storage account.
- - azure_container: The container to store files.
- - expiration_secs: Duration (in seconds) after which a signed URL will expire. None indicates no expiration.
- """
- account_name = AZURE_SA_NAME
- account_key = AZURE_SA_KEY
- azure_container = "media"
- expiration_secs = None
- class AzureStaticStorage(AzureStorage):
- """
- Custom storage backend for Azure Blob Storage to handle the storage of application static files
- Attributes:
- - account_name: The name of the Azure Blob Storage account.
- - account_key: The authentication key for the Azure Blob Storage account.
- - azure_container: The container to store files.
- - expiration_secs: Duration (in seconds) after which a signed URL will expire. None indicates no expiration.
- """
- account_name = AZURE_SA_NAME
- account_key = AZURE_SA_KEY
- azure_container = "static"
- expiration_secs = None
- AZURE_DB_HOST=xxxx.mysql.database.azure.com
- AZURE_DB_USER=xxxx
- AZURE_DB_PASSWORD=xxxxx
- AZURE_DB_PORT=3306
- AZURE_DB_NAME=xxxxx
- AZURE_SA_KEY=xxxxx
- AZURE_SA_NAME=xx
- EMAIL_HOST_PASSWORD=xx
- EMAIL_HOST_USER=xx
- GOOGLE_API_KEY=xx
- GOOGLE_BOOKS_API_URL=xx
- SECRET_KEY=xx
- SECURE_SSL_REDIRECT=xx
- DEBUG=1
- azure-core==1.28.0
- azure-storage-blob==12.17.0
- django-storages==1.13.2
- isodate==0.6.1
- mysqlclient==2.1.1
- whitenoise==6.5.0
- python-dotenv==1.0.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement