diff --git a/.editorconfig b/.editorconfig index 8ac421b7..658dda71 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,7 +8,7 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.{py,rst,ini}] +[*.{py,rst,ini,sh}] indent_style = space indent_size = 4 diff --git a/README.md b/README.md index 8a1be72e..ea63ae0d 100644 --- a/README.md +++ b/README.md @@ -11,38 +11,32 @@ npm run tailwind # run vue vite dev server cd client && npm run dev -# run django dev server -cd server && python manage.py runserver +# reset db and run django dev server +./prepare_server.sh ``` ## Installation See `.tool-versions` file for used django and node version +You have to set up at least the following environment variables: + +```bash +export IT_APP_ENVIRONMENT=development +``` + +See `.env_secrets/local_daniel.env` for more possible environment variables. +Especially set correct values for `POSTGRES_*` and `DATABASE_URL` + + ### Server part -Run every sub command in the `server` directory - -Create a new PostgreSQL database and role +The "prepare_server.sh" script will create the database according to `POSTGRE_*` environment variables. +It will also setup the tables for django and run the django development server. ```bash -createdb vbv_lernwelt -createuser vbv_lernwelt -``` - -Set the environment variable accordingly - -```bash -export VBV_DATABASE_URL='postgres://vbv_lernwelt@localhost:5432/vbv_lernwelt' -``` - -Set `VBV_DJANGO_READ_DOT_ENV_FILE=True` to make the config read the `example.env` file (with direnv!?). - -```bash -python manage.py migrate - -# sync server -python manage.py runserver +# will initial`migrate` and `runserver` etc... +./prepare_server.sh # or async server # uvicorn config.asgi:application --host 0.0.0.0 --reload @@ -50,8 +44,6 @@ python manage.py runserver ### Client part -Run every command in the `client` directory - ```bash npm install diff --git a/caprover_create_app.py b/caprover_create_app.py index 44cde962..652f1d88 100644 --- a/caprover_create_app.py +++ b/caprover_create_app.py @@ -44,11 +44,11 @@ cap.create_and_update_app( image_name='docker.io/iterativ/vbv-lernwelt-django', environment_variables={ # 'DJANGO_SETTINGS_MODULE': 'config.settings.base', - 'VBV_DJANGO_SECRET_KEY': env.str('VBV_DJANGO_SECRET_KEY'), - 'VBV_DJANGO_ADMIN_URL': env.str('VBV_DJANGO_ADMIN_URL'), - 'VBV_DJANGO_ALLOWED_HOSTS': env.str('VBV_DJANGO_ALLOWED_HOSTS'), - 'VBV_SENTRY_DSN': env.str('VBV_SENTRY_DSN'), - 'VBV_DJANGO_DEV_MODE': 'caprover', + 'IT_DJANGO_SECRET_KEY': env.str('IT_DJANGO_SECRET_KEY'), + 'IT_DJANGO_ADMIN_URL': env.str('IT_DJANGO_ADMIN_URL'), + 'IT_DJANGO_ALLOWED_HOSTS': env.str('IT_DJANGO_ALLOWED_HOSTS'), + 'IT_SENTRY_DSN': env.str('IT_SENTRY_DSN'), + 'IT_APP_ENVIRONMENT': 'caprover', 'POSTGRES_HOST': 'srv-captain--vbv-lernwelt-postgres-db', 'POSTGRES_PORT': 5432, 'POSTGRES_DB': db_name, diff --git a/compose/django/docker_entrypoint.sh b/compose/django/docker_entrypoint.sh index 5192d90e..524f6902 100644 --- a/compose/django/docker_entrypoint.sh +++ b/compose/django/docker_entrypoint.sh @@ -13,9 +13,9 @@ if [ -z "${POSTGRES_USER}" ]; then base_postgres_image_default_user='postgres' export POSTGRES_USER="${base_postgres_image_default_user}" fi -export VBV_DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" +export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" -echo $VBV_DATABASE_URL +echo $DATABASE_URL postgres_ready() { python << END diff --git a/env/docker_local.env b/env/docker_local.env index 93a5c471..7919aebc 100644 --- a/env/docker_local.env +++ b/env/docker_local.env @@ -8,5 +8,5 @@ POSTGRES_PASSWORD=hNqfCdG6bwCLcnfboDtNM1L2Hiwp8GuKp1DJ6t2rcKl15Vls2QbByoIZ6IQlci # General # ------------------------------------------------------------------------------ -VBV_DJANGO_LOCAL_DOCKER=True +IT_DJANGO_LOCAL_DOCKER=True IPYTHONDIR=/app/.ipython diff --git a/env_secrets/caprover.env b/env_secrets/caprover.env index c1f40ca6..738c5c3f 100644 Binary files a/env_secrets/caprover.env and b/env_secrets/caprover.env differ diff --git a/env_secrets/local_daniel.env b/env_secrets/local_daniel.env index b0f76bee..2cbf413e 100644 Binary files a/env_secrets/local_daniel.env and b/env_secrets/local_daniel.env differ diff --git a/env_secrets/local_lorenz.env b/env_secrets/local_lorenz.env index 611e670c..4104dedb 100644 Binary files a/env_secrets/local_lorenz.env and b/env_secrets/local_lorenz.env differ diff --git a/env_secrets/production.env b/env_secrets/production.env index 36afa782..7169a777 100644 Binary files a/env_secrets/production.env and b/env_secrets/production.env differ diff --git a/example.env b/example.env new file mode 100644 index 00000000..06329196 --- /dev/null +++ b/example.env @@ -0,0 +1 @@ +export IT_APP_ENVIRONMENT='development' diff --git a/local-setup-for-tests.sh b/local-setup-for-tests.sh deleted file mode 100755 index f861cfe5..00000000 --- a/local-setup-for-tests.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -#export DATABASE_HOST=postgres -#export DATABASE_PORT=5432 -#export DATABASE_URL=postgres://$DATABASE_USER:$PG_PASSWORD@$DATABASE_HOST:$DATABASE_PORT/$DATABASE_NAME -# -#echo $DATABASE_URL -#DJANGO_SETTINGS_MODULE=config.settings.base -#DATABASE_NAME=vbv_lernwelt -SKIP_SETUP=false -## - -echo "Setting up VBV Project for Local usage" -if [ "$SKIP_SETUP" = false ]; then - if [ -z "$PG_PORT" ]; then # if the port is set in the env, use iterg - DB_PORT=""; - else - DB_PORT="-p $PG_PORT"; - fi - if [ -z "$PG_USER" ]; then # if the user is set in the env, use it - DB_USER=""; - else - DB_USER="-U $PG_USER"; - fi - echo "psql -h localhost --port=$DB_PORT --username=$DB_USER -c 'drop database if exists' $DATABASE_NAME;" - - echo "Drop all connections to the database" - psql -h localhost --port=$DB_PORT --username=$DB_USER -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$DATABASE_NAME' AND pid <> pg_backend_pid();" - - echo "Drop database: $DATABASE_NAME" - psql -h localhost --port=$DB_PORT --username=$DB_USER -c "drop database if exists $DATABASE_NAME;" - - echo "Create database: $DATABASE_NAME" - psql -h localhost --port=$DB_PORT --username=$DB_USER -c "create database $DATABASE_NAME;" - - # reset data - python3 server/manage.py createcachetable --settings="$DJANGO_SETTINGS_MODULE" - python3 server/manage.py migrate --settings="$DJANGO_SETTINGS_MODULE" - python3 server/manage.py create_default_users --settings="$DJANGO_SETTINGS_MODULE" - python3 server/manage.py create_default_learningpath --settings="$DJANGO_SETTINGS_MODULE" -# -# # make django translations - (cd server && python3 manage.py compilemessages --settings="$DJANGO_SETTINGS_MODULE") -fi - diff --git a/prepare_server.sh b/prepare_server.sh new file mode 100755 index 00000000..655f1fe5 --- /dev/null +++ b/prepare_server.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +if [ -z "$CI" ]; +then + # kill all subprocess on exit + trap "exit" INT TERM ERR + trap "kill 0" EXIT +else echo "CI is set to $CI"; +fi + +# script should fail when any process returns non zero code +set -ev + +# handle arguments +SKIP_SETUP=false +START_BACKGROUND=false + +for i in "$@" +do +case $i in + --start-background) + START_BACKGROUND=true + shift # past argument + ;; + --skip-setup) + SKIP_SETUP=true + shift # past argument with no value + ;; + *) + # unknown option + ;; +esac +done + +echo "SKIP_SETUP = ${SKIP_SETUP}" + +POSTGRES_DB=${POSTGRES_DB:-vbv_lernwelt} +DJANGO_PORT=${DJANGO_PORT:-8000} + +mypsql() { + psql -h "${POSTGRES_HOST:-localhost}" -p "${POSTGRES_PORT:-5432}" -U "${POSTGRES_USER:-postgres}" "$@" +} + +if [ "$SKIP_SETUP" = false ]; then + echo "Drop all connections to $POSTGRES_DB" + mypsql -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$POSTGRES_DB' AND pid <> pg_backend_pid();" > /dev/null 2>&1 + echo "Drop database: $POSTGRES_DB" + mypsql -c "drop database if exists $POSTGRES_DB;" + echo "Create database: $POSTGRES_DB" + mypsql -c "create database $POSTGRES_DB;" + + echo "initialize database for django" + python3 server/manage.py createcachetable --settings="$DJANGO_SETTINGS_MODULE" + python3 server/manage.py migrate --settings="$DJANGO_SETTINGS_MODULE" + python3 server/manage.py create_default_users --settings="$DJANGO_SETTINGS_MODULE" + python3 server/manage.py create_default_learningpath --settings="$DJANGO_SETTINGS_MODULE" + + # make django translations + (cd server && python3 manage.py compilemessages --settings="$DJANGO_SETTINGS_MODULE") +else + echo "else" +# python3 src/manage.py recreate_customer_data_for_integration_tests --settings="$DJANGO_SETTINGS_MODULE" +fi + +if [ "$START_BACKGROUND" = true ]; then + python3 server/manage.py runserver "${DJANGO_PORT}" --settings="$DJANGO_SETTINGS_MODULE" > /dev/null & +else + python3 server/manage.py runserver "${DJANGO_PORT}" --settings="$DJANGO_SETTINGS_MODULE" +fi diff --git a/prepare_server_cypress.sh b/prepare_server_cypress.sh index 8ef42ba9..36789573 100755 --- a/prepare_server_cypress.sh +++ b/prepare_server_cypress.sh @@ -1,91 +1,6 @@ -#!/bin/bash +export POSTGRES_DB=vbv_lernwelt_cypress +export DJANGO_PORT=8001 +export DJANGO_SETTINGS_MODULE=config.settings.test_cypress +export IT_APP_ENVIRONMENT=development -if [ -z "$CI" ]; -then - # kill all subprocess on exit - trap "exit" INT TERM ERR - trap "kill 0" EXIT -else echo "CI is set to $CI"; -fi - -# script should fail when any process returns non zero code -set -ev - -# handle arguments -SKIP_SETUP=false -START_BACKGROUND=false -PROXY_VUE=false - -for i in "$@" -do -case $i in - --start-background) - START_BACKGROUND=true - shift # past argument - ;; - --skip-setup) - SKIP_SETUP=true - shift # past argument with no value - ;; - --proxy-vue) - PROXY_VUE=true - shift # past argument with no value - ;; - *) - # unknown option - ;; -esac -done - -echo "SKIP_SETUP = ${SKIP_SETUP}" - -DJANGO_SETTINGS_MODULE=config.settings.test_cypress -CYPRESS_DB=vbv_lernwelt_cypress - -if [ "$SKIP_SETUP" = false ]; then - if [ -z "$PG_PORT" ]; then # if the port is set in the env, use iterg - DB_PORT=""; - else - DB_PORT="-p $PG_PORT"; - fi - if [ -z "$PG_USER" ]; then # if the user is set in the env, use it - DB_USER=""; - else - DB_USER="-U $PG_USER"; - fi - echo "psql -h localhost $DB_PORT $DB_USER -c 'drop database if exists $CYPRESS_DB;'" - # create database - psql -h localhost $DB_PORT $DB_USER -c "drop database if exists $CYPRESS_DB;" - psql -h localhost $DB_PORT $DB_USER -c "create database $CYPRESS_DB;" - - # reset data - # python3 src/manage.py randomdata --settings="$DJANGO_SETTINGS_MODULE" - python3 server/manage.py createcachetable --settings="$DJANGO_SETTINGS_MODULE" - python3 server/manage.py migrate --settings="$DJANGO_SETTINGS_MODULE" - - # make django translations - (cd server && python3 manage.py compilemessages --settings="$DJANGO_SETTINGS_MODULE") - - -else - echo "else" -# python3 src/manage.py recreate_customer_data_for_integration_tests --settings="$DJANGO_SETTINGS_MODULE" -fi - -if [ "$PROXY_VUE" = true ]; then - export DJANGO_VUE_LANDINGPAGE_PROXY=http://localhost:8080/ -fi - -# install cypress here to avoid problems with `npm install` on the iesc servers -#CYPRESS_INSTALLED=0 -##npx --no-install cypress --version || CYPRESS_INSTALLED=$? -#if [ $CYPRESS_INSTALLED -ne 0 ]; then -# echo "install cypress" -## npm install cypress@5.6.0 @testing-library/cypress@7.0.2 --no-save -#fi - -if [ "$START_BACKGROUND" = true ]; then - python3 server/manage.py runserver 8001 --settings="$DJANGO_SETTINGS_MODULE" > /dev/null & -else - python3 server/manage.py runserver 8001 --settings="$DJANGO_SETTINGS_MODULE" -fi +./prepare_server.sh "$@" diff --git a/server/config/settings/base.py b/server/config/settings/base.py index 9894b2a7..ba700be2 100644 --- a/server/config/settings/base.py +++ b/server/config/settings/base.py @@ -10,21 +10,17 @@ from environs import Env from vbv_lernwelt.core.utils import structlog_add_app_info SERVER_ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent -# vbv_lernwelt/ APPS_DIR = SERVER_ROOT_DIR / "vbv_lernwelt" env = Env() -READ_DOT_ENV_FILE = env.bool("VBV_DJANGO_READ_DOT_ENV_FILE", default=False) -if READ_DOT_ENV_FILE: - # OS environment variables take precedence over variables from .env - env.read_env(str(SERVER_ROOT_DIR / "example.env")) - -DJANGO_DEV_MODE = env("VBV_DJANGO_DEV_MODE", default="development") +# set to "development" for local development +APP_ENVIRONMENT = env("IT_APP_ENVIRONMENT") # GENERAL # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#debug -DEBUG = env.bool("VBV_DJANGO_DEBUG", False) +DEBUG = env.bool("IT_DJANGO_DEBUG", True if APP_ENVIRONMENT == "development" else False) + # Local time zone. Choices are # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # though not all of them may be available with every OS. @@ -48,8 +44,8 @@ LOCALE_PATHS = [str(SERVER_ROOT_DIR / "locale")] # https://docs.djangoproject.com/en/dev/ref/settings/#databases DATABASES = { "default": env.dj_db_url( - "VBV_DATABASE_URL", - default="postgres://vbv_lernwelt@localhost:5432/vbv_lernwelt", + "DATABASE_URL", + default="postgres://postgres@localhost:5432/vbv_lernwelt", ) } DATABASES["default"]["ATOMIC_REQUESTS"] = True # noqa F405 @@ -308,11 +304,14 @@ MANAGERS = ADMINS # https://docs.djangoproject.com/en/dev/ref/settings/#logging # See https://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. -VBV_DJANGO_LOGGING_CONF = env( - "VBV_DJANGO_LOGGING_CONF", default="VBV_DJANGO_LOGGING_CONF_JSON_FILE" -) -if VBV_DJANGO_LOGGING_CONF == "VBV_DJANGO_LOGGING_CONF_CONSOLE_COLOR": +logging_conf_default = "IT_DJANGO_LOGGING_CONF_JSON_FILE" +if DEBUG: + logging_conf_default = "IT_DJANGO_LOGGING_CONF_CONSOLE_COLOR" + +IT_DJANGO_LOGGING_CONF = env("IT_DJANGO_LOGGING_CONF", default=logging_conf_default) + +if IT_DJANGO_LOGGING_CONF == "IT_DJANGO_LOGGING_CONF_CONSOLE_COLOR": timestamper = structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S") LOGGING = { "version": 1, @@ -476,12 +475,12 @@ SPECTACULAR_SETTINGS = { SECRET_KEY = env( - "VBV_DJANGO_SECRET_KEY", + "IT_DJANGO_SECRET_KEY", default="J9FiYN31FuY7lHrmx9Mpai3GGpTVCxakEclOfCLretDe7bTf2DtTsgazJ0aIMtbq", ) # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts ALLOWED_HOSTS = env.list( - "VBV_DJANGO_ALLOWED_HOSTS", default=["localhost", "0.0.0.0", "127.0.0.1"] + "IT_DJANGO_ALLOWED_HOSTS", default=["localhost", "0.0.0.0", "127.0.0.1"] ) @@ -489,21 +488,21 @@ ALLOWED_HOSTS = env.list( CACHES = { "default": { "BACKEND": env( - "VBV_DJANGO_CACHE_BACKEND", + "IT_DJANGO_CACHE_BACKEND", default="django.core.cache.backends.db.DatabaseCache", ), - "LOCATION": env("VBV_DJANGO_CACHE_LOCATION", default="django_cache_table"), + "LOCATION": env("IT_DJANGO_CACHE_LOCATION", default="django_cache_table"), } } -if "django_redis.cache.RedisCache" in env("VBV_DJANGO_CACHE_BACKEND", default=""): +if "django_redis.cache.RedisCache" in env("IT_DJANGO_CACHE_BACKEND", default=""): CACHES = { "default": { "BACKEND": env( - "VBV_DJANGO_CACHE_BACKEND", + "IT_DJANGO_CACHE_BACKEND", default="django.core.cache.backends.db.DatabaseCache", ), - "LOCATION": env("VBV_DJANGO_CACHE_LOCATION", default="django_cache_table"), + "LOCATION": env("IT_DJANGO_CACHE_LOCATION", default="django_cache_table"), "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", # Mimicing memcache behavior. @@ -530,7 +529,7 @@ OAUTH = { } } -if DJANGO_DEV_MODE == "development": +if APP_ENVIRONMENT == "development": # http://whitenoise.evans.io/en/latest/django.html#using-whitenoise-in-development INSTALLED_APPS = ["whitenoise.runserver_nostatic"] + INSTALLED_APPS # noqa F405 @@ -547,7 +546,7 @@ if DJANGO_DEV_MODE == "development": # } # https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips INTERNAL_IPS = ["127.0.0.1", "10.0.2.2"] - if env.bool("VBV_DJANGO_LOCAL_DOCKER", False): + if env.bool("IT_DJANGO_LOCAL_DOCKER", False): import socket hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) @@ -564,13 +563,13 @@ if DJANGO_DEV_MODE == "development": # https://django-extensions.readthedocs.io/en/latest/installation_instructions.html#configuration INSTALLED_APPS += ["django_extensions"] # noqa F405 -if DJANGO_DEV_MODE in ["production", "caprover"]: +if APP_ENVIRONMENT in ["production", "caprover"]: # SECURITY # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect - SECURE_SSL_REDIRECT = env.bool("VBV_DJANGO_SECURE_SSL_REDIRECT", default=True) + SECURE_SSL_REDIRECT = env.bool("IT_DJANGO_SECURE_SSL_REDIRECT", default=True) # https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure SESSION_COOKIE_SECURE = True # https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure @@ -604,7 +603,7 @@ if DJANGO_DEV_MODE in ["production", "caprover"]: default="VBV Lernwelt ", ) # https://docs.djangoproject.com/en/dev/ref/settings/#server-email - SERVER_EMAIL = env("VBV_DJANGO_SERVER_EMAIL", default=DEFAULT_FROM_EMAIL) + SERVER_EMAIL = env("IT_DJANGO_SERVER_EMAIL", default=DEFAULT_FROM_EMAIL) # https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix EMAIL_SUBJECT_PREFIX = env( "DJANGO_EMAIL_SUBJECT_PREFIX", @@ -614,7 +613,7 @@ if DJANGO_DEV_MODE in ["production", "caprover"]: # ADMIN # ------------------------------------------------------------------------------ # Django Admin URL regex. - ADMIN_URL = env("VBV_DJANGO_ADMIN_URL") + ADMIN_URL = env("IT_DJANGO_ADMIN_URL", 'admin/') # Anymail # ------------------------------------------------------------------------------ @@ -633,7 +632,7 @@ if DJANGO_DEV_MODE in ["production", "caprover"]: from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.integrations.redis import RedisIntegration - SENTRY_DSN = env("VBV_SENTRY_DSN") + SENTRY_DSN = env("IT_SENTRY_DSN") SENTRY_LOG_LEVEL = env.int("DJANGO_SENTRY_LOG_LEVEL", logging.INFO) sentry_logging = LoggingIntegration( diff --git a/server/config/settings/test.py b/server/config/settings/test.py index 90c4b66c..39548444 100644 --- a/server/config/settings/test.py +++ b/server/config/settings/test.py @@ -9,7 +9,7 @@ from .base import env # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#secret-key SECRET_KEY = env( - "VBV_DJANGO_SECRET_KEY", + "IT_DJANGO_SECRET_KEY", default="1NpUCSvAKLpDZL9e3tqDaUe8Kk2xAuF1tXosFjBanc4lFCgNcfBp02MD3UjB72ZS", ) # https://docs.djangoproject.com/en/dev/ref/settings/#test-runner diff --git a/server/config/settings/test_cypress.py b/server/config/settings/test_cypress.py index dd94cb1f..e3c625b1 100644 --- a/server/config/settings/test_cypress.py +++ b/server/config/settings/test_cypress.py @@ -9,7 +9,7 @@ from .base import env # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#secret-key SECRET_KEY = env( - "VBV_DJANGO_SECRET_KEY", + "IT_DJANGO_SECRET_KEY", default="1LhwZ0DvP4cGBgbBdCfaBQV7eiaOc4jWKdzO9WEXLFT7AaqBN6jqd0uyaZeAZ19K", ) diff --git a/server/example.env b/server/example.env deleted file mode 100644 index 7e4c6848..00000000 --- a/server/example.env +++ /dev/null @@ -1,11 +0,0 @@ -export VBV_DATABASE_URL='postgres://vbv_lernwelt@localhost:5432/vbv_lernwelt' -#export VBV_DJANGO_LOGGING_CONF=VBV_DJANGO_LOGGING_CONF_CONSOLE_COLOR -export VBV_DJANGO_DEBUG=True - -# oauth is for the moment not used -export OAUTH_CLIENT_ID=iterativ -export OAUTH_CLIENT_SECRET=abced-1234 -export OAUTH_ACCESS_TOKEN_URL=https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/token -export OAUTH_AUTHORIZE_URL=https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/auth -export OAUTH_API_BASE_URL=https://sso.test.b.lernetz.host/auth/realms/vbv/protocol/openid-connect/ -export OAUTH_LOCAL_REDIRECT_URI=http://localhost:8000/api/oauth/callback/ diff --git a/server/vbv_lernwelt/core/create_default_users.py b/server/vbv_lernwelt/core/create_default_users.py index 82960734..5cd12ce7 100644 --- a/server/vbv_lernwelt/core/create_default_users.py +++ b/server/vbv_lernwelt/core/create_default_users.py @@ -9,13 +9,11 @@ def create_default_users(user_model=User, group_model=Group): content_creator_grop, created = group_model.objects.get_or_create(name='content_creator_grop') student_group, created = group_model.objects.get_or_create(name='student_group') - admin_user, created = _get_or_create_user(user_model=user_model, - username='admin', - password='admin') - admin_user.is_superuser=True + admin_user, created = _get_or_create_user(user_model=user_model, username='admin', password='admin') + admin_user.is_superuser = True admin_user.groups.add(admin_group) - admin_user.save() + student_user, created = _get_or_create_user(user_model=user_model, username='student', password='student') student_user.groups.add(student_group) student_user.save() diff --git a/server/vbv_lernwelt/core/utils.py b/server/vbv_lernwelt/core/utils.py index af7f5938..637707c7 100644 --- a/server/vbv_lernwelt/core/utils.py +++ b/server/vbv_lernwelt/core/utils.py @@ -10,8 +10,8 @@ def structlog_add_app_info( logger: logging.Logger, method_name: str, event_dict: EventDict ) -> EventDict: event_dict["django_app"] = "vbv_lernwelt" - event_dict["django_dev_mode"] = settings.DJANGO_DEV_MODE - event_dict["django_app_dev_mode"] = f"vbv_lernwelt_{settings.DJANGO_DEV_MODE}" + event_dict["APP_ENVIRONMENT"] = settings.APP_ENVIRONMENT + event_dict["django_app_dev_mode"] = f"vbv_lernwelt_{settings.APP_ENVIRONMENT}" return event_dict diff --git a/server/vbv_lernwelt/core/views.py b/server/vbv_lernwelt/core/views.py index 5fe68853..50597690 100644 --- a/server/vbv_lernwelt/core/views.py +++ b/server/vbv_lernwelt/core/views.py @@ -19,8 +19,9 @@ def vue_home(request): content_type = headers.get('content-type', 'text/html') return HttpResponse(res.text, content_type=content_type) except Exception as e: - print(f'Can not connect to vue dev server at {settings.IT_SERVE_VUE_URL}:', e) - return + return HttpResponse( + f'Can not connect to vue dev server at {settings.IT_SERVE_VUE_URL}: {e}' + ) # render index.html from `npm run build` return render(request, 'index.html', {}) diff --git a/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py b/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py index 5e8a7527..17513b03 100644 --- a/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py +++ b/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py @@ -159,9 +159,6 @@ von Neukunden zu benützen circle_7 = CircleFactory.create(title="Prüfungsvorbereitung", parent=lp, topic=tp) - - - def delete_default_learning_path(): LearningUnit.objects.all().delete() LearningSequence.objects.all().delete()