Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.py 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. """
  2. Django settings for mysite project.
  3. Generated by 'django-admin startproject' using Django 2.0.6.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/2.0/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/2.0/ref/settings/
  8. """
  9. import os
  10. import re
  11. import socket
  12. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  13. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  14. # Quick-start development settings - unsuitable for production
  15. # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
  16. # SECURITY WARNING: keep the secret key used in production secret!
  17. SECRET_KEY = 'rh2cynsps7=3fb-bmb!+6g(!a(j5i3dq54ps08y2^py8z*49ct'
  18. # SECURITY WARNING: don't run with debug turned on in production!
  19. DEBUG = True
  20. ALLOWED_HOSTS = []
  21. # Development or Production
  22. r = re.search(r'^172.17', socket.gethostbyname(socket.gethostname()))
  23. DEVELOPMENT = (r == None)
  24. # Application definition
  25. INSTALLED_APPS = [
  26. 'django.contrib.admin',
  27. 'django.contrib.auth',
  28. 'django.contrib.contenttypes',
  29. 'django.contrib.sessions',
  30. 'django.contrib.messages',
  31. 'django.contrib.staticfiles',
  32. 'application',
  33. 'taggit',
  34. 'taggit_templatetags2',
  35. 'kombu.transport.django',
  36. ]
  37. MIDDLEWARE = [
  38. 'django.middleware.security.SecurityMiddleware',
  39. 'django.contrib.sessions.middleware.SessionMiddleware',
  40. 'django.middleware.common.CommonMiddleware',
  41. 'django.middleware.csrf.CsrfViewMiddleware',
  42. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  43. 'django.contrib.messages.middleware.MessageMiddleware',
  44. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  45. ]
  46. ROOT_URLCONF = 'mysite.urls'
  47. TEMPLATES = [
  48. {
  49. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  50. 'DIRS': [],
  51. 'APP_DIRS': True,
  52. 'OPTIONS': {
  53. 'context_processors': [
  54. 'django.template.context_processors.debug',
  55. 'django.template.context_processors.request',
  56. 'django.contrib.auth.context_processors.auth',
  57. 'django.contrib.messages.context_processors.messages',
  58. ],
  59. },
  60. },
  61. ]
  62. WSGI_APPLICATION = 'mysite.wsgi.application'
  63. # Database
  64. # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
  65. if DEVELOPMENT:
  66. DATABASES = {
  67. 'default': {
  68. 'ENGINE': 'django.db.backends.sqlite3',
  69. 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  70. }
  71. }
  72. print(" --- Development sqlite database --- ")
  73. else:
  74. DATABASES = {
  75. 'default': {
  76. 'ENGINE': 'django.db.backends.mysql',
  77. 'NAME': 'django-app',
  78. 'USER': 'django-app',
  79. 'PASSWORD': '*******',
  80. 'HOST': 'mysql',
  81. 'PORT': '3306',
  82. 'OPTIONS': {
  83. 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
  84. },
  85. }
  86. }
  87. # Password validation
  88. # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
  89. AUTH_PASSWORD_VALIDATORS = [
  90. {
  91. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  92. },
  93. {
  94. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  95. },
  96. {
  97. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  98. },
  99. {
  100. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  101. },
  102. ]
  103. # Internationalization
  104. # https://docs.djangoproject.com/en/2.0/topics/i18n/
  105. LANGUAGE_CODE = 'en-us'
  106. TIME_ZONE = 'Europe/Berlin'
  107. USE_I18N = True
  108. USE_L10N = True
  109. USE_TZ = True
  110. # Static files (CSS, JavaScript, Images)
  111. # https://docs.djangoproject.com/en/2.0/howto/static-files/
  112. STATIC_URL = '/static/'
  113. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  114. # Konfiguration des Auth-Systems
  115. LDAP_DOMAIN = 'ADS1'
  116. LDAP_SERVER = 'gso1.ads1.fh-nuernberg.de'
  117. if DEVELOPMENT:
  118. LOGIN_REDIRECT_URL = '/'
  119. LOGOUT_REDIRECT_URL = '/'
  120. LOGIN_URL = "/accounts/login/"
  121. else:
  122. LOGIN_REDIRECT_URL = '/app/'
  123. LOGOUT_REDIRECT_URL = '/app/'
  124. LOGIN_URL = "/app/accounts/login/"
  125. if DEVELOPMENT:
  126. AUTHENTICATION_BACKENDS = [
  127. 'django.contrib.auth.backends.ModelBackend',
  128. ]
  129. print(" --- Development stage --- ")
  130. else:
  131. AUTHENTICATION_BACKENDS = [
  132. 'django.contrib.auth.backends.ModelBackend',
  133. 'mysite.ldap_backend.LdapBackend',
  134. ]
  135. print(" --- Live stage --- ")
  136. AUTH_PROFILE_MODULE = 'application.CustomUser'
  137. #Log Configuration
  138. LOGGING = {
  139. 'version': 1,
  140. 'disable_existing_loggers': True,
  141. 'formatters': {
  142. 'standard': {
  143. 'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
  144. 'datefmt' : "%d/%b/%Y %H:%M:%S"
  145. },
  146. },
  147. 'handlers': {
  148. 'null': {
  149. 'level':'DEBUG',
  150. 'class':'logging.NullHandler',
  151. },
  152. 'logfile': {
  153. 'level':'DEBUG',
  154. 'class':'logging.handlers.RotatingFileHandler',
  155. 'filename': os.path.join(BASE_DIR, 'log.txt'),
  156. 'maxBytes': 50000,
  157. 'backupCount': 2,
  158. 'formatter': 'standard',
  159. },
  160. 'console':{
  161. 'level':'INFO',
  162. 'class':'logging.StreamHandler',
  163. 'formatter': 'standard'
  164. },
  165. },
  166. 'loggers': {
  167. 'django': {
  168. 'handlers':['console'],
  169. 'propagate': True,
  170. 'level':'WARN',
  171. },
  172. 'django.db.backends': {
  173. 'handlers': ['console'],
  174. 'level': 'DEBUG',
  175. 'propagate': False,
  176. },
  177. 'mysite': {
  178. 'handlers': ['console', 'logfile'],
  179. 'level': 'DEBUG',
  180. 'formatter': 'standard'
  181. },
  182. }
  183. }
  184. if DEBUG:
  185. INTERNAL_IPS = ('127.0.0.1', 'localhost',)
  186. MIDDLEWARE += (
  187. 'debug_toolbar.middleware.DebugToolbarMiddleware',
  188. )
  189. INSTALLED_APPS += (
  190. 'debug_toolbar',
  191. )
  192. DEBUG_TOOLBAR_PANELS = [
  193. 'debug_toolbar.panels.versions.VersionsPanel',
  194. 'debug_toolbar.panels.timer.TimerPanel',
  195. 'debug_toolbar.panels.settings.SettingsPanel',
  196. 'debug_toolbar.panels.headers.HeadersPanel',
  197. 'debug_toolbar.panels.request.RequestPanel',
  198. 'debug_toolbar.panels.sql.SQLPanel',
  199. 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
  200. 'debug_toolbar.panels.templates.TemplatesPanel',
  201. 'debug_toolbar.panels.cache.CachePanel',
  202. 'debug_toolbar.panels.signals.SignalsPanel',
  203. 'debug_toolbar.panels.logging.LoggingPanel',
  204. 'debug_toolbar.panels.redirects.RedirectsPanel',
  205. ]
  206. DEBUG_TOOLBAR_CONFIG = {
  207. 'INTERCEPT_REDIRECTS': False,
  208. }