diff --git a/lidiabrowser/lidiabrowser/.env.dist b/.env.dist similarity index 100% rename from lidiabrowser/lidiabrowser/.env.dist rename to .env.dist diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be51999..cdfc4f1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,5 +37,5 @@ jobs: ruff --output-format=github --target-version=py38 . - name: Test with pytest run: | - cp lidiabrowser/lidiabrowser/.env.dist lidiabrowser/lidiabrowser/.env + cp .env.dist .env pytest lidiabrowser diff --git a/.gitignore b/.gitignore index 54caad0..d01d47c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.sqlite3 __pycache__/ .python-version +htdocs/ diff --git a/README.md b/README.md index 9180f75..d277ebd 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Install the dependencies: pip install -r requirements.txt -Create a file `lidiabrowser/lidiabrowser/.env` with your Zotero library and authentication details: +Create a file `.env` in the repository root with your Zotero library and authentication details: ```sh ZOTERO_LIBRARY_ID=12345 @@ -29,5 +29,7 @@ To run on a local machine, use: cd lidiabrowser python manage.py migrate python manage.py runserver +python manage.py sync +python manage.py populate ``` diff --git a/lidiabrowser/lidiabrowser/settings.py b/lidiabrowser/lidiabrowser/settings.py index 398de33..7a9dd81 100644 --- a/lidiabrowser/lidiabrowser/settings.py +++ b/lidiabrowser/lidiabrowser/settings.py @@ -10,29 +10,37 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ """ +import os from pathlib import Path import environ root = environ.Path(__file__) -env = environ.Env() -environ.Env.read_env() +env = environ.Env( + # Set casting, default value + # Defaults are for local development; set server config in .env + SECRET_KEY=(str, 'BmM7FkllTHs_5Q0nsdalUDUlV0Q-B5Pl5uVxwRQSr_E'), + DEBUG=(bool, True), + ALLOWED_HOSTS=(list, []), + STATIC_ROOT=(str, '../htdocs') +) SITE_ROOT = root() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +environ.Env.read_env(os.path.join(BASE_DIR.parent, '.env')) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-m8_b*$)+y4!o3%-=$xf2kpiu6cqd16&0bekmw94^hfucpjzja&" +SECRET_KEY = env.str('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = env.bool('DEBUG') -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = env.list('ALLOWED_HOSTS') # Application definition @@ -143,6 +151,8 @@ STATIC_URL = "static/" +STATIC_ROOT = env.str('STATIC_ROOT') + # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field diff --git a/lidiabrowser/wsgi.py b/lidiabrowser/wsgi.py new file mode 100644 index 0000000..0b67412 --- /dev/null +++ b/lidiabrowser/wsgi.py @@ -0,0 +1,20 @@ +""" +RSLab Django WSGI config for the lidiabrowser application. + +It exposes the WSGI callable as a module-level variable named ``application``. + +Since this Django-only setup does not use our default Cookiecutter workflow, +this root-level wsgi file is included to facilitate our deployment script. +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lidiabrowser.settings") + +try: + application = get_wsgi_application() +except Exception as e: + # Ends up in Apache logs + print(e) diff --git a/requirements.txt b/requirements.txt index 8487d83..8bee7e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile requirements.in +# pip-compile # asgiref==3.7.2 # via django @@ -18,7 +18,7 @@ django-environ==0.11.2 # via -r requirements.in feedparser==6.0.10 # via pyzotero -idna==3.4 +idna==3.6 # via requests iso639-lang==2.2.1 # via -r requirements.in @@ -38,5 +38,7 @@ sgmllib3k==1.0.0 # via feedparser sqlparse==0.4.4 # via django +typing-extensions==4.8.0 + # via asgiref urllib3==2.1.0 # via requests