Skip to content

Commit 77ceb7e

Browse files
committed
Adapt settings to Django 4
1 parent 5544d0e commit 77ceb7e

File tree

13 files changed

+129
-102
lines changed

13 files changed

+129
-102
lines changed

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ services:
2727
- SOCIAL_AUTH_GOOGLE_OAUTH2_KEY
2828
- SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET
2929
- SOCIAL_AUTH_FACEBOOK_KEY
30-
- SOCIAL_AUTH_FACEBOOK_SECRET
30+
- SOCIAL_AUTH_FACEBOOK_SECRET
31+
- SUBMISSION_URL

example.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ HTTP_PORT=8000
77
ALLOWED_HOSTS=127.0.0.1
88
SECRET_KEY=t2-r&t0yj0b%q$b^@ptqya=13mq0rsz1_5&h^ub-=+(ueiqsql
99
DJANGO_SETTINGS_MODULE=web.settings.docker
10-
STATIC_PATH=./data/static
10+
STATIC_PATH=./data/static
11+
SUBMISSION_URL=http://127.0.0.1:8000

web/Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ RUN mkdir -p /var/static
99
RUN chown -R tomo /src /var/static
1010
USER tomo
1111
ENV UWSGI_CHDIR=/src
12-
ENV UWSGI_MODULE=web.wsgi.docker:application
12+
ENV UWSGI_MODULE=web.wsgi:application
1313
ENV UWSGI_MASTER=True
14-
# Enables us to simply restart UWSGI by deleting /tmp/project-master.pid
15-
ENV UWSGI_PIDFILE=/tmp/project-master.pid
1614
ENV UWSGI_VACUUM=True
1715
ENV UWSGI_MAX_REQUESTS=5000
1816
ENV UWSGI_UID=tomo
1917
ENV UWSGI_GID=tomo
20-
ENV UWSGI_HTTP=:8080
18+
ENV UWSGI_SOCKET=:8080
2119
ENV UWSGI_STATIC_MAP=/static=/var/static
22-
CMD ./manage.py migrate --no-input && ./manage.py collectstatic --no-input && uwsgi
20+
CMD uwsgi

web/manage.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
23
import os
34
import sys
45

5-
if __name__ == "__main__":
6+
7+
def main():
8+
"""Run administrative tasks."""
69
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web.settings.local")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
719

8-
from django.core.management import execute_from_command_line
920

10-
execute_from_command_line(sys.argv)
21+
if __name__ == "__main__":
22+
main()

web/web/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for web project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web.settings.local")
15+
16+
application = get_asgi_application()

web/web/settings/arnes.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
from .docker import *
22

3-
DEBUG = False
4-
5-
WSGI_APPLICATION = "web.wsgi.arnes.application"
6-
7-
MIDDLEWARE = (
8-
"django.contrib.sessions.middleware.SessionMiddleware",
9-
"django.middleware.locale.LocaleMiddleware",
10-
"django.middleware.common.CommonMiddleware",
11-
"django.middleware.csrf.CsrfViewMiddleware",
12-
"django.contrib.auth.middleware.AuthenticationMiddleware",
3+
MIDDLEWARE.insert(
4+
MIDDLEWARE.index("django.contrib.auth.middleware.AuthenticationMiddleware") + 1,
135
"shibboleth.middleware.ShibbolethRemoteUserMiddleware",
14-
"django.contrib.messages.middleware.MessageMiddleware",
15-
"django.middleware.clickjacking.XFrameOptionsMiddleware",
16-
"simple_history.middleware.HistoryRequestMiddleware",
176
)
187

8+
DEBUG = False
9+
1910
SHIBBOLETH_ATTRIBUTE_MAP = {
2011
"mail": (True, "username"),
2112
"givenName": (True, "first_name"),
@@ -37,4 +28,3 @@
3728
SOCIAL_AUTH_FACEBOOK_SCOPE = ["email"]
3829
SOCIAL_AUTH_USER_MODEL = "users.User"
3930
SOCIAL_AUTH_FACEBOOK_API_VERSION = "2.11"
40-
SUBMISSION_URL = "https://www.projekt-tomo.si"

web/web/settings/common.py

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
"""
2+
Django settings for web project.
3+
4+
Generated by 'django-admin startproject' using Django 4.1.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.1/ref/settings/
11+
"""
12+
113
import os
14+
from pathlib import Path
215

3-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
16+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
17+
BASE_DIR = Path(__file__).resolve().parent.parent
18+
19+
20+
# Application definition
421

522
INSTALLED_APPS = [
623
"django.contrib.admin",
@@ -23,6 +40,7 @@
2340
]
2441

2542
MIDDLEWARE = [
43+
"django.middleware.security.SecurityMiddleware",
2644
"django.contrib.sessions.middleware.SessionMiddleware",
2745
"django.middleware.locale.LocaleMiddleware",
2846
"django.middleware.common.CommonMiddleware",
@@ -35,43 +53,72 @@
3553

3654
ROOT_URLCONF = "web.urls"
3755

38-
LANGUAGE_CODE = "en"
39-
40-
TIME_ZONE = "UTC"
41-
42-
USE_I18N = True
43-
44-
USE_L10N = True
45-
46-
USE_TZ = True
47-
48-
AUTH_USER_MODEL = "users.User"
49-
5056
TEMPLATES = [
5157
{
5258
"BACKEND": "django.template.backends.django.DjangoTemplates",
5359
"DIRS": [
54-
os.path.join(BASE_DIR, "templates"),
60+
BASE_DIR / ".." / "templates",
5561
],
5662
"APP_DIRS": True,
5763
"OPTIONS": {
5864
"context_processors": [
59-
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
60-
# list if you haven't customized them:
61-
"django.contrib.auth.context_processors.auth",
6265
"django.template.context_processors.debug",
63-
"django.template.context_processors.i18n",
64-
"django.template.context_processors.media",
65-
"django.template.context_processors.static",
66-
"django.template.context_processors.tz",
67-
"django.contrib.messages.context_processors.messages",
6866
"django.template.context_processors.request",
67+
"django.contrib.auth.context_processors.auth",
68+
"django.contrib.messages.context_processors.messages",
6969
],
7070
},
7171
},
7272
]
7373

74-
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
74+
WSGI_APPLICATION = "web.wsgi.application"
75+
76+
77+
# Password validation
78+
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
79+
80+
AUTH_PASSWORD_VALIDATORS = [
81+
{
82+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
83+
},
84+
{
85+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
86+
},
87+
{
88+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
89+
},
90+
{
91+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
92+
},
93+
]
94+
95+
96+
# Internationalization
97+
# https://docs.djangoproject.com/en/4.1/topics/i18n/
98+
99+
LANGUAGE_CODE = "en-us"
100+
101+
TIME_ZONE = "UTC"
102+
103+
USE_I18N = True
104+
105+
USE_TZ = True
106+
107+
108+
# Static files (CSS, JavaScript, Images)
109+
# https://docs.djangoproject.com/en/4.1/howto/static-files/
110+
111+
STATIC_URL = "static/"
112+
113+
# Default primary key field type
114+
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
115+
116+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
117+
118+
119+
AUTH_USER_MODEL = "users.User"
120+
121+
LOCALE_PATHS = [BASE_DIR / "locale"]
75122

76123
LOGGING = {
77124
"version": 1,
@@ -80,7 +127,7 @@
80127
"file": {
81128
"level": "WARNING", # 'DEBUG'
82129
"class": "logging.FileHandler",
83-
"filename": BASE_DIR + "/debug.log",
130+
"filename": BASE_DIR / "debug.log",
84131
},
85132
},
86133
"loggers": {
@@ -92,4 +139,6 @@
92139
},
93140
}
94141

95-
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
142+
SUBMISSION_URL = os.environ.get("SUBMISSION_URL", "http://127.0.0.1:8000")
143+
LOGIN_REDIRECT_URL = "/"
144+
STATIC_URL = "/static/"

web/web/settings/docker.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
ALLOWED_HOSTS = [os.environ["ALLOWED_HOSTS"]]
88

9-
WSGI_APPLICATION = "web.wsgi.docker.application"
10-
119
DATABASES = {
1210
"default": {
1311
"ENGINE": "django.db.backends.postgresql_psycopg2",
@@ -20,7 +18,3 @@
2018
}
2119

2220
STATIC_ROOT = "/var/static/"
23-
STATIC_URL = "/static/"
24-
25-
LOGIN_REDIRECT_URL = "/"
26-
SUBMISSION_URL = "http://127.0.0.1:8000"

web/web/settings/local.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
from .common import *
22

3-
INSTALLED_APPS += [
4-
"silk",
5-
]
3+
INSTALLED_APPS.append("silk")
64
MIDDLEWARE.insert(0, "silk.middleware.SilkyMiddleware")
75

6+
# Quick-start development settings - unsuitable for production
7+
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
8+
9+
# SECURITY WARNING: keep the secret key used in production secret!
810
SECRET_KEY = "0vb+-_-52phz@ii^cxr+mlgvmn6fctd+v5qpnv&k+-00#u-==0"
911

12+
# SECURITY WARNING: don't run with debug turned on in production!
1013
DEBUG = True
1114

1215
ALLOWED_HOSTS = []
1316

14-
WSGI_APPLICATION = "web.wsgi.local.application"
17+
# Database
18+
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
1519

1620
DATABASES = {
1721
"default": {
1822
"ENGINE": "django.db.backends.sqlite3",
19-
"NAME": "tomo.sqlite3",
23+
"NAME": BASE_DIR / "db.sqlite3",
2024
}
2125
}
22-
23-
STATIC_URL = "/static/"
24-
LOGIN_URL = "/accounts/login/"
25-
LOGOUT_URL = "/accounts/logout/"
26-
LOGIN_REDIRECT_URL = "/"
27-
SUBMISSION_URL = "http://127.0.0.1:8000"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
It exposes the WSGI callable as a module-level variable named ``application``.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
88
"""
99

1010
import os
1111

12-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web.settings.local")
13-
1412
from django.core.wsgi import get_wsgi_application
1513

14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web.settings.local")
15+
1616
application = get_wsgi_application()

0 commit comments

Comments
 (0)