Advertisement
themaleem

deploy setting.js

Aug 4th, 2023 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.39 KB | None | 0 0
  1. """
  2. Django settings for registrationapps project.
  3.  
  4. Generated by 'django-admin startproject' using Django 4.2.2.
  5.  
  6. For more information on this file, see
  7. https://docs.djangoproject.com/en/4.2/topics/settings/
  8.  
  9. For the full list of settings and their values, see
  10. https://docs.djangoproject.com/en/4.2/ref/settings/
  11. """
  12.  
  13. import os
  14. from pathlib import Path
  15. from dotenv import load_dotenv
  16. from django.urls import reverse_lazy
  17.  
  18. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  19. BASE_DIR = Path(__file__).resolve().parent.parent
  20.  
  21. # Initialise environment variables
  22. load_dotenv(BASE_DIR / ".env")
  23.  
  24. # Quick-start development settings - unsuitable for production
  25. # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
  26.  
  27. # SECURITY WARNING: keep the secret key used in production secret!
  28. SECRET_KEY = os.environ.get("SECRET_KEY")
  29.  
  30.  
  31. # SECURITY WARNING: don't run with debug turned on in production!
  32. DEBUG = os.environ.get("DEBUG", False) in ["1"]
  33.  
  34. if DEBUG:
  35. ALLOWED_HOSTS = []
  36. else:
  37. ALLOWED_HOSTS = [
  38. "https://cloudgeeks.azurewebsites.net",
  39. "cloudgeeks.azurewebsites.net",
  40. ]
  41. CSRF_TRUSTED_ORIGINS = ["https://cloudgeeks.azurewebsites.net"]
  42. SECURE_SSL_REDIRECT = True
  43. SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
  44.  
  45.  
  46. # Application definition
  47.  
  48. INSTALLED_APPS = [
  49. "jazzmin",
  50. "django.contrib.admin",
  51. "django.contrib.auth",
  52. "django.contrib.contenttypes",
  53. "django.contrib.sessions",
  54. "django.contrib.messages",
  55. "django.contrib.staticfiles",
  56. "studentregistration.apps.StudentregistrationConfig",
  57. "users.apps.UsersConfig",
  58. "crispy_forms",
  59. "crispy_bootstrap4",
  60. "rest_framework",
  61. "drf_yasg",
  62. "storages",
  63. ]
  64.  
  65.  
  66. MIDDLEWARE = [
  67. "django.middleware.security.SecurityMiddleware",
  68. "whitenoise.middleware.WhiteNoiseMiddleware",
  69. "django.contrib.sessions.middleware.SessionMiddleware",
  70. "django.middleware.common.CommonMiddleware",
  71. "django.middleware.csrf.CsrfViewMiddleware",
  72. "django.contrib.auth.middleware.AuthenticationMiddleware",
  73. # our custom middleware has to come after AuthenticationMiddleware
  74. "registrationapps.middleware.RedirectLoggedInMiddleware",
  75. "django.contrib.messages.middleware.MessageMiddleware",
  76. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  77. ]
  78.  
  79. ROOT_URLCONF = "registrationapps.urls"
  80.  
  81. TEMPLATES = [
  82. {
  83. "BACKEND": "django.template.backends.django.DjangoTemplates",
  84. "DIRS": [],
  85. "APP_DIRS": True,
  86. "OPTIONS": {
  87. "context_processors": [
  88. "django.template.context_processors.debug",
  89. "django.template.context_processors.request",
  90. "django.contrib.auth.context_processors.auth",
  91. "django.contrib.messages.context_processors.messages",
  92. ],
  93. },
  94. },
  95. ]
  96.  
  97. WSGI_APPLICATION = "registrationapps.wsgi.application"
  98.  
  99. # Database
  100. # https://docs.djangoproject.com/en/4.2/ref/settings/#databases
  101.  
  102. if DEBUG:
  103. DATABASES = {
  104. "default": {
  105. "ENGINE": "django.db.backends.sqlite3",
  106. "NAME": BASE_DIR / "db.sqlite3",
  107. }
  108. }
  109. else:
  110. DATABASES = {
  111. "default": {
  112. "ENGINE": "django.db.backends.mysql",
  113. "NAME": os.environ.get("AZURE_DB_NAME"),
  114. "HOST": os.environ.get("AZURE_DB_HOST"),
  115. "PORT": os.environ.get("AZURE_DB_PORT"),
  116. "USER": os.environ.get("AZURE_DB_USER"),
  117. "PASSWORD": os.environ.get("AZURE_DB_PASSWORD"),
  118. }
  119. }
  120.  
  121. # Password validation
  122. # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
  123.  
  124. AUTH_PASSWORD_VALIDATORS = [
  125. {
  126. "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  127. },
  128. {
  129. "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
  130. },
  131. {
  132. "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
  133. },
  134. {
  135. "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
  136. },
  137. ]
  138.  
  139. # Internationalization
  140. # https://docs.djangoproject.com/en/4.2/topics/i18n/
  141.  
  142. LANGUAGE_CODE = "en-us"
  143.  
  144. TIME_ZONE = "UTC"
  145.  
  146. USE_I18N = True
  147.  
  148. USE_TZ = True
  149.  
  150. # Static files (CSS, JavaScript, Images)
  151. # https://docs.djangoproject.com/en/4.2/howto/static-files/
  152. if DEBUG:
  153. STATIC_URL = "static/"
  154. MEDIA_ROOT = BASE_DIR / "media"
  155. MEDIA_URL = "/media/"
  156. else:
  157. MEDIA_URL = (
  158. f"https://{os.environ.get('AZURE_SA_NAME')}.blob.core.windows.net/media/"
  159. )
  160. STATIC_URL = (
  161. f"https://{os.environ.get('AZURE_SA_NAME')}.blob.core.windows.net/static/"
  162. )
  163. DEFAULT_FILE_STORAGE = "registrationapps.storages.AzureMediaStorage"
  164. STATICFILES_STORAGE = "registrationapps.storages.AzureStaticStorage"
  165. AZURE_SA_NAME = os.environ.get("AZURE_SA_NAME")
  166. AZURE_SA_KEY = os.environ.get("AZURE_SA_KEY")
  167. STATIC_ROOT = BASE_DIR / "staticfiles"
  168. MEDIA_ROOT = BASE_DIR / "mediafiles"
  169.  
  170.  
  171. # Default primary key field type
  172. # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
  173.  
  174. DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
  175.  
  176. # django-crispy-forms
  177. # https://django-crispy-forms.readthedocs.io/en/latest/
  178.  
  179. CRISPY_ALLOWED_TEMPLATE_PACK = "bootstrap4"
  180. CRISPY_TEMPLATE_PACK = "bootstrap4"
  181.  
  182. # Jazzmin Configuration
  183. # https://django-jazzmin.readthedocs.io/installation/
  184.  
  185. JAZZMIN_SETTINGS = {
  186. "site_title": "CloudGeeks Admin",
  187. "site_brand": "Cloud Geeks Admin",
  188. "site_header": "Cloud Geeks Admin",
  189. "welcome_sign": "Welcome to Cloud Geeks University",
  190. "copyright": "Cloud Geeks",
  191. }
  192.  
  193. JAZZMIN_UI_TWEAKS = {
  194. "theme": "flatly",
  195. "dark_mode_theme": "solar",
  196. }
  197.  
  198. # Redirect to the student dashboard after login
  199. LOGIN_REDIRECT_URL = "dashboard"
  200.  
  201. # Required to redirect user when they hit login_required page
  202. LOGIN_URL = reverse_lazy("login")
  203.  
  204. # Email Settings
  205. # https://docs.djangoproject.com/en/4.2/topics/email/
  206. EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
  207. EMAIL_HOST = "smtp.gmail.com"
  208. EMAIL_PORT = 587
  209. EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER")
  210. EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD")
  211. EMAIL_USE_TLS = True
  212.  
  213. RECIPIENTS = [
  214. EMAIL_HOST_USER,
  215. "themaleem@gmail.com",
  216. "charityodoh75@gmail.com",
  217. ]
  218.  
  219. # Google Books API
  220. GOOGLE_BOOKS_API_URL = os.environ.get("GOOGLE_BOOKS_API_URL")
  221. GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230. from storages.backends.azure_storage import AzureStorage
  231.  
  232. from .settings import AZURE_SA_KEY, AZURE_SA_NAME
  233.  
  234.  
  235. class AzureMediaStorage(AzureStorage):
  236. """
  237. Custom storage backend for Azure Blob Storage tailored for media files.
  238.  
  239. This class is intended to handle the storage of uploaded media files such as
  240. profile pictures on Azure Blob Storage.
  241.  
  242. Attributes:
  243. - account_name: The name of the Azure Blob Storage account.
  244. - account_key: The authentication key for the Azure Blob Storage account.
  245. - azure_container: The container to store files.
  246. - expiration_secs: Duration (in seconds) after which a signed URL will expire. None indicates no expiration.
  247. """
  248.  
  249. account_name = AZURE_SA_NAME
  250. account_key = AZURE_SA_KEY
  251. azure_container = "media"
  252. expiration_secs = None
  253.  
  254.  
  255. class AzureStaticStorage(AzureStorage):
  256. """
  257. Custom storage backend for Azure Blob Storage to handle the storage of application static files
  258.  
  259. Attributes:
  260. - account_name: The name of the Azure Blob Storage account.
  261. - account_key: The authentication key for the Azure Blob Storage account.
  262. - azure_container: The container to store files.
  263. - expiration_secs: Duration (in seconds) after which a signed URL will expire. None indicates no expiration.
  264. """
  265.  
  266. account_name = AZURE_SA_NAME
  267. account_key = AZURE_SA_KEY
  268. azure_container = "static"
  269. expiration_secs = None
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276. AZURE_DB_HOST=xxxx.mysql.database.azure.com
  277. AZURE_DB_USER=xxxx
  278. AZURE_DB_PASSWORD=xxxxx
  279. AZURE_DB_PORT=3306
  280. AZURE_DB_NAME=xxxxx
  281.  
  282. AZURE_SA_KEY=xxxxx
  283. AZURE_SA_NAME=xx
  284. EMAIL_HOST_PASSWORD=xx
  285. EMAIL_HOST_USER=xx
  286. GOOGLE_API_KEY=xx
  287. GOOGLE_BOOKS_API_URL=xx
  288.  
  289. SECRET_KEY=xx
  290. SECURE_SSL_REDIRECT=xx
  291. DEBUG=1
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. azure-core==1.28.0
  299. azure-storage-blob==12.17.0
  300. django-storages==1.13.2
  301. isodate==0.6.1
  302. mysqlclient==2.1.1
  303. whitenoise==6.5.0
  304. python-dotenv==1.0.0
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement