Project And Teamorganisation Tool
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

settings.py 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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/3.0/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/3.0/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. 'simple_history',
  34. ]
  35. MIDDLEWARE = [
  36. 'django.middleware.security.SecurityMiddleware',
  37. 'django.contrib.sessions.middleware.SessionMiddleware',
  38. 'django.middleware.locale.LocaleMiddleware',
  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. 'simple_history.middleware.HistoryRequestMiddleware',
  45. 'users.middleware.SettingsMiddleware',
  46. ]
  47. ROOT_URLCONF = 'main.urls'
  48. TEMPLATES = [
  49. {
  50. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  51. 'DIRS': [],
  52. 'APP_DIRS': True,
  53. 'OPTIONS': {
  54. 'context_processors': [
  55. 'django.template.context_processors.debug',
  56. 'django.template.context_processors.request',
  57. 'django.contrib.auth.context_processors.auth',
  58. 'django.contrib.messages.context_processors.messages',
  59. ],
  60. },
  61. },
  62. ]
  63. WSGI_APPLICATION = 'main.wsgi.application'
  64. # Database
  65. # https://docs.djangoproject.com/en/5.1/ref/settings/#databases
  66. DATABASES = {
  67. 'default': {
  68. 'ENGINE': 'django.db.backends.sqlite3',
  69. 'NAME': BASE_DIR / 'db.sqlite3',
  70. }
  71. }
  72. # Password validation
  73. # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
  74. AUTH_PASSWORD_VALIDATORS = [
  75. {
  76. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  77. },
  78. {
  79. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  80. },
  81. {
  82. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  83. },
  84. {
  85. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  86. },
  87. ]
  88. # Internationalization
  89. # https://docs.djangoproject.com/en/5.1/topics/i18n/
  90. LANGUAGE_CODE = 'en-us'
  91. LANGUAGES = [
  92. ('en', 'English'),
  93. ('de', 'Deutsch'),
  94. ]
  95. TIME_ZONE = 'UTC'
  96. USE_I18N = True
  97. LOCALE_PATHS = [
  98. os.path.join(BASE_DIR, 'themes', 'locale'),
  99. os.path.join(BASE_DIR, 'users', 'locale'),
  100. os.path.join(BASE_DIR, 'patt', 'locale'),
  101. ]
  102. USE_L10N = True
  103. USE_TZ = True
  104. # Static files (CSS, JavaScript, Images)
  105. # https://docs.djangoproject.com/en/5.1/howto/static-files/
  106. STATIC_ROOT = os.path.join(BASE_DIR, 'data', 'static')
  107. STATIC_URL = 'static/'
  108. MEDIA_ROOT = os.path.join(BASE_DIR, 'data', 'media')
  109. MEDIA_URL = '/media/'
  110. MYCREOLE_ROOT = os.path.join(BASE_DIR, 'data', 'mycreole')
  111. MYCREOLE_ATTACHMENT_ACCESS = {
  112. 'read': 'patt.access.read_attachment',
  113. 'modify': 'patt.access.modify_attachment',
  114. }
  115. MYCREOLE_BAR = {
  116. 'navibar': 'patt.context.navigationbar',
  117. 'menubar': 'patt.context.menubar',
  118. }
  119. MYCREOLE_EXT_FILTERS = [
  120. 'patt.creole.task_link_filter',
  121. 'patt.creole.tasklist_link_filter',
  122. ]
  123. WHOOSH_PATH = os.path.join(BASE_DIR, 'data', 'whoosh_index')
  124. LOGIN_URL = 'users-login'
  125. # Default primary key field type
  126. # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
  127. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  128. # Check permission of config.py
  129. #
  130. if sys.platform == 'linux' or sys.platform == 'linux2':
  131. st = os.stat(os.path.join(BASE_DIR, 'config.py'))
  132. if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
  133. raise PermissionError("conig.py is readable by group or others.")
  134. # Default values, if not defined in config.py
  135. #
  136. USER_CONFIG_DEFAULTS = {
  137. 'DEBUG': False,
  138. 'SECRET_KEY': None,
  139. 'DEFAULT_THEME': 'clear-green',
  140. 'ALLOWED_HOSTS': ['127.0.0.1', 'localhost', ],
  141. 'CSRF_TRUSTED_ORIGINS': [],
  142. }
  143. # Set configuration parameters
  144. #
  145. thismodule = sys.modules[__name__]
  146. for property_name in USER_CONFIG_DEFAULTS:
  147. try:
  148. value = getattr(config, property_name)
  149. except AttributeError:
  150. value = USER_CONFIG_DEFAULTS[property_name]
  151. setattr(thismodule, property_name, value)
  152. # SECURITY WARNING: keep the secret key used in production secret!
  153. #
  154. if SECRET_KEY is None:
  155. chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
  156. s_key = ''.join([random.choice(chars) for n in range(50)])
  157. secret_key_warning = "You need to create a config.py file including at least a SECRET_KEY definition (e.g.: --> %s <--)." % repr(s_key)
  158. raise KeyError(secret_key_warning)
  159. # Logging Configuration
  160. #
  161. ROOT_LOGGER_NAME = os.path.basename(os.path.dirname(__file__))
  162. default_handler = ['socket', 'console'] if DEBUG else ['console']
  163. class DjangoSocketHandler(_SocketHandler):
  164. def emit(self, record):
  165. if hasattr(record, 'request'):
  166. record.request = None
  167. return super().emit(record)
  168. LOGGING = {
  169. 'version': 1,
  170. 'disable_existing_loggers': False,
  171. 'formatters': {
  172. 'short': {
  173. 'format': "%(asctime)s \"%(name)s - %(levelname)s - %(message)s\"",
  174. 'datefmt': '[%d/%b/%Y %H:%M:%S]',
  175. },
  176. 'long': {
  177. 'format': """~~~~(%(levelname)-10s)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  178. File "%(pathname)s", line %(lineno)d, in %(funcName)s
  179. %(asctime)s: %(name)s - %(message)s
  180. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""",
  181. },
  182. },
  183. 'handlers': {
  184. 'console': {
  185. 'level': 'DEBUG',
  186. 'class': 'logging.StreamHandler',
  187. 'formatter': 'short',
  188. },
  189. 'socket': {
  190. 'level': 'DEBUG',
  191. 'class': f'{ROOT_LOGGER_NAME}.settings.DjangoSocketHandler',
  192. 'host': '127.0.0.1',
  193. 'port': 19996,
  194. },
  195. },
  196. 'loggers': {
  197. 'django': {
  198. 'handlers': default_handler,
  199. 'level': 'INFO',
  200. 'propagate': False,
  201. },
  202. ROOT_LOGGER_NAME: {
  203. 'handlers': default_handler,
  204. 'level': 'DEBUG' if DEBUG else 'INFO',
  205. 'propagate': False,
  206. },
  207. },
  208. }