Python Galery
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

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