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

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