diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index afb15c9..e04e03d 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -27,8 +27,13 @@ jobs: - name: Set Environment Variables env: SECRET_KEY: ${{ secrets.SECRET_KEY }} - run: echo "SECRET_KEY=${SECRET_KEY}" > /home/runner/work/Albercan-Backend/Albercan-Backend/envs/.env + STATIC_ROOT: ${{ secrets.STATIC_ROOT }} + run: | + echo "SECRET_KEY=${SECRET_KEY}" > ./envs/.env + echo "STATIC_ROOT=${STATIC_ROOT}" >> ./envs/.env - name: Install Dependencies run: poetry install + - name: Collect Static Files + run: poetry run python manage.py collectstatic --no-input - name: Run Tests - run: poetry run python manage.py test \ No newline at end of file + run: poetry run python manage.py test diff --git a/README.md b/README.md index 64775ca..1a33599 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,7 @@ poetry install 2. Ejecuta el servidor de desarrollo de Django: ```bash poetry run python manage.py runserver -``` \ No newline at end of file +``` + +## Errors +En ocasiones los tests no corren porque el STORAGES.staticfiles apunta a whitenoise, pero si lo usamos por el que usa django por defecto ```django.contrib.staticfiles.storage.StaticFilesStorage``` anda todo bien. \ No newline at end of file diff --git a/albercan_backend/settings.py b/albercan_backend/settings.py index 6e2ad27..6308e5b 100644 --- a/albercan_backend/settings.py +++ b/albercan_backend/settings.py @@ -23,12 +23,12 @@ # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = env('SECRET_KEY') +SECRET_KEY = env("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = env.BOOL('DEBUG', False) +DEBUG = env.BOOL("DEBUG", False) -ALLOWED_HOSTS = env.LIST('ALLOWED_HOSTS', []) +ALLOWED_HOSTS = env.LIST("ALLOWED_HOSTS", []) # Application definition @@ -41,11 +41,13 @@ "django.contrib.staticfiles", "people", "pet", - "structure" + "structure", + "authentication", ] MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", + "whitenoise.middleware.WhiteNoiseMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", @@ -59,7 +61,7 @@ TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [BASE_DIR / PROJECT_NAME / 'templates'], + "DIRS": [BASE_DIR / PROJECT_NAME / "templates"], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -135,11 +137,21 @@ STATIC_ROOT = env("STATIC_ROOT") # This is when I run the app in prod STATIC_ROOT = f"{(BASE_DIR / STATIC_ROOT).absolute()}" if STATIC_ROOT else None -STATICFILES_DIRS = [ - BASE_DIR / PROJECT_NAME / "static" -] +STATICFILES_DIRS = [BASE_DIR / PROJECT_NAME / "static"] +STORAGES = { + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, +} # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +LOGIN_REDIRECT_URL = "/index" +LOGOUT_REDIRECT_URL = "/auth/login" +CSRF_COOKIE_SECURE = True diff --git a/albercan_backend/static/css/navbar.css b/albercan_backend/static/css/navbar.css index 726198b..7e890b1 100644 --- a/albercan_backend/static/css/navbar.css +++ b/albercan_backend/static/css/navbar.css @@ -71,4 +71,13 @@ header .navbar .dropdown-menu .dropdown-item.active:hover { header .navbar .dropdown-menu .dropdown-item.active { background: #bc5148; color: #fff; +} + +#logout-form { + display: inline; +} +#logout-form button { + background: none; + border: none; + cursor: pointer; } \ No newline at end of file diff --git a/albercan_backend/templates/base.html b/albercan_backend/templates/base.html index 4fdfd01..d68a3c2 100644 --- a/albercan_backend/templates/base.html +++ b/albercan_backend/templates/base.html @@ -20,6 +20,7 @@ + {% block styles %}{% endblock %} diff --git a/albercan_backend/templates/navbar.html b/albercan_backend/templates/navbar.html index c15d4cd..7414d17 100644 --- a/albercan_backend/templates/navbar.html +++ b/albercan_backend/templates/navbar.html @@ -1,7 +1,7 @@