diff --git a/WikiENS/settings/.gitignore b/WikiENS/settings/.gitignore new file mode 100644 index 0000000..2142506 --- /dev/null +++ b/WikiENS/settings/.gitignore @@ -0,0 +1 @@ +secret.py diff --git a/WikiENS/settings/__init__.py b/WikiENS/settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/WikiENS/settings.default.py b/WikiENS/settings/common.py similarity index 59% rename from WikiENS/settings.default.py rename to WikiENS/settings/common.py index cffb20f..87862de 100644 --- a/WikiENS/settings.default.py +++ b/WikiENS/settings/common.py @@ -1,36 +1,42 @@ -""" -Django settings for WikiENS project. - -Generated by 'django-admin startproject' using Django 1.11.1. - -For more information on this file, see -https://docs.djangoproject.com/en/1.11/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.11/ref/settings/ -""" - import os from django.urls import reverse_lazy -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +from django.contrib.messages import constants as messages + +try: + from . import secret +except ImportError: + raise ImportError( + "The secret.py file is missing.\n" + "For a development environment, simply copy secret_example.py" + ) -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "_u5q4-^1qgkqg=i5o5ha*xkd@82#l$e+%m)$v+4y#t-5!g-%g2" - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] +def import_secret(name): + """ + Shorthand for importing a value from the secret module and raising an + informative exception if a secret is missing. + """ + try: + return getattr(secret, name) + except AttributeError: + raise RuntimeError("Secret missing: {}".format(name)) -# Application definition +SECRET_KEY = import_secret("SECRET_KEY") +ADMINS = import_secret("ADMINS") +MANAGERS = ADMINS +EMAIL_HOST = import_secret("EMAIL_HOST") + +DBNAME = import_secret("DBNAME") +DBUSER = import_secret("DBUSER") +DBPASSWD = import_secret("DBPASSWD") + +SERVER_EMAIL = "wiki@www.eleves.ens.fr" + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + INSTALLED_APPS = [ "django.contrib.admin", @@ -46,8 +52,7 @@ INSTALLED_APPS = [ "sekizai", "sorl.thumbnail", "widget_tweaks", - "shared", # Do not move, so templates in `shared` can override - # thoses in `wiki` + "shared", # Keep `shared` above `wiki` to override the default templates "wiki_groups", "wiki", "wiki.plugins.attachments", @@ -85,9 +90,9 @@ TEMPLATES = [ "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", "sekizai.context_processors.sekizai", - ], + ] }, - }, + } ] WSGI_APPLICATION = "WikiENS.wsgi.application" @@ -100,8 +105,11 @@ SITE_ID = 1 DATABASES = { "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + "ENGINE": "django.db.backends.postgresql", + "NAME": DBNAME, + "USER": DBUSER, + "PASSWORD": DBPASSWD, + "HOST": "localhost", } } @@ -111,11 +119,16 @@ DATABASES = { AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + "NAME": ( + # XXX. Cette chaîne est très longue… Je la coupe en deux sinon + # black ne me fiche pas la paix (mais c'est vraiment nul) + "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",}, + {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, + {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"}, + {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"}, ] @@ -133,18 +146,6 @@ USE_L10N = True USE_TZ = True -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.11/howto/static-files/ - -STATIC_URL = "/static/" - - -# Email -# https://docs.djangoproject.com/en/1.11/topics/email/ - -EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" - - # Authentication # https://docs.djangoproject.com/en/1.11/ref/settings/#auth # https://django-allauth.readthedocs.io/en/latest/index.html @@ -159,16 +160,60 @@ SOCIALACCOUNT_ADAPTER = "shared.allauth_adapter.SocialAccountAdapter" HOME_URL = reverse_lazy("wiki:root") LOGIN_URL = "/_profil/login/" +LOGOUT_URL = reverse_lazy("account_logout") LOGIN_REDIRECT_URL = HOME_URL ACCOUNT_LOGOUT_REDIRECT_URL = HOME_URL + +def _user_display(user): + return user.get_full_name() or user.username + + ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False ACCOUNT_HOME_URL = HOME_URL -ACCOUNT_USER_DISPLAY = lambda u: u.get_full_name() or u.username +ACCOUNT_USER_DISPLAY = _user_display + +SOCIALACCOUNT_PROVIDERS = { + "clipper": { + "MESSAGE_SUGGEST_LOGOUT_ON_LOGOUT": True, + "MESSAGE_SUGGEST_LOGOUT_ON_LOGOUT_LEVEL": messages.INFO, + }, +} + + +# Static / media contents + +STATIC_URL = "/_static/" +MEDIA_URL = "/_media/" + # WIKI SETTINGS -LOGOUT_URL = reverse_lazy("account_logout") +WIKI_ATTACHMENTS_EXTENSIONS = [ + "pdf", + "doc", + "odt", + "docx", + "txt", + "md", + "c2p", + "msc", + "png", + "jpg", + "svg", + "ai", + "esf", + "tex", +] + +WIKI_REVISIONS_PER_HOUR = 180 +WIKI_REVISIONS_PER_MINUTES = 180 + +# Dark magic - tell django to use X-Forwarded-* +# This is needed for django-allauth-cas, see +# https://blog.ubuntu.com/2015/08/18/django-behind-a-proxy-fixing-absolute-urls +USE_X_FORWARDED_HOST = True +SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # Use sign up, login, logout, profile settings views of allauth. WIKI_ACCOUNT_HANDLING = False diff --git a/WikiENS/settings/local.py b/WikiENS/settings/local.py new file mode 100644 index 0000000..6771ca2 --- /dev/null +++ b/WikiENS/settings/local.py @@ -0,0 +1,16 @@ +import os + + +from .common import * # noqa +from .common import BASE_DIR + + +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" +DEBUG = True + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + } +} diff --git a/WikiENS/settings/prod.py b/WikiENS/settings/prod.py new file mode 100644 index 0000000..1c420b6 --- /dev/null +++ b/WikiENS/settings/prod.py @@ -0,0 +1,11 @@ +import os + +from .common import * # noqa +from .common import BASE_DIR + + +DEBUG = False +ALLOWED_HOSTS = ["www.eleves.ens.fr", "wiki.eleves.ens.fr"] + +STATIC_ROOT = os.path.join(BASE_DIR, "..", "static") +MEDIA_ROOT = os.path.join(BASE_DIR, "..", "media") diff --git a/WikiENS/settings/secret_example.py b/WikiENS/settings/secret_example.py new file mode 100644 index 0000000..499f35d --- /dev/null +++ b/WikiENS/settings/secret_example.py @@ -0,0 +1,7 @@ +SECRET_KEY = "_u5q4-^1qgkqg=i5o5ha*xkd@82#l$e+%m)$v+4y#t-5!g-%g2" +ADMINS = None +EMAIL_HOST = "localhost" + +DBNAME = "wiki" +DBUSER = "wiki" +DBPASSWD = "dummy" diff --git a/manage.py b/manage.py index 1ae7a2c..bd7b5ad 100755 --- a/manage.py +++ b/manage.py @@ -3,7 +3,7 @@ import os import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WikiENS.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WikiENS.settings.local") try: from django.core.management import execute_from_command_line except ImportError: diff --git a/requirement.txt b/requirements.txt similarity index 73% rename from requirement.txt rename to requirements.txt index 1b7f7be..99847eb 100644 --- a/requirement.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ Django==2.2.* -# django-allauth-ens==1.0.0b2 -git+https://git.eleves.ens.fr/klub-dev-ens/django-allauth-ens.git +git+https://git.eleves.ens.fr/klub-dev-ens/django-allauth-ens.git@1.1.3 wiki==0.5