Project And Teamorganisation Tool
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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. """
  2. Django settings for patt project.
  3. Generated by 'django-admin startproject' using Django 5.1.1.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/5.1/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/5.1/ref/settings/
  8. """
  9. from pathlib import Path
  10. import config
  11. from logging.handlers import SocketHandler as _SocketHandler
  12. import os
  13. import random
  14. import stat
  15. import sys
  16. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  17. BASE_DIR = Path(__file__).resolve().parent.parent
  18. # Quick-start development settings - unsuitable for production
  19. # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
  20. # Application definition
  21. INSTALLED_APPS = [
  22. 'patt.apps.PattConfig',
  23. 'themes.apps.ThemesConfig',
  24. 'mycreole.apps.MycreoleConfig',
  25. 'users.apps.UsersConfig',
  26. #
  27. 'django.contrib.admin',
  28. 'django.contrib.auth',
  29. 'django.contrib.contenttypes',
  30. 'django.contrib.sessions',
  31. 'django.contrib.messages',
  32. 'django.contrib.staticfiles',
  33. #
  34. 'simple_history',
  35. ]
  36. MIDDLEWARE = [
  37. 'django.middleware.security.SecurityMiddleware',
  38. 'django.contrib.sessions.middleware.SessionMiddleware',
  39. 'django.middleware.locale.LocaleMiddleware',
  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. 'simple_history.middleware.HistoryRequestMiddleware',
  46. 'users.middleware.SettingsMiddleware',
  47. ]
  48. ROOT_URLCONF = 'main.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 = 'main.wsgi.application'
  65. # Database
  66. # https://docs.djangoproject.com/en/5.1/ref/settings/#databases
  67. DATABASES = {
  68. 'default': {
  69. 'ENGINE': 'django.db.backends.sqlite3',
  70. 'NAME': BASE_DIR / 'db.sqlite3',
  71. }
  72. }
  73. # Password validation
  74. # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
  75. AUTH_PASSWORD_VALIDATORS = [
  76. {
  77. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  78. },
  79. {
  80. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  81. },
  82. {
  83. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  84. },
  85. {
  86. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  87. },
  88. ]
  89. # Internationalization
  90. # https://docs.djangoproject.com/en/5.1/topics/i18n/
  91. LANGUAGE_CODE = 'en-us'
  92. LANGUAGES = [
  93. ('en', 'English'),
  94. ('de', 'Deutsch'),
  95. ]
  96. TIME_ZONE = 'UTC'
  97. USE_I18N = True
  98. LOCALE_PATHS = [
  99. os.path.join(BASE_DIR, 'themes', 'locale'),
  100. os.path.join(BASE_DIR, 'users', 'locale'),
  101. os.path.join(BASE_DIR, 'patt', 'locale'),
  102. ]
  103. USE_L10N = True
  104. USE_TZ = True
  105. # Static files (CSS, JavaScript, Images)
  106. # https://docs.djangoproject.com/en/5.1/howto/static-files/
  107. STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
  108. STATIC_URL = 'static/'
  109. MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
  110. MEDIA_URL = '/media/'
  111. USERS_PROFILE_ADDITIONS = {"PaTT Profile": 'patt.forms.PattUserProfileForm'}
  112. MYCREOLE_ROOT = os.path.join(BASE_DIR, 'data', 'mycreole')
  113. MYCREOLE_ATTACHMENT_ACCESS = {
  114. 'read': 'patt.access.read_attachment',
  115. 'modify': 'patt.access.modify_attachment',
  116. }
  117. MYCREOLE_BAR = {
  118. 'navibar': 'patt.context.navigationbar',
  119. 'menubar': 'patt.context.menubar',
  120. }
  121. MYCREOLE_EXT_FILTERS = [
  122. 'patt.creole.task_link_filter',
  123. 'patt.creole.tasklist_link_filter',
  124. ]
  125. WHOOSH_PATH = os.path.join(BASE_DIR, 'data', 'whoosh_index')
  126. LOGIN_URL = 'users-login'
  127. # Default primary key field type
  128. # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
  129. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  130. # Check permission of config.py
  131. #
  132. if sys.platform == 'linux' or sys.platform == 'linux2':
  133. st = os.stat(os.path.join(BASE_DIR, 'config.py'))
  134. if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
  135. raise PermissionError("conig.py is readable by group or others.")
  136. # Default values, if not defined in config.py
  137. #
  138. USER_CONFIG_DEFAULTS = {
  139. 'DEBUG': False,
  140. 'SECRET_KEY': None,
  141. 'DEFAULT_THEME': 'clear-green',
  142. 'ALLOWED_HOSTS': ['127.0.0.1', 'localhost', ],
  143. 'CSRF_TRUSTED_ORIGINS': [],
  144. 'ADMINS': [],
  145. 'PASSWORD_RESET_TIMEOUT': 60*60*3,
  146. #
  147. 'EMAIL_HOST': None,
  148. 'EMAIL_PORT': None,
  149. 'EMAIL_HOST_USER': None,
  150. 'EMAIL_FROM': "piki",
  151. 'EMAIL_HOST_PASSWORD': None,
  152. 'EMAIL_USE_TLS': None,
  153. 'EMAIL_USE_SSL': None,
  154. 'EMAIL_TIMEOUT': None,
  155. 'EMAIL_SSL_KEYFILE': None,
  156. 'EMAIL_SSL_CERTFILE': None,
  157. }
  158. # Set configuration parameters
  159. #
  160. thismodule = sys.modules[__name__]
  161. for property_name in USER_CONFIG_DEFAULTS:
  162. try:
  163. value = getattr(config, property_name)
  164. setattr(thismodule, property_name, value)
  165. except AttributeError:
  166. if not property_name.startswith('EMAIL_') or property_name == 'EMAIL_FROM':
  167. value = USER_CONFIG_DEFAULTS[property_name]
  168. setattr(thismodule, property_name, value)
  169. # SECURITY WARNING: keep the secret key used in production secret!
  170. #
  171. if SECRET_KEY is None:
  172. chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
  173. s_key = ''.join([random.choice(chars) for n in range(50)])
  174. secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--)." % repr(s_key)
  175. raise KeyError(secret_key_warning)
  176. # Logging Configuration
  177. #
  178. ROOT_LOGGER_NAME = os.path.basename(os.path.dirname(__file__))
  179. default_handler = ['socket', 'console'] if DEBUG else ['console']
  180. class DjangoSocketHandler(_SocketHandler):
  181. def emit(self, record):
  182. if hasattr(record, 'request'):
  183. record.request = None
  184. return super().emit(record)
  185. LOGGING = {
  186. 'version': 1,
  187. 'disable_existing_loggers': False,
  188. 'formatters': {
  189. 'short': {
  190. 'format': "%(asctime)s \"%(name)s - %(levelname)s - %(message)s\"",
  191. 'datefmt': '[%d/%b/%Y %H:%M:%S]',
  192. },
  193. 'long': {
  194. 'format': """~~~~(%(levelname)-10s)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195. File "%(pathname)s", line %(lineno)d, in %(funcName)s
  196. %(asctime)s: %(name)s - %(message)s
  197. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""",
  198. },
  199. },
  200. 'handlers': {
  201. 'console': {
  202. 'level': 'DEBUG',
  203. 'class': 'logging.StreamHandler',
  204. 'formatter': 'short',
  205. },
  206. 'socket': {
  207. 'level': 'DEBUG',
  208. 'class': f'{ROOT_LOGGER_NAME}.settings.DjangoSocketHandler',
  209. 'host': '127.0.0.1',
  210. 'port': 19996,
  211. },
  212. },
  213. 'loggers': {
  214. 'django': {
  215. 'handlers': default_handler,
  216. 'level': 'INFO',
  217. 'propagate': False,
  218. },
  219. ROOT_LOGGER_NAME: {
  220. 'handlers': default_handler,
  221. 'level': 'DEBUG' if DEBUG else 'INFO',
  222. 'propagate': False,
  223. },
  224. },
  225. }