Browse Source

#590: sync misago project template with django, remove misago.conf.defaults import from settings.py

Rafał Pitoń 8 years ago
parent
commit
1267916c0f

+ 7 - 1
misago/conf/defaults.py

@@ -73,16 +73,21 @@ INSTALLED_APPS = (
 
 
 MIDDLEWARE_CLASSES = (
 MIDDLEWARE_CLASSES = (
     'debug_toolbar.middleware.DebugToolbarMiddleware',
     'debug_toolbar.middleware.DebugToolbarMiddleware',
+
     'misago.users.middleware.RealIPMiddleware',
     'misago.users.middleware.RealIPMiddleware',
     'misago.core.middleware.frontendcontext.FrontendContextMiddleware',
     'misago.core.middleware.frontendcontext.FrontendContextMiddleware',
+
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
+
     'misago.users.middleware.UserMiddleware',
     'misago.users.middleware.UserMiddleware',
+
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
+
     'misago.core.middleware.exceptionhandler.ExceptionHandlerMiddleware',
     'misago.core.middleware.exceptionhandler.ExceptionHandlerMiddleware',
     'misago.users.middleware.OnlineTrackerMiddleware',
     'misago.users.middleware.OnlineTrackerMiddleware',
     'misago.admin.middleware.AdminAuthMiddleware',
     'misago.admin.middleware.AdminAuthMiddleware',
@@ -91,12 +96,13 @@ MIDDLEWARE_CLASSES = (
 )
 )
 
 
 DEFAULT_CONTEXT_PROCESSORS = (
 DEFAULT_CONTEXT_PROCESSORS = (
-    'django.contrib.auth.context_processors.auth',
     'django.template.context_processors.debug',
     'django.template.context_processors.debug',
     'django.template.context_processors.i18n',
     'django.template.context_processors.i18n',
     'django.template.context_processors.media',
     'django.template.context_processors.media',
     'django.template.context_processors.static',
     'django.template.context_processors.static',
     'django.template.context_processors.tz',
     'django.template.context_processors.tz',
+
+    'django.contrib.auth.context_processors.auth',
     'django.contrib.messages.context_processors.messages',
     'django.contrib.messages.context_processors.messages',
 
 
     'misago.core.context_processors.site_address',
     'misago.core.context_processors.site_address',

+ 15 - 4
misago/project_template/manage.py

@@ -2,10 +2,21 @@
 import os
 import os
 import sys
 import sys
 
 
-
 if __name__ == "__main__":
 if __name__ == "__main__":
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
-
-    from django.core.management import execute_from_command_line
-
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError:
+        # The above import may fail for some other reason. Ensure that the
+        # issue is really that Django is missing to avoid masking other
+        # exceptions on Python 2.
+        try:
+            import django
+        except ImportError:
+            raise ImportError(
+                "Couldn't import Django. Are you sure it's installed and "
+                "available on your PYTHONPATH environment variable? Did you "
+                "forget to activate a virtual environment?"
+            )
+        raise
     execute_from_command_line(sys.argv)
     execute_from_command_line(sys.argv)

+ 218 - 45
misago/project_template/project_name/settings.py

@@ -1,5 +1,7 @@
 """
 """
-Misago settings for {{ project_name }} project.
+Django settings for {{ project_name }} project.
+
+Generated by 'django-admin startproject' using Django {{ django_version }}.
 
 
 For more information on this file, see
 For more information on this file, see
 https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/
 https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/
@@ -8,24 +10,21 @@ For the full list of settings and their values, see
 https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/
 https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/
 """
 """
 
 
-# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 import os
 import os
 
 
-from misago.conf.defaults import *
-
-
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 
 
 
 # Quick-start development settings - unsuitable for production
 # Quick-start development settings - unsuitable for production
 # See https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/checklist/
 # See https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/checklist/
 
 
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = '{{ secret_key }}'
+
 # SECURITY WARNING: don't run with debug turned on in production!
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True
 DEBUG = True
 
 
-# Hosts allowed to POST to your site
-# If you are unsure, just enter here your host name, eg. 'mysite.com'
-
 ALLOWED_HOSTS = []
 ALLOWED_HOSTS = []
 
 
 
 
@@ -34,7 +33,7 @@ ALLOWED_HOSTS = []
 
 
 DATABASES = {
 DATABASES = {
     'default': {
     'default': {
-        # Only PostgreSQL is supported
+        # Misago requires PostgreSQL to run
         'ENGINE': 'django.db.backends.postgresql',
         'ENGINE': 'django.db.backends.postgresql',
         'NAME': '',
         'NAME': '',
         'USER': '',
         'USER': '',
@@ -43,63 +42,163 @@ DATABASES = {
     }
     }
 }
 }
 
 
-# PostgreSQL text search configuration to use in searches
-# Defaults to "simple", for list of installed configurations run "\dF" in "psql"
-# Standard configs as of PostgreSQL 9.5: dutch, english, finnish, french,
-# german, hungarian, italian, norwegian, portuguese, romanian, russian, simple,
-# spanish, swedish, turkish
-# Example on adding custom language can be found here: https://github.com/lemonskyjwt/plpstgrssearch
-
-MISAGO_SEARCH_CONFIG = 'simple'
 
 
-
-# Cache
-# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#caches
+# Caching
+# https://docs.djangoproject.com/en/{{ docs_version }}/topics/cache/#setting-up-the-cache
 
 
 CACHES = {
 CACHES = {
     'default': {
     'default': {
-        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
+        # Misago doesn't run well with LocMemCache in production environments
+        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
     }
     }
 }
 }
 
 
 
 
-# Site language
+# Password validation
+# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+    {
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+    },
+]
+
+
+# Internationalization
 # https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/
 # https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/
 
 
 LANGUAGE_CODE = 'en-us'
 LANGUAGE_CODE = 'en-us'
 
 
-# Fallback Timezone
-# Used to format dates on server, that are then
-# presented to clients with disabled JS
-# Consult http://en.wikipedia.org/wiki/List_of_tz_database_time_zones TZ column
-# for valid values
-
 TIME_ZONE = 'UTC'
 TIME_ZONE = 'UTC'
 
 
+USE_I18N = True
 
 
-# Path used to access static files (CSS, JavaScript, Images)
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
 # https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
 
 
 STATIC_URL = '/static/'
 STATIC_URL = '/static/'
 
 
-# Path used to access uploaded media (Avatars and Profile Backgrounds, ect.)
-# This is NOT path used to serve posts attachments.
+
+# User uploads (Avatars, Attachments, files uploaded in other Django apps, ect.)
 # https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
 # https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/
+
 MEDIA_URL = '/media/'
 MEDIA_URL = '/media/'
 
 
 
 
-# Automatically setup default paths to media and static directories
-MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
+# The absolute path to the directory where collectstatic will collect static files for deployment.
+# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#static-root
+
 STATIC_ROOT = os.path.join(BASE_DIR, 'static')
 STATIC_ROOT = os.path.join(BASE_DIR, 'static')
 
 
 
 
-# Automatically setup default paths for static and template directories
-# You can use those directories to easily customize and add your own
-# assets and templates to your site
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#media-root
+
+MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
+
+
+# This setting defines the additional locations the staticfiles app will traverse if the FileSystemFinder finder
+# is enabled, e.g. if you use the collectstatic or findstatic management command or use the static file serving view.
+# https://docs.djangoproject.com/en/1.10/ref/settings/#staticfiles-dirs
+
 STATICFILES_DIRS = (
 STATICFILES_DIRS = (
     os.path.join(BASE_DIR, 'theme', 'static'),
     os.path.join(BASE_DIR, 'theme', 'static'),
 )
 )
 
 
+
+# Application definition
+
+AUTH_USER_MODEL = 'misago_users.User'
+
+AUTHENTICATION_BACKENDS = (
+    'misago.users.authbackends.MisagoBackend',
+)
+
+CSRF_FAILURE_VIEW = 'misago.core.errorpages.csrf_failure'
+
+INSTALLED_APPS = [
+    # Misago overrides for Django core feature
+    'misago',
+    'misago.users',
+
+    # Django apps
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.humanize',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+
+    # 3rd party apps used by Misago
+    'debug_toolbar',
+    'crispy_forms',
+    'mptt',
+    'rest_framework',
+
+    # Misago apps
+    'misago.admin',
+    'misago.acl',
+    'misago.core',
+    'misago.conf',
+    'misago.markup',
+    'misago.legal',
+    'misago.categories',
+    'misago.threads',
+    'misago.readtracker',
+    'misago.search',
+    'misago.faker',
+
+    # Utility for moving data from Misago 0.5
+    'misago.datamover',
+]
+
+INTERNAL_IPS = ['127.0.0.1']
+
+LOGIN_REDIRECT_URL = 'misago:index'
+
+LOGIN_URL = 'misago:login'
+
+LOGOUT_URL = 'misago:logout'
+
+MIDDLEWARE = [
+    'debug_toolbar.middleware.DebugToolbarMiddleware',
+
+    'misago.users.middleware.RealIPMiddleware',
+    'misago.core.middleware.frontendcontext.FrontendContextMiddleware',
+
+    'django.middleware.security.SecurityMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+
+    'misago.users.middleware.UserMiddleware',
+    'misago.core.middleware.exceptionhandler.ExceptionHandlerMiddleware',
+    'misago.users.middleware.OnlineTrackerMiddleware',
+    'misago.admin.middleware.AdminAuthMiddleware',
+    'misago.threads.middleware.UnreadThreadsCountMiddleware',
+    'misago.core.middleware.threadstore.ThreadStoreMiddleware',
+]
+
+ROOT_URLCONF = '{{ project_name }}.urls'
+
 TEMPLATES = [
 TEMPLATES = [
     {
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
@@ -108,22 +207,96 @@ TEMPLATES = [
         ],
         ],
         'APP_DIRS': True,
         'APP_DIRS': True,
         'OPTIONS': {
         'OPTIONS': {
-            'context_processors': DEFAULT_CONTEXT_PROCESSORS,
+            'context_processors': [
+                'django.template.context_processors.debug',
+                'django.template.context_processors.i18n',
+                'django.template.context_processors.media',
+                'django.template.context_processors.request',
+                'django.template.context_processors.static',
+                'django.template.context_processors.tz',
+                'django.contrib.auth.context_processors.auth',
+                'django.contrib.messages.context_processors.messages',
+
+                'misago.core.context_processors.site_address',
+                'misago.conf.context_processors.settings',
+                'misago.users.context_processors.user_links',
+                'misago.legal.context_processors.legal_links',
+
+                # Data preloaders
+                'misago.conf.context_processors.preload_settings_json',
+                'misago.core.context_processors.current_link',
+                'misago.markup.context_processors.preload_api_url',
+                'misago.threads.context_processors.preload_threads_urls',
+                'misago.users.context_processors.preload_user_json',
+
+                # Note: keep frontend_context processor last for previous processors
+                # to be able to expose data UI app via request.frontend_context
+                'misago.core.context_processors.frontend_context',
+            ],
         },
         },
     },
     },
 ]
 ]
 
 
+WSGI_APPLICATION = '{{ project_name }}.wsgi.application'
 
 
-# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = '{{ secret_key }}'
+
+# Django Crispy Forms
+#http://django-crispy-forms.readthedocs.io/en/latest/install.html
+
+CRISPY_TEMPLATE_PACK = 'bootstrap3'
+
+
+# Django Debug Toolbar
+# http://django-debug-toolbar.readthedocs.io/en/stable/configuration.html
+
+DEBUG_TOOLBAR_PANELS = (
+    'debug_toolbar.panels.versions.VersionsPanel',
+    'debug_toolbar.panels.timer.TimerPanel',
+    'debug_toolbar.panels.settings.SettingsPanel',
+    'debug_toolbar.panels.headers.HeadersPanel',
+    'debug_toolbar.panels.request.RequestPanel',
+    'debug_toolbar.panels.sql.SQLPanel',
+
+    'misago.acl.panels.MisagoACLPanel',
+
+    'debug_toolbar.panels.staticfiles.StaticFilesPanel',
+    'debug_toolbar.panels.templates.TemplatesPanel',
+    'debug_toolbar.panels.cache.CachePanel',
+    'debug_toolbar.panels.signals.SignalsPanel',
+    'debug_toolbar.panels.logging.LoggingPanel',
+)
+
+
+# Django Rest Framework
+# http://www.django-rest-framework.org/api-guide/settings/
+
+REST_FRAMEWORK = {
+    'DEFAULT_PERMISSION_CLASSES': (
+        'misago.core.rest_permissions.IsAuthenticatedOrReadOnly',
+    ),
+    'DEFAULT_RENDERER_CLASSES': (
+        'rest_framework.renderers.JSONRenderer',
+    ),
+    'EXCEPTION_HANDLER': 'misago.core.exceptionhandler.handle_api_exception',
+    'UNAUTHENTICATED_USER': 'misago.users.models.AnonymousUser',
+    'URL_FORMAT_OVERRIDE': None,
+}
+
+
+# Misago specific settings
+# https://misago.readthedocs.io/en/latest/developers/settings.html
+
+# PostgreSQL text search configuration to use in searches
+# Defaults to "simple", for list of installed configurations run "\dF" in "psql"
+# Standard configs as of PostgreSQL 9.5 are: dutch, english, finnish, french,
+# german, hungarian, italian, norwegian, portuguese, romanian, russian, simple,
+# spanish, swedish and turkish
+# Example on adding custom language can be found here: https://github.com/lemonskyjwt/plpstgrssearch
+
+MISAGO_SEARCH_CONFIG = 'simple'
 
 
 
 
 # Path to directory containing avatar galleries
 # Path to directory containing avatar galleries
 # Those galleries can be loaded by running loadavatargallery command
 # Those galleries can be loaded by running loadavatargallery command
-MISAGO_AVATAR_GALLERY = os.path.join(BASE_DIR, 'avatargallery')
 
 
-
-# Application definition
-# Don't edit those settings unless you know what you are doing
-ROOT_URLCONF = '{{ project_name }}.urls'
-WSGI_APPLICATION = '{{ project_name }}.wsgi.application'
+MISAGO_AVATAR_GALLERY = os.path.join(BASE_DIR, 'avatargallery')

+ 18 - 3
misago/project_template/project_name/urls.py

@@ -1,3 +1,18 @@
+"""{{ project_name }} URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+    https://docs.djangoproject.com/en/1.10/topics/http/urls/
+Examples:
+Function views
+    1. Add an import:  from my_app import views
+    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
+Class-based views
+    1. Add an import:  from other_app.views import Home
+    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
+Including another URLconf
+    1. Import the include() function: from django.conf.urls import url, include
+    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
+"""
 from django.conf import settings
 from django.conf import settings
 from django.conf.urls import include, url
 from django.conf.urls import include, url
 from django.conf.urls.static import static
 from django.conf.urls.static import static
@@ -24,7 +39,7 @@ urlpatterns = [
 ]
 ]
 
 
 
 
-# If debug mode is enabled, run debug toolbar
+# If debug mode is enabled, include debug toolbar
 if settings.DEBUG:
 if settings.DEBUG:
     import debug_toolbar
     import debug_toolbar
     urlpatterns += [
     urlpatterns += [
@@ -32,7 +47,7 @@ if settings.DEBUG:
     ]
     ]
 
 
 
 
-# Use static file server for static and media (debug only)
+# Use static file server for static and media files (debug only)
 urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
 urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
 urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
 urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
 
 
@@ -40,7 +55,7 @@ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
 # Error Handlers
 # Error Handlers
 # Misago needs those handlers to deal with errors raised by it's middlewares
 # Misago needs those handlers to deal with errors raised by it's middlewares
 # If you replace those handlers with custom ones, make sure you decorate them
 # If you replace those handlers with custom ones, make sure you decorate them
-# functions with shared_403_exception_handler or shared_404_exception_handler
+# with shared_403_exception_handler or shared_404_exception_handler
 # decorators that are defined in misago.views.errorpages module!
 # decorators that are defined in misago.views.errorpages module!
 handler403 = 'misago.core.errorpages.permission_denied'
 handler403 = 'misago.core.errorpages.permission_denied'
 handler404 = 'misago.core.errorpages.page_not_found'
 handler404 = 'misago.core.errorpages.page_not_found'

+ 1 - 2
misago/project_template/project_name/wsgi.py

@@ -1,5 +1,5 @@
 """
 """
-Misago settings for {{ project_name }} project.
+WSGI config for {{ project_name }} project.
 
 
 It exposes the WSGI callable as a module-level variable named ``application``.
 It exposes the WSGI callable as a module-level variable named ``application``.
 
 
@@ -11,7 +11,6 @@ import os
 
 
 from django.core.wsgi import get_wsgi_application
 from django.core.wsgi import get_wsgi_application
 
 
-
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
 
 
 application = get_wsgi_application()
 application = get_wsgi_application()