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 7.2KB

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