settings.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import ldap
  4. from django_auth_ldap.config import LDAPSearch, PosixGroupType
  5. # from custom.coin_posix_group_type import CoinPosixGroupType
  6. # Django settings for coin project.
  7. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  8. BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  9. PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
  10. DEBUG = TEMPLATE_DEBUG = False
  11. ADMINS = (
  12. # ('Your Name', 'your_email@example.com'),
  13. )
  14. MANAGERS = ADMINS
  15. # Instance LDAP de développement:
  16. # adresse du serveur : ldapdev.illyse.org
  17. # port ldap: 389
  18. # port ldaps: 636
  19. DATABASES = {
  20. # Base de donnée du SI
  21. 'default': {
  22. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  23. 'NAME': 'illyse_coin',
  24. 'USER': 'illyse_coin',
  25. 'PASSWORD': '',
  26. 'HOST': '', # Empty for localhost through domain sockets
  27. 'PORT': '', # Empty for default
  28. },
  29. # LDAP backend pour stockage et mise à jour de données
  30. 'ldap': {
  31. 'ENGINE': 'ldapdb.backends.ldap',
  32. 'NAME': 'ldap://ldapdev.illyse.org:389/',
  33. 'TLS': True,
  34. 'GLOBAL_OPTIONS': {ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER},
  35. 'USER': 'cn=illysedev,ou=services,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR',
  36. 'PASSWORD': 'gfj83-E8ECgGh23JK_Ol12'
  37. }
  38. }
  39. DATABASE_ROUTERS = ['ldapdb.router.Router']
  40. # Hosts/domain names that are valid for this site; required if DEBUG is False
  41. # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
  42. ALLOWED_HOSTS = []
  43. # Local time zone for this installation. Choices can be found here:
  44. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  45. # although not all choices may be available on all operating systems.
  46. # In a Windows environment this must be set to your system time zone.
  47. TIME_ZONE = 'Europe/Paris'
  48. # Language code for this installation. All choices can be found here:
  49. # http://www.i18nguy.com/unicode/language-identifiers.html
  50. LANGUAGE_CODE = 'fr-fr'
  51. SITE_ID = 1
  52. # If you set this to False, Django will make some optimizations so as not
  53. # to load the internationalization machinery.
  54. USE_I18N = True
  55. # If you set this to False, Django will not format dates, numbers and
  56. # calendars according to the current locale.
  57. USE_L10N = True
  58. # If you set this to False, Django will not use timezone-aware datetimes.
  59. USE_TZ = True
  60. # Default URL for login and logout
  61. LOGIN_URL = '/members/login'
  62. LOGIN_REDIRECT_URL = '/members'
  63. LOGOUT_URL = '/members/logout'
  64. # Absolute filesystem path to the directory that will hold user-uploaded files.
  65. # Example: "/var/www/example.com/media/"
  66. MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
  67. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  68. # trailing slash.
  69. # Examples: "http://example.com/media/", "http://media.example.com/"
  70. MEDIA_URL = '/media/'
  71. # Absolute path to the directory static files should be collected to.
  72. # Don't put anything in this directory yourself; store your static files
  73. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
  74. # Example: "/var/www/example.com/static/"
  75. STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
  76. # URL prefix for static files.
  77. # Example: "http://example.com/static/", "http://static.example.com/"
  78. STATIC_URL = '/static/'
  79. # Additional locations of static files
  80. STATICFILES_DIRS = (
  81. # Put strings here, like "/home/html/static" or "C:/www/django/static".
  82. # Always use forward slashes, even on Windows.
  83. # Don't forget to use absolute paths, not relative paths.
  84. )
  85. # List of finder classes that know how to find static files in
  86. # various locations.
  87. STATICFILES_FINDERS = (
  88. 'django.contrib.staticfiles.finders.FileSystemFinder',
  89. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  90. #'django.contrib.staticfiles.finders.DefaultStorageFinder',
  91. )
  92. # Make this unique, and don't share it with anybody.
  93. SECRET_KEY = '!qy_)gao6q)57#mz1s-d$5^+dp1nt=lk1d19&9bb3co37vn)!3'
  94. # List of callables that know how to import templates from various sources.
  95. TEMPLATE_LOADERS = (
  96. 'django.template.loaders.filesystem.Loader',
  97. 'django.template.loaders.app_directories.Loader',
  98. #'django.template.loaders.eggs.Loader',
  99. )
  100. MIDDLEWARE_CLASSES = (
  101. 'django.middleware.common.CommonMiddleware',
  102. 'django.contrib.sessions.middleware.SessionMiddleware',
  103. 'django.middleware.csrf.CsrfViewMiddleware',
  104. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  105. 'django.contrib.messages.middleware.MessageMiddleware',
  106. # Uncomment the next line for simple clickjacking protection:
  107. # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  108. )
  109. ROOT_URLCONF = 'coin.urls'
  110. # Python dotted path to the WSGI application used by Django's runserver.
  111. WSGI_APPLICATION = 'coin.wsgi.application'
  112. TEMPLATE_DIRS = (
  113. # Only absolute paths, always forward slashes
  114. os.path.join(PROJECT_PATH, 'templates/'),
  115. )
  116. INSTALLED_APPS = (
  117. 'django.contrib.auth',
  118. 'django.contrib.contenttypes',
  119. 'django.contrib.sessions',
  120. #'django.contrib.sites',
  121. 'django.contrib.messages',
  122. 'django.contrib.staticfiles',
  123. # Uncomment the next line to enable the admin:
  124. 'django.contrib.admin',
  125. # Uncomment the next line to enable admin documentation:
  126. #'django.contrib.admindocs',
  127. 'south',
  128. 'ldapdb', # LDAP as database backend
  129. 'autocomplete_light', #Automagic autocomplete foreingkey form component
  130. 'activelink', #Detect if a link match actual page
  131. 'coin',
  132. 'coin.members',
  133. 'coin.offers',
  134. 'coin.billing',
  135. 'coin.resources',
  136. 'coin.reverse_dns',
  137. 'coin.vpn'
  138. )
  139. # A sample logging configuration. The only tangible logging
  140. # performed by this configuration is to send an email to
  141. # the site admins on every HTTP 500 error when DEBUG=False.
  142. # See http://docs.djangoproject.com/en/dev/topics/logging for
  143. # more details on how to customize your logging configuration.
  144. LOGGING = {
  145. 'version': 1,
  146. 'disable_existing_loggers': False,
  147. 'filters': {
  148. 'require_debug_false': {
  149. '()': 'django.utils.log.RequireDebugFalse'
  150. }
  151. },
  152. 'handlers': {
  153. 'mail_admins': {
  154. 'level': 'ERROR',
  155. 'filters': ['require_debug_false'],
  156. 'class': 'django.utils.log.AdminEmailHandler'
  157. }
  158. },
  159. 'loggers': {
  160. 'django.request': {
  161. 'handlers': ['mail_admins'],
  162. 'level': 'ERROR',
  163. 'propagate': True,
  164. },
  165. }
  166. }
  167. TEMPLATE_CONTEXT_PROCESSORS = (
  168. "django.contrib.auth.context_processors.auth",
  169. "django.core.context_processors.debug",
  170. "django.core.context_processors.i18n",
  171. "django.core.context_processors.media",
  172. "django.core.context_processors.static",
  173. "django.core.context_processors.tz",
  174. "django.core.context_processors.request",
  175. "django.contrib.messages.context_processors.messages")
  176. AUTH_USER_MODEL = 'members.Member'
  177. AUTHENTICATION_BACKENDS = (
  178. # 'django_auth_ldap.backend.LDAPBackend',
  179. 'django.contrib.auth.backends.ModelBackend',
  180. )
  181. # LDAP Backend pour authentification
  182. AUTH_LDAP_SERVER_URI = "ldap://ldapdev.illyse.org:389"
  183. AUTH_LDAP_START_TLS = True
  184. AUTH_LDAP_GLOBAL_OPTIONS = {ldap.OPT_X_TLS_REQUIRE_CERT: ldap.OPT_X_TLS_NEVER}
  185. AUTH_LDAP_BIND_DN = "cn=illysedev,ou=services,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
  186. AUTH_LDAP_BIND_PASSWORD = "gfj83-E8ECgGh23JK_Ol12"
  187. AUTH_LDAP_USER_SEARCH = LDAPSearch(
  188. "ou=users,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR",
  189. ldap.SCOPE_SUBTREE,
  190. "(cn=%(user)s)"
  191. )
  192. AUTH_LDAP_CACHE_GROUPS = False
  193. AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
  194. "ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR",
  195. ldap.SCOPE_SUBTREE,
  196. "(objectClass=posixGroup)"
  197. )
  198. AUTH_LDAP_GROUP_TYPE = PosixGroupType()
  199. # AUTH_LDAP_REQUIRE_GROUP = "cn=admin,ou=groups,o=ILLYSE,"
  200. # "l=Villeurbanne,st=RHA,c=FR"
  201. AUTH_LDAP_USER_ATTR_MAP = {
  202. "first_name": "givenName",
  203. "last_name": "sn"
  204. }
  205. AUTH_LDAP_USER_FLAGS_BY_GROUP = {
  206. "is_active": "cn=coin,ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR",
  207. "is_staff": "cn=coin_admin,ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR",
  208. "is_superuser": "cn=coin_admin,ou=groups,ou=unix,o=ILLYSE,l=Villeurbanne,st=RHA,c=FR"
  209. }
  210. # Surcharge les paramètres en utilisant le fichier settings-local.py
  211. try:
  212. from settings_local import *
  213. except ImportError:
  214. pass