Python Galery
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

settings.py 7.3KB

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