Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 1 | """ |
| 2 | Django settings for hiccup_server project. |
| 3 | |
| 4 | Generated by 'django-admin startproject' using Django 1.9.7. |
| 5 | |
| 6 | For more information on this file, see |
| 7 | https://docs.djangoproject.com/en/1.9/topics/settings/ |
| 8 | |
| 9 | For the full list of settings and their values, see |
| 10 | https://docs.djangoproject.com/en/1.9/ref/settings/ |
| 11 | """ |
| 12 | |
| 13 | import os |
| 14 | |
| 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
| 16 | BASE_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 Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 23 | SECRET_KEY = "7u+#ha3hk!x+*)clhs46%n*)w1q+5s4+yoc#1!nm0b%fwwrud@" |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 24 | |
| 25 | # SECURITY WARNING: don't run with debug turned on in production! |
Dirk Vogt | f2a3342 | 2016-10-11 17:17:26 +0200 | [diff] [blame] | 26 | DEBUG = True |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 27 | |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 28 | ALLOWED_HOSTS = ["*"] |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 29 | |
| 30 | |
| 31 | # Application definition |
| 32 | |
| 33 | INSTALLED_APPS = [ |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 34 | "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 Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 58 | ] |
| 59 | |
| 60 | MIDDLEWARE_CLASSES = [ |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 61 | "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 Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 69 | ] |
| 70 | |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 71 | ROOT_URLCONF = "hiccup.urls" |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 72 | |
| 73 | TEMPLATES = [ |
| 74 | { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 75 | "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 Vogt | 57a615d | 2017-05-04 22:29:54 +0200 | [diff] [blame] | 84 | # `allauth` needs this from django |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 85 | "django.template.context_processors.request", |
| 86 | ] |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 87 | }, |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 88 | } |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 89 | ] |
| 90 | |
Dirk Vogt | 57a615d | 2017-05-04 22:29:54 +0200 | [diff] [blame] | 91 | AUTHENTICATION_BACKENDS = ( |
| 92 | # Needed to login by username in Django admin, regardless of `allauth` |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 93 | "django.contrib.auth.backends.ModelBackend", |
Dirk Vogt | 57a615d | 2017-05-04 22:29:54 +0200 | [diff] [blame] | 94 | # `allauth` specific authentication methods, such as login by e-mail |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 95 | "allauth.account.auth_backends.AuthenticationBackend", |
Dirk Vogt | 57a615d | 2017-05-04 22:29:54 +0200 | [diff] [blame] | 96 | ) |
| 97 | |
Mitja Nikolaus | 5c3e057 | 2018-07-30 13:36:14 +0200 | [diff] [blame] | 98 | # WSGI_APPLICATION = 'hiccup_server.wsgi.application' |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 99 | |
| 100 | |
| 101 | # Database |
| 102 | # https://docs.djangoproject.com/en/1.9/ref/settings/#databases |
| 103 | |
| 104 | DATABASES = { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 105 | "default": { |
Mitja Nikolaus | 18a96ed | 2018-09-05 16:05:39 +0200 | [diff] [blame] | 106 | "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 Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | |
| 116 | # Password validation |
| 117 | # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators |
| 118 | |
| 119 | AUTH_PASSWORD_VALIDATORS = [ |
| 120 | { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 121 | "NAME": "django.contrib.auth.password_validation" |
| 122 | ".UserAttributeSimilarityValidator" |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 123 | }, |
| 124 | { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 125 | "NAME": "django.contrib.auth.password_validation" |
| 126 | ".MinimumLengthValidator" |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 127 | }, |
| 128 | { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 129 | "NAME": "django.contrib.auth.password_validation" |
| 130 | ".CommonPasswordValidator" |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 131 | }, |
| 132 | { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 133 | "NAME": "django.contrib.auth.password_validation" |
| 134 | ".NumericPasswordValidator" |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 135 | }, |
| 136 | ] |
| 137 | |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 138 | # Internationalization |
| 139 | # https://docs.djangoproject.com/en/1.9/topics/i18n/ |
| 140 | |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 141 | LANGUAGE_CODE = "en-us" |
| 142 | TIME_ZONE = "Europe/Amsterdam" |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 143 | USE_I18N = True |
| 144 | USE_L10N = True |
| 145 | USE_TZ = True |
| 146 | |
Dirk Vogt | 47d80ba | 2016-08-26 09:31:39 +0200 | [diff] [blame] | 147 | REST_FRAMEWORK = { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 148 | "DEFAULT_AUTHENTICATION_CLASSES": ( |
| 149 | "rest_framework.authentication.BasicAuthentication", |
| 150 | "rest_framework.authentication.SessionAuthentication", |
| 151 | "rest_framework.authentication.TokenAuthentication", |
Dirk Vogt | f2a3342 | 2016-10-11 17:17:26 +0200 | [diff] [blame] | 152 | ), |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 153 | "DEFAULT_PERMISSION_CLASSES": ( |
| 154 | "rest_framework.permissions.IsAuthenticated", |
Dirk Vogt | d134521 | 2016-09-14 14:31:45 +0200 | [diff] [blame] | 155 | ), |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 156 | "DEFAULT_FILTER_BACKENDS": ( |
| 157 | "django_filters.rest_framework.DjangoFilterBackend", |
| 158 | ), |
Mitja Nikolaus | 21075cf | 2018-08-30 16:53:21 +0200 | [diff] [blame] | 159 | "DEFAULT_PAGINATION_CLASS": ( |
| 160 | "rest_framework.pagination.LimitOffsetPagination" |
| 161 | ), |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 162 | "PAGE_SIZE": 100, |
Dirk Vogt | 57a615d | 2017-05-04 22:29:54 +0200 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | SITE_ID = 1 |
| 166 | |
Mitja Nikolaus | 5c3e057 | 2018-07-30 13:36:14 +0200 | [diff] [blame] | 167 | SOCIALACCOUNT_ADAPTER = "hiccup.allauth_adapters.FairphoneAccountAdapter" |
| 168 | LOGIN_REDIRECT_URL = "/hiccup_stats/" |
Dirk Vogt | 57a615d | 2017-05-04 22:29:54 +0200 | [diff] [blame] | 169 | # disable form signups |
Mitja Nikolaus | 5c3e057 | 2018-07-30 13:36:14 +0200 | [diff] [blame] | 170 | ACCOUNT_ADAPTER = "hiccup.allauth_adapters.FormAccountAdapter" |
| 171 | ACCOUNT_EMAIL_REQUIRED = True |
| 172 | ACCOUNT_LOGOUT_REDIRECT_URL = "/accounts/login/" |
Dirk Vogt | 57a615d | 2017-05-04 22:29:54 +0200 | [diff] [blame] | 173 | |
| 174 | SOCIALACCOUNT_PROVIDERS = { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 175 | "google": { |
| 176 | "SCOPE": ["profile", "email"], |
| 177 | "AUTH_PARAMS": {"access_type": "online"}, |
Dirk Vogt | 57a615d | 2017-05-04 22:29:54 +0200 | [diff] [blame] | 178 | } |
Dirk Vogt | 47d80ba | 2016-08-26 09:31:39 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Dirk Vogt | f130c75 | 2016-08-23 14:45:01 +0200 | [diff] [blame] | 181 | # Static files (CSS, JavaScript, Images) |
| 182 | # https://docs.djangoproject.com/en/1.9/howto/static-files/ |
| 183 | |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 184 | STATIC_URL = "/static/" |
Dirk Vogt | 20539e5 | 2016-08-26 11:17:35 +0200 | [diff] [blame] | 185 | |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 186 | STATIC_ROOT = os.path.join(BASE_DIR, "static") |
Dirk Vogt | d8b956b | 2016-11-22 15:03:21 +0100 | [diff] [blame] | 187 | |
Franz-Xaver Geiger | 38a66bc | 2018-10-09 14:52:26 +0200 | [diff] [blame] | 188 | MEDIA_ROOT = os.path.join(BASE_DIR, "crashreport_uploads") |
| 189 | |
Franz-Xaver Geiger | 69909c9 | 2018-02-27 17:02:38 +0100 | [diff] [blame] | 190 | |
| 191 | # Logging |
| 192 | # https://docs.djangoproject.com/en/2.0/topics/logging/#examples |
| 193 | |
| 194 | LOGGING = { |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 195 | "version": 1, |
| 196 | "disable_existing_loggers": False, |
| 197 | "handlers": { |
| 198 | "file": { |
| 199 | "level": "DEBUG", |
| 200 | "class": "logging.FileHandler", |
| 201 | "filename": os.path.join(BASE_DIR, "debug.log"), |
| 202 | } |
Franz-Xaver Geiger | 69909c9 | 2018-02-27 17:02:38 +0100 | [diff] [blame] | 203 | }, |
Mitja Nikolaus | cb50f2c | 2018-08-24 13:54:48 +0200 | [diff] [blame] | 204 | "loggers": { |
| 205 | "django": {"handlers": ["file"], "level": "DEBUG", "propagate": True} |
Franz-Xaver Geiger | 69909c9 | 2018-02-27 17:02:38 +0100 | [diff] [blame] | 206 | }, |
| 207 | } |
| 208 | |
Mitja Nikolaus | d199506 | 2018-07-30 14:10:27 +0200 | [diff] [blame] | 209 | |
| 210 | # Automatic documentation generation |
| 211 | # https://drf-yasg.readthedocs.io/en/stable/index.html |
| 212 | |
Mitja Nikolaus | 4d759da | 2018-08-28 15:31:29 +0200 | [diff] [blame] | 213 | SWAGGER_SETTINGS = { |
| 214 | "DEFAULT_INFO": "hiccup.urls.api_info", |
| 215 | "SECURITY_DEFINITIONS": { |
| 216 | "Device token authentication": { |
| 217 | "type": "apiKey", |
| 218 | "name": "Authorization", |
| 219 | "in": "header", |
| 220 | "description": ( |
| 221 | "Authenticate using a token that was returned on successful " |
| 222 | "registration of a new device. The token can only be used to " |
| 223 | "authenticate requests that target the device with the " |
| 224 | "matching UUID. The token has to be put in the request header: " |
| 225 | "'Authorization: Token <AUTH_TOKEN>'" |
| 226 | ), |
| 227 | }, |
| 228 | "Google OAuth": { |
| 229 | "type": "oauth2", |
| 230 | "flow": "implicit", |
| 231 | "authorizationUrl": "/accounts/google/login/callback/", |
| 232 | "scopes": {}, |
| 233 | "description": ( |
| 234 | "Authenticate using a Google account. Only E-mail addresses " |
| 235 | "in the @fairphone.com domain are allowed." |
| 236 | ), |
| 237 | }, |
| 238 | }, |
| 239 | } |
Mitja Nikolaus | d199506 | 2018-07-30 14:10:27 +0200 | [diff] [blame] | 240 | |
Dirk Vogt | d8b956b | 2016-11-22 15:03:21 +0100 | [diff] [blame] | 241 | try: |
Mitja Nikolaus | bcaf502 | 2018-08-30 16:40:38 +0200 | [diff] [blame] | 242 | from local_settings import * # noqa: F403,F401 pylint: disable=W0401,W0614 |
Mitja Nikolaus | e7d3c76 | 2018-08-30 17:29:27 +0200 | [diff] [blame] | 243 | except ImportError: |
Dirk Vogt | d8b956b | 2016-11-22 15:03:21 +0100 | [diff] [blame] | 244 | pass |