blob: 8a06b15476303db781c56f972244ed457cdfca8e [file] [log] [blame]
Dirk Vogtf130c752016-08-23 14:45:01 +02001"""
2Django settings for hiccup_server project.
3
4Generated by 'django-admin startproject' using Django 1.9.7.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/1.9/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/1.9/ref/settings/
11"""
12
13import os
14
15# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17
18
19# Quick-start development settings - unsuitable for production
20# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
21
22# SECURITY WARNING: keep the secret key used in production secret!
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020023SECRET_KEY = "7u+#ha3hk!x+*)clhs46%n*)w1q+5s4+yoc#1!nm0b%fwwrud@"
Dirk Vogtf130c752016-08-23 14:45:01 +020024
25# SECURITY WARNING: don't run with debug turned on in production!
Dirk Vogtf2a33422016-10-11 17:17:26 +020026DEBUG = True
Dirk Vogtf130c752016-08-23 14:45:01 +020027
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020028ALLOWED_HOSTS = ["*"]
Dirk Vogtf130c752016-08-23 14:45:01 +020029
30
31# Application definition
32
33INSTALLED_APPS = [
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020034 "django.contrib.admin",
35 "django.contrib.auth",
36 "django.contrib.contenttypes",
37 "django.contrib.sessions",
38 "django.contrib.sites",
39 "django.contrib.messages",
40 "django.contrib.staticfiles",
41 "rest_framework",
42 "rest_framework.authtoken",
43 "crashreports",
44 "crashreport_stats",
45 "taggit",
46 "crispy_forms",
47 "bootstrap3",
48 "bootstrapform",
49 "django_extensions",
50 "django_filters",
51 "djfrontend",
52 "djfrontend.skeleton",
53 "allauth",
54 "allauth.account",
55 "allauth.socialaccount",
56 "allauth.socialaccount.providers.google",
57 "drf_yasg",
Dirk Vogtf130c752016-08-23 14:45:01 +020058]
59
60MIDDLEWARE_CLASSES = [
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020061 "django.middleware.security.SecurityMiddleware",
62 "django.contrib.sessions.middleware.SessionMiddleware",
63 "django.middleware.common.CommonMiddleware",
64 "django.middleware.csrf.CsrfViewMiddleware",
65 "django.contrib.auth.middleware.AuthenticationMiddleware",
66 "django.contrib.auth.middleware.SessionAuthenticationMiddleware",
67 "django.contrib.messages.middleware.MessageMiddleware",
68 "django.middleware.clickjacking.XFrameOptionsMiddleware",
Dirk Vogtf130c752016-08-23 14:45:01 +020069]
70
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020071ROOT_URLCONF = "hiccup.urls"
Dirk Vogtf130c752016-08-23 14:45:01 +020072
73TEMPLATES = [
74 {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020075 "BACKEND": "django.template.backends.django.DjangoTemplates",
76 "DIRS": [os.path.join(BASE_DIR, "hiccup", "templates")],
77 "APP_DIRS": True,
78 "OPTIONS": {
79 "context_processors": [
80 "django.template.context_processors.debug",
81 "django.template.context_processors.request",
82 "django.contrib.auth.context_processors.auth",
83 "django.contrib.messages.context_processors.messages",
Dirk Vogt57a615d2017-05-04 22:29:54 +020084 # `allauth` needs this from django
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020085 "django.template.context_processors.request",
86 ]
Dirk Vogtf130c752016-08-23 14:45:01 +020087 },
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020088 }
Dirk Vogtf130c752016-08-23 14:45:01 +020089]
90
Dirk Vogt57a615d2017-05-04 22:29:54 +020091AUTHENTICATION_BACKENDS = (
92 # Needed to login by username in Django admin, regardless of `allauth`
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020093 "django.contrib.auth.backends.ModelBackend",
Dirk Vogt57a615d2017-05-04 22:29:54 +020094 # `allauth` specific authentication methods, such as login by e-mail
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +020095 "allauth.account.auth_backends.AuthenticationBackend",
Dirk Vogt57a615d2017-05-04 22:29:54 +020096)
97
Mitja Nikolaus5c3e0572018-07-30 13:36:14 +020098# WSGI_APPLICATION = 'hiccup_server.wsgi.application'
Dirk Vogtf130c752016-08-23 14:45:01 +020099
100
101# Database
102# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
103
104DATABASES = {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200105 "default": {
Mitja Nikolaus18a96ed2018-09-05 16:05:39 +0200106 "ENGINE": "django.db.backends.postgresql_psycopg2",
107 "HOST": "", # Connect to database through UNIX domain sockets
108 "PORT": "", # Not needed for UNIX domain sockets
109 "NAME": os.environ.get("USER"),
110 "USER": os.environ.get("USER"),
111 "PASSWORD": "", # Not needed for UNIX domain sockets
Dirk Vogtf130c752016-08-23 14:45:01 +0200112 }
113}
114
115
116# Password validation
117# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
118
119AUTH_PASSWORD_VALIDATORS = [
120 {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200121 "NAME": "django.contrib.auth.password_validation"
122 ".UserAttributeSimilarityValidator"
Dirk Vogtf130c752016-08-23 14:45:01 +0200123 },
124 {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200125 "NAME": "django.contrib.auth.password_validation"
126 ".MinimumLengthValidator"
Dirk Vogtf130c752016-08-23 14:45:01 +0200127 },
128 {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200129 "NAME": "django.contrib.auth.password_validation"
130 ".CommonPasswordValidator"
Dirk Vogtf130c752016-08-23 14:45:01 +0200131 },
132 {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200133 "NAME": "django.contrib.auth.password_validation"
134 ".NumericPasswordValidator"
Dirk Vogtf130c752016-08-23 14:45:01 +0200135 },
136]
137
Dirk Vogtf130c752016-08-23 14:45:01 +0200138# Internationalization
139# https://docs.djangoproject.com/en/1.9/topics/i18n/
140
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200141LANGUAGE_CODE = "en-us"
142TIME_ZONE = "Europe/Amsterdam"
Dirk Vogtf130c752016-08-23 14:45:01 +0200143USE_I18N = True
144USE_L10N = True
145USE_TZ = True
146
Dirk Vogt47d80ba2016-08-26 09:31:39 +0200147REST_FRAMEWORK = {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200148 "DEFAULT_AUTHENTICATION_CLASSES": (
149 "rest_framework.authentication.BasicAuthentication",
150 "rest_framework.authentication.SessionAuthentication",
151 "rest_framework.authentication.TokenAuthentication",
Dirk Vogtf2a33422016-10-11 17:17:26 +0200152 ),
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200153 "DEFAULT_PERMISSION_CLASSES": (
154 "rest_framework.permissions.IsAuthenticated",
Dirk Vogtd1345212016-09-14 14:31:45 +0200155 ),
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200156 "DEFAULT_FILTER_BACKENDS": (
157 "django_filters.rest_framework.DjangoFilterBackend",
158 ),
Mitja Nikolaus21075cf2018-08-30 16:53:21 +0200159 "DEFAULT_PAGINATION_CLASS": (
160 "rest_framework.pagination.LimitOffsetPagination"
161 ),
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200162 "PAGE_SIZE": 100,
Dirk Vogt57a615d2017-05-04 22:29:54 +0200163}
164
165SITE_ID = 1
166
Mitja Nikolaus5c3e0572018-07-30 13:36:14 +0200167SOCIALACCOUNT_ADAPTER = "hiccup.allauth_adapters.FairphoneAccountAdapter"
168LOGIN_REDIRECT_URL = "/hiccup_stats/"
Dirk Vogt57a615d2017-05-04 22:29:54 +0200169# disable form signups
Mitja Nikolaus5c3e0572018-07-30 13:36:14 +0200170ACCOUNT_ADAPTER = "hiccup.allauth_adapters.FormAccountAdapter"
171ACCOUNT_EMAIL_REQUIRED = True
172ACCOUNT_LOGOUT_REDIRECT_URL = "/accounts/login/"
Dirk Vogt57a615d2017-05-04 22:29:54 +0200173
174SOCIALACCOUNT_PROVIDERS = {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200175 "google": {
176 "SCOPE": ["profile", "email"],
177 "AUTH_PARAMS": {"access_type": "online"},
Dirk Vogt57a615d2017-05-04 22:29:54 +0200178 }
Dirk Vogt47d80ba2016-08-26 09:31:39 +0200179}
180
Mitja Nikolaus8b801092018-12-10 10:36:44 +0100181# To use the Google OAuth feature, overwrite these values with the correct
182# client id and secret in your local settings before running the migrations.
183SOCIALACCOUNT_GOOGLE_CLIENT_ID = ""
184SOCIALACCOUNT_GOOGLE_SECRET = ""
185
Dirk Vogtf130c752016-08-23 14:45:01 +0200186# Static files (CSS, JavaScript, Images)
187# https://docs.djangoproject.com/en/1.9/howto/static-files/
188
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200189STATIC_URL = "/static/"
Dirk Vogt20539e52016-08-26 11:17:35 +0200190
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200191STATIC_ROOT = os.path.join(BASE_DIR, "static")
Dirk Vogtd8b956b2016-11-22 15:03:21 +0100192
Franz-Xaver Geiger38a66bc2018-10-09 14:52:26 +0200193MEDIA_ROOT = os.path.join(BASE_DIR, "crashreport_uploads")
194
Franz-Xaver Geiger69909c92018-02-27 17:02:38 +0100195
196# Logging
197# https://docs.djangoproject.com/en/2.0/topics/logging/#examples
198
199LOGGING = {
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200200 "version": 1,
201 "disable_existing_loggers": False,
202 "handlers": {
203 "file": {
204 "level": "DEBUG",
205 "class": "logging.FileHandler",
206 "filename": os.path.join(BASE_DIR, "debug.log"),
207 }
Franz-Xaver Geiger69909c92018-02-27 17:02:38 +0100208 },
Mitja Nikolauscb50f2c2018-08-24 13:54:48 +0200209 "loggers": {
Mitja Nikolaus88cc94e2018-11-23 13:47:22 +0100210 "django": {"handlers": ["file"], "level": "DEBUG", "propagate": True},
211 "hiccup": {"handlers": ["file"], "level": "DEBUG", "propagate": True},
212 "crashreports": {
213 "handlers": ["file"],
214 "level": "DEBUG",
215 "propagate": True,
216 },
217 "crashreport_stats": {
218 "handlers": ["file"],
219 "level": "DEBUG",
220 "propagate": True,
221 },
Franz-Xaver Geiger69909c92018-02-27 17:02:38 +0100222 },
223}
224
Mitja Nikolausd1995062018-07-30 14:10:27 +0200225
226# Automatic documentation generation
227# https://drf-yasg.readthedocs.io/en/stable/index.html
228
Mitja Nikolaus4d759da2018-08-28 15:31:29 +0200229SWAGGER_SETTINGS = {
230 "DEFAULT_INFO": "hiccup.urls.api_info",
231 "SECURITY_DEFINITIONS": {
232 "Device token authentication": {
233 "type": "apiKey",
234 "name": "Authorization",
235 "in": "header",
236 "description": (
237 "Authenticate using a token that was returned on successful "
238 "registration of a new device. The token can only be used to "
239 "authenticate requests that target the device with the "
240 "matching UUID. The token has to be put in the request header: "
241 "'Authorization: Token <AUTH_TOKEN>'"
242 ),
243 },
244 "Google OAuth": {
245 "type": "oauth2",
246 "flow": "implicit",
247 "authorizationUrl": "/accounts/google/login/callback/",
248 "scopes": {},
249 "description": (
250 "Authenticate using a Google account. Only E-mail addresses "
251 "in the @fairphone.com domain are allowed."
252 ),
253 },
254 },
255}
Mitja Nikolausd1995062018-07-30 14:10:27 +0200256
Dirk Vogtd8b956b2016-11-22 15:03:21 +0100257try:
Mitja Nikolausbcaf5022018-08-30 16:40:38 +0200258 from local_settings import * # noqa: F403,F401 pylint: disable=W0401,W0614
Mitja Nikolause7d3c762018-08-30 17:29:27 +0200259except ImportError:
Dirk Vogtd8b956b2016-11-22 15:03:21 +0100260 pass