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.0KB

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