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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. ]
  36. MIDDLEWARE = [
  37. 'django.middleware.security.SecurityMiddleware',
  38. 'django.contrib.sessions.middleware.SessionMiddleware',
  39. 'django.middleware.common.CommonMiddleware',
  40. 'django.middleware.csrf.CsrfViewMiddleware',
  41. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  42. 'django.contrib.messages.middleware.MessageMiddleware',
  43. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  44. ]
  45. ROOT_URLCONF = 'mysite.urls'
  46. TEMPLATES = [
  47. {
  48. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  49. 'DIRS': [],
  50. 'APP_DIRS': True,
  51. 'OPTIONS': {
  52. 'context_processors': [
  53. 'django.template.context_processors.debug',
  54. 'django.template.context_processors.request',
  55. 'django.contrib.auth.context_processors.auth',
  56. 'django.contrib.messages.context_processors.messages',
  57. ],
  58. },
  59. },
  60. ]
  61. WSGI_APPLICATION = 'mysite.wsgi.application'
  62. # Database
  63. # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
  64. if DEVELOPMENT:
  65. DATABASES = {
  66. 'default': {
  67. 'ENGINE': 'django.db.backends.sqlite3',
  68. 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  69. }
  70. }
  71. print(" --- Development sqlite database --- ")
  72. else:
  73. DATABASES = {
  74. 'default': {
  75. 'ENGINE': 'django.db.backends.mysql',
  76. 'NAME': 'django-app',
  77. 'USER': 'django-app',
  78. 'PASSWORD': '*******',
  79. 'HOST': 'mysql',
  80. 'PORT': '3306',
  81. 'OPTIONS': {
  82. 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
  83. },
  84. }
  85. }
  86. # Password validation
  87. # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
  88. AUTH_PASSWORD_VALIDATORS = [
  89. {
  90. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  91. },
  92. {
  93. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  94. },
  95. {
  96. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  97. },
  98. {
  99. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  100. },
  101. ]
  102. # Internationalization
  103. # https://docs.djangoproject.com/en/2.0/topics/i18n/
  104. LANGUAGE_CODE = 'en-us'
  105. TIME_ZONE = 'Europe/Berlin'
  106. USE_I18N = True
  107. USE_L10N = True
  108. USE_TZ = True
  109. # Static files (CSS, JavaScript, Images)
  110. # https://docs.djangoproject.com/en/2.0/howto/static-files/
  111. STATIC_URL = '/static/'
  112. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  113. # Konfiguration des Auth-Systems
  114. LDAP_DOMAIN = 'ADS1'
  115. LDAP_SERVER = 'gso1.ads1.fh-nuernberg.de'
  116. if DEVELOPMENT:
  117. LOGIN_REDIRECT_URL = '/'
  118. LOGOUT_REDIRECT_URL = '/'
  119. LOGIN_URL = "/accounts/login/"
  120. else:
  121. LOGIN_REDIRECT_URL = '/app/'
  122. LOGOUT_REDIRECT_URL = '/app/'
  123. LOGIN_URL = "/app/accounts/login/"
  124. if DEVELOPMENT:
  125. AUTHENTICATION_BACKENDS = [
  126. 'django.contrib.auth.backends.ModelBackend',
  127. ]
  128. print(" --- Development stage --- ")
  129. else:
  130. AUTHENTICATION_BACKENDS = [
  131. 'django.contrib.auth.backends.ModelBackend',
  132. 'mysite.ldap_backend.LdapBackend',
  133. ]
  134. print(" --- Live stage --- ")
  135. #Log Configuration
  136. LOGGING = {
  137. 'version': 1,
  138. 'disable_existing_loggers': True,
  139. 'formatters': {
  140. 'standard': {
  141. 'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
  142. 'datefmt' : "%d/%b/%Y %H:%M:%S"
  143. },
  144. },
  145. 'handlers': {
  146. 'null': {
  147. 'level':'DEBUG',
  148. 'class':'logging.NullHandler',
  149. },
  150. 'logfile': {
  151. 'level':'DEBUG',
  152. 'class':'logging.handlers.RotatingFileHandler',
  153. 'filename': os.path.join(BASE_DIR, 'log.txt'),
  154. 'maxBytes': 50000,
  155. 'backupCount': 2,
  156. 'formatter': 'standard',
  157. },
  158. 'console':{
  159. 'level':'INFO',
  160. 'class':'logging.StreamHandler',
  161. 'formatter': 'standard'
  162. },
  163. },
  164. 'loggers': {
  165. 'django': {
  166. 'handlers':['console'],
  167. 'propagate': True,
  168. 'level':'WARN',
  169. },
  170. 'django.db.backends': {
  171. 'handlers': ['console'],
  172. 'level': 'DEBUG',
  173. 'propagate': False,
  174. },
  175. 'mysite': {
  176. 'handlers': ['console', 'logfile'],
  177. 'level': 'DEBUG',
  178. 'formatter': 'standard'
  179. },
  180. }
  181. }
  182. if DEBUG:
  183. INTERNAL_IPS = ('127.0.0.1', 'localhost',)
  184. MIDDLEWARE += (
  185. 'debug_toolbar.middleware.DebugToolbarMiddleware',
  186. )
  187. INSTALLED_APPS += (
  188. 'debug_toolbar',
  189. )
  190. DEBUG_TOOLBAR_PANELS = [
  191. 'debug_toolbar.panels.versions.VersionsPanel',
  192. 'debug_toolbar.panels.timer.TimerPanel',
  193. 'debug_toolbar.panels.settings.SettingsPanel',
  194. 'debug_toolbar.panels.headers.HeadersPanel',
  195. 'debug_toolbar.panels.request.RequestPanel',
  196. 'debug_toolbar.panels.sql.SQLPanel',
  197. 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
  198. 'debug_toolbar.panels.templates.TemplatesPanel',
  199. 'debug_toolbar.panels.cache.CachePanel',
  200. 'debug_toolbar.panels.signals.SignalsPanel',
  201. 'debug_toolbar.panels.logging.LoggingPanel',
  202. 'debug_toolbar.panels.redirects.RedirectsPanel',
  203. ]
  204. DEBUG_TOOLBAR_CONFIG = {
  205. 'INTERCEPT_REDIRECTS': False,
  206. }