Piki is a minimal wiki
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.

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