From 83a6745c742e4c09548a87c2328c33dba49ed191 Mon Sep 17 00:00:00 2001 From: Stuart Maxwell Date: Wed, 8 May 2024 20:35:02 +1200 Subject: [PATCH] Initial commit --- .editorconfig | 14 ++ .github/workflows/docker-image.yml | 35 +++++ .gitignore | 98 +++++++++++++ .pre-commit-config.yaml | 46 ++++++ .prettierignore | 3 + .vscode/settings.json | 5 + Dockerfile | 29 ++++ README.md | 58 ++++++++ config/__init__.py | 1 + config/asgi.py | 15 ++ config/settings.py | 212 +++++++++++++++++++++++++++ config/settings_testing.py | 11 ++ config/urls.py | 17 +++ config/wsgi.py | 15 ++ docker-compose.yml | 14 ++ entrypoint.sh | 17 +++ env.template | 18 +++ manage.py | 22 +++ pyproject.toml | 28 ++++ requirements.in | 9 ++ requirements.txt | 37 +++++ static/css/styles.css | 1 + static/css/styles.min.css | 0 templates/base.html | 19 +++ templates/snippets/footer.html | 0 templates/snippets/header.html | 18 +++ templates/svg/gear.svg | 4 + website/__init__.py | 1 + website/apps.py | 10 ++ website/migrations/__init__.py | 0 website/templates/website/index.html | 8 + website/test_views.py | 12 ++ website/urls.py | 11 ++ website/views.py | 13 ++ 34 files changed, 801 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/docker-image.yml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 .prettierignore create mode 100644 .vscode/settings.json create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 config/__init__.py create mode 100644 config/asgi.py create mode 100644 config/settings.py create mode 100644 config/settings_testing.py create mode 100644 config/urls.py create mode 100644 config/wsgi.py create mode 100644 docker-compose.yml create mode 100755 entrypoint.sh create mode 100644 env.template create mode 100755 manage.py create mode 100644 pyproject.toml create mode 100644 requirements.in create mode 100644 requirements.txt create mode 100644 static/css/styles.css create mode 100644 static/css/styles.min.css create mode 100644 templates/base.html create mode 100644 templates/snippets/footer.html create mode 100644 templates/snippets/header.html create mode 100644 templates/svg/gear.svg create mode 100644 website/__init__.py create mode 100644 website/apps.py create mode 100644 website/migrations/__init__.py create mode 100644 website/templates/website/index.html create mode 100644 website/test_views.py create mode 100644 website/urls.py create mode 100644 website/views.py diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3d1e45d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# http://editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.py] +indent_size = 4 diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..f180585 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,35 @@ +name: Build and Deploy Docker Image + +on: + push: + branches: [main] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.TOKEN_GITHUB }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ github.repository }}:latest + + - name: Send POST request to webhook + run: | + curl --fail --retry 3 --max-time 10 -X POST "${{ secrets.DOCKER_WEBHOOK }}" || exit 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7faf52d --- /dev/null +++ b/.gitignore @@ -0,0 +1,98 @@ +# Django # +*.log +*.pot +*.pyc +__pycache__ +*.sqlite3 +media +staticfiles + +# Backup files # +*.bak + +# Python # +*.py[cod] +*$py.class + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# sftp configuration file +sftp-config.json + +# Package control specific files Package +Control.last-run +Control.ca-list +Control.ca-bundle +Control.system-ca-bundle +GitHub.sublime-settings + +# Visual Studio Code # +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history + +# Macos yuck +.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7a3788e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,46 @@ +default_language_version: + python: python3.11 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-toml + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - repo: https://github.com/adamchainz/django-upgrade + rev: "1.16.0" # replace with latest tag on GitHub + hooks: + - id: django-upgrade + args: [--target-version, "4.2"] # Replace with Django version + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.4.3 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - repo: https://github.com/thibaudcolas/curlylint + rev: v0.13.1 + hooks: + - id: curlylint + exclude: 'templates/snippets/timetable_search\.html' + - repo: https://github.com/rtts/djhtml + rev: 3.0.6 + hooks: + - id: djhtml + args: + - --tabwidth=2 + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 + hooks: + - id: prettier + types_or: + - css + - xml + additional_dependencies: + - prettier@2.5.1 + - "@prettier/plugin-xml@1.2.0" diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..8c218c6 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +*.min.css +*.min.js +*.svg diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6d8c9f6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "python.testing.pytestArgs": ["."], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a644247 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM python:3.12-slim-bookworm + +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y build-essential curl libpq-dev --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \ + && apt-get clean + +# Keeps Python from generating .pyc files in the container +ENV PYTHONDONTWRITEBYTECODE 1 + +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED 1 + +# Install pip requirements +RUN python -m pip install --upgrade pip +COPY requirements.txt /app/requirements.txt +RUN python -m pip install -r /app/requirements.txt + +WORKDIR /app +COPY . /app +RUN mkdir /app/staticfiles + +# Switching to a non-root user +RUN useradd appuser && chown -R appuser /app +USER appuser + +# Expose port 8000 for Gunicorn +EXPOSE 8000 diff --git a/README.md b/README.md new file mode 100644 index 0000000..bfbb0d3 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# My Django X + +Inspired by Will Vincent's [DjangoX project](https://github.com/wsvincent/djangox). + +## Features + +- Django 5.0.latest & Python 3.12.latest +- Basic first app called `website` +- Basic template with Bootstrap +- Dockerfile and docker-compose file +- Github Actions workflow to build the Docker file +- Lots of other config inspired by [Adam Johnson's Boost Your Django DX book](https://adamchainz.gumroad.com/l/byddx) + +## Installation + +1. Git clone this repository: `git clone ...` +2. Change directory into the repo: `cd mydjangox` +3. Create a virtual environment: e.g. `uv venv` +4. Activate the virtual environment: `source .venv/bin/activate` +5. Compile the requirements: e.g. `uv pip compile --upgrade requirements.in -o requirements.txt` +6. Install requirements: e.g. `uv pip sync requirements.txt` +7. Run the Django migrations: `python manage.py migrate` +8. Create a superuser: `python manage.py createsuperuser` +9. Start the server: `python manage.py runserver` +10. Navigate to: + +## More Configuration + +- Rename `env.template` to `.env` and configure the following settings: + + | Env Name | Env Value | + | ------------------- | -------------------------------------------------------------------------------------------------- | + | SECRET_KEY | The Django secret key to add to the `settings.py` file. | + | DEBUG | Ensure this is set to `False` in production. | + | ALLOWED_HOSTS | List of allowed hosts, e.g. `example.com,www.example.com`. | + | EMAIL_HOST | Name or IP address of the SMTP server. | + | EMAIL_PORT | The port of the SMTP server. | + | EMAIL_HOST_USER | The username to authenticate with the SMTP server. | + | EMAIL_HOST_PASSWORD | The password for the SMTP server username. | + | EMAIL_USE_TLS | Either `True` or `False` to use TLS. | + | DEFAULT_FROM_EMAIL | The email address to send emails from . | + | DB_ENGINE | The database engine to use. | + | DB_NAME | The database name to connect to. If using SQLite, this will be the filename without the extension. | + | DB_HOST | Name or IP address of the database server. | + | DB_PORT | The port of the database server. | + | DB_USER | The username to authenticate with the database server. | + | DB_PASSWORD | The password for the database server username. | + | WHITENOISE_STATIC | Boolean value that turns on Whitenoise for serving static content. | + | ADMIN_URL | The path to the Admin site so it can be hidden from easily being guessed. | + +## Github Action + +- Configure the following repository secrets: + + - `TOKEN_GITHUB`: This should be a personal access token with read and write permissions for the repo. + - `DOCKER_WEBHOOK`: This is a webhook that will be called after the image has been created. Useful for kicking off an automation to restart and re-pull the image. If you don't want to use this, delete the `Send POST request to webhook` action from the workflow in the `docker-image.yml` file. + +- Push to Github `main` branch to kick off the workflow. diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..28c6e45 --- /dev/null +++ b/config/__init__.py @@ -0,0 +1 @@ +"""config package.""" diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 0000000..805423d --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,15 @@ +"""ASGI config for config project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +application = get_asgi_application() diff --git a/config/settings.py b/config/settings.py new file mode 100644 index 0000000..72aa22d --- /dev/null +++ b/config/settings.py @@ -0,0 +1,212 @@ +"""Django settings for config project.""" + +from pathlib import Path + +import environ +from django.contrib.messages import constants as messages + +BASE_DIR = Path(__file__).resolve().parent.parent + +env = environ.Env( + # set casting, default value + SECRET_KEY=(str, "this_is_just_a_temporary_secret_key"), + DEBUG=(bool, True), + ALLOWED_HOSTS=(list, ["127.0.0.1"]), + EMAIL_HOST=(str, ""), + EMAIL_PORT=(str, ""), + EMAIL_HOST_USER=(str, ""), + EMAIL_HOST_PASSWORD=(str, ""), + EMAIL_USE_TLS=(bool, True), + DEFAULT_FROM_EMAIL=(str, ""), + DB_ENGINE=(str, "django.db.backends.sqlite3"), + DB_NAME=(str, "db"), + DB_USER=(str, ""), + DB_PASSWORD=(str, ""), + DB_HOST=(str, ""), + DB_PORT=(str, ""), + WHITENOISE_STATIC=(bool, True), + ADMIN_URL=(str, "admin"), +) + +environ.Env.read_env(Path(BASE_DIR / ".env")) + +SECRET_KEY = env("SECRET_KEY") +DEBUG = env("DEBUG") +ALLOWED_HOSTS = env("ALLOWED_HOSTS") +ADMIN_URL = env("ADMIN_URL") +CSRF_TRUSTED_ORIGINS = [f"https://{domain}" for domain in ALLOWED_HOSTS] + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "website", +] + +if DEBUG: + INSTALLED_APPS += [ + "debug_toolbar", + ] + +# The middleware section is broken up to allow various middleware to be +# added in different environments and in different orders. +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", +] + +# Whitenoise +WHITENOISE_STATIC = env("WHITENOISE_STATIC") +if WHITENOISE_STATIC: + MIDDLEWARE += [ + "whitenoise.middleware.WhiteNoiseMiddleware", + ] + +# django-debug-toolbar +if DEBUG: + MIDDLEWARE += [ + "debug_toolbar.middleware.DebugToolbarMiddleware", + ] + +# Common middleware +MIDDLEWARE += [ + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "config.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [BASE_DIR / "templates"], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "config.wsgi.application" + +# Database +if "sqlite" in env("DB_ENGINE"): + DB_NAME = BASE_DIR / f"{env('DB_NAME')}.sqlite3" +else: + DB_NAME = env("DB_NAME") + +DATABASES = { + "default": { + "ENGINE": env("DB_ENGINE"), + "NAME": DB_NAME, + "USER": env("DB_USER"), + "PASSWORD": env("DB_PASSWORD"), + "HOST": env("DB_HOST"), + "PORT": env("DB_PORT"), + }, +} + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": ( + "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" + ), + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + +# Internationalization +# https://docs.djangoproject.com/en/5.0/topics/i18n/ +LANGUAGE_CODE = "en-nz" +TIME_ZONE = "Pacific/Auckland" +USE_I18N = True +USE_TZ = True + +# The path that the static files will be served from +STATIC_URL = "/static/" +# The directory that collectstatic will collect static files to +STATIC_ROOT = BASE_DIR / "staticfiles" +# The directory that static files will be collected from +STATICFILES_DIRS = [ + BASE_DIR / "static", +] + +# Email configuration +EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" +EMAIL_HOST = env("EMAIL_HOST") +EMAIL_PORT = env("EMAIL_PORT") +EMAIL_HOST_USER = env("EMAIL_HOST_USER") +EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD") +EMAIL_USE_TLS = env("EMAIL_USE_TLS") +DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL") + +# django-debug-toolbar +INTERNAL_IPS = ["127.0.0.1"] + +# The following constants let us use Bootstrap alerts with messages +MESSAGE_TAGS = { + messages.DEBUG: "alert-info", + messages.INFO: "alert-info", + messages.SUCCESS: "alert-success", + messages.WARNING: "alert-warning", + messages.ERROR: "alert-danger", +} + +# Media uploads for untrusted files +MEDIA_ROOT = "media" +MEDIA_URL = "/media/" + +# Logging configuration +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "filters": { + "require_debug_true": { + "()": "django.utils.log.RequireDebugTrue", + }, + }, + "formatters": { + "rich": {"datefmt": "[%X]"}, + }, + "handlers": { + "console": { + "level": "DEBUG", + "class": "rich.logging.RichHandler", + "formatter": "rich", + "filters": ["require_debug_true"], + "rich_tracebacks": True, + "tracebacks_show_locals": True, + }, + }, + "loggers": { + "django": { + "handlers": [], + "level": "INFO", + }, + }, + "root": { + "handlers": ["console"], + "level": "DEBUG", + }, +} diff --git a/config/settings_testing.py b/config/settings_testing.py new file mode 100644 index 0000000..79603f1 --- /dev/null +++ b/config/settings_testing.py @@ -0,0 +1,11 @@ +"""Settings for running tests.""" + +from .settings import * # noqa: F403, F401, RUF100 + +# Use an in-memory database for testing +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": ":memory:", + }, +} diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..5bc8790 --- /dev/null +++ b/config/urls.py @@ -0,0 +1,17 @@ +"""URL configuration for config project.""" + +from django.conf import settings +from django.contrib import admin +from django.urls import include, path + +urlpatterns = [] + +if settings.DEBUG: + urlpatterns += [ + path("__debug__/", include("debug_toolbar.urls")), + ] + +urlpatterns += [ + path(f"{settings.ADMIN_URL}/", admin.site.urls), + path("", include("website.urls")), +] diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 0000000..5c86085 --- /dev/null +++ b/config/wsgi.py @@ -0,0 +1,15 @@ +"""WSGI config for config project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +application = get_wsgi_application() diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2392f1e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.8" + +services: + app: + image: ghcr.io/stuartmaxwell/stuartmnz:latest + entrypoint: /app/entrypoint.sh + restart: always + command: gunicorn --worker-tmp-dir /dev/shm --workers=2 --worker-class=gthread --bind 0.0.0.0:8000 config.wsgi + user: "1000" + volumes: + - static_volume:/app + +volumes: + static_volume: diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..e42b913 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +if [ "$DB" = "postgresql" ] +then + echo "Waiting for postgresql..." + + while ! nc -z $DB_HOST $DB_PORT; do + sleep 0.1 + done + + echo "PostgreSQL started" +fi + +python manage.py migrate --no-input +python manage.py collectstatic --no-input + +exec "$@" diff --git a/env.template b/env.template new file mode 100644 index 0000000..80cf347 --- /dev/null +++ b/env.template @@ -0,0 +1,18 @@ +# Rename this to `.env` and remove this line. +SECRET_KEY= +DEBUG= +ALLOWED_HOSTS= +EMAIL_HOST= +EMAIL_PORT= +EMAIL_HOST_USER= +EMAIL_HOST_PASSWORD= +EMAIL_USE_TLS= +DEFAULT_FROM_EMAIL= +DB_ENGINE= +DB_NAME= +DB_USER= +DB_PASSWORD= +DB_HOST= +DB_PORT= +WHITENOISE_STATIC +ADMIN_URL= diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..8e7ac79 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2b73889 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,28 @@ +[tool.pytest.ini_options] +DJANGO_SETTINGS_MODULE = "config.settings_testing" +python_files = "tests.py test_*.py *_tests.py" + +[tool.curlylint.rules] +image_alt = true + +[tool.ruff] +select = ["ALL"] +ignore = [ + "G004", # Logging statement uses f-string + "D203", # 1 blank line required before class docstring + "D213", # multi-line-summary-second-line + "TD003", # Missing issue link on the line following this TODO + "FIX002", # Line contains TODO, consider resolving the issue + "TD002", # Missing author in TODO + "S308", # suspicious-mark-safe-usage +] + +target-version = "py312" + +[tool.ruff.per-file-ignores] +"test*" = ["ALL"] +"**/migrations/*" = ["ALL"] +"manage.py" = ["ALL"] + +[tool.ruff.lint.pydocstyle] +convention = "google" # Accepts: "google", "numpy", or "pep257". diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..be92da8 --- /dev/null +++ b/requirements.in @@ -0,0 +1,9 @@ +django>=5.0,<5.1 +django-environ +django-debug-toolbar +whitenoise +gunicorn +psycopg[binary] +pytest +pytest-django +rich diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7ed9b78 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,37 @@ +# This file was autogenerated by uv via the following command: +# uv pip compile requirements.in -o requirements.txt +asgiref==3.8.1 + # via django +django==5.0.6 + # via django-debug-toolbar +django-debug-toolbar==4.3.0 +django-environ==0.11.2 +gunicorn==22.0.0 +iniconfig==2.0.0 + # via pytest +markdown-it-py==3.0.0 + # via rich +mdurl==0.1.2 + # via markdown-it-py +packaging==24.0 + # via + # gunicorn + # pytest +pluggy==1.5.0 + # via pytest +psycopg==3.1.18 +psycopg-binary==3.1.18 + # via psycopg +pygments==2.18.0 + # via rich +pytest==8.2.0 + # via pytest-django +pytest-django==4.8.0 +rich==13.7.1 +sqlparse==0.5.0 + # via + # django + # django-debug-toolbar +typing-extensions==4.11.0 + # via psycopg +whitenoise==6.6.0 diff --git a/static/css/styles.css b/static/css/styles.css new file mode 100644 index 0000000..7f10a59 --- /dev/null +++ b/static/css/styles.css @@ -0,0 +1 @@ +/* Custom sytles for stuartm.nz */ diff --git a/static/css/styles.min.css b/static/css/styles.min.css new file mode 100644 index 0000000..e69de29 diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..a4ef5da --- /dev/null +++ b/templates/base.html @@ -0,0 +1,19 @@ +{% load static %} + + + + + + + {% block title %}{% endblock title %} + + + + + {% include "snippets/header.html" %} +
+ {% block content %}{% endblock content %} +
+ {% include "snippets/footer.html" %} + + diff --git a/templates/snippets/footer.html b/templates/snippets/footer.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/snippets/header.html b/templates/snippets/header.html new file mode 100644 index 0000000..78bdef0 --- /dev/null +++ b/templates/snippets/header.html @@ -0,0 +1,18 @@ + diff --git a/templates/svg/gear.svg b/templates/svg/gear.svg new file mode 100644 index 0000000..fa96c15 --- /dev/null +++ b/templates/svg/gear.svg @@ -0,0 +1,4 @@ + + + + diff --git a/website/__init__.py b/website/__init__.py new file mode 100644 index 0000000..53f905a --- /dev/null +++ b/website/__init__.py @@ -0,0 +1 @@ +"""Website package init file.""" diff --git a/website/apps.py b/website/apps.py new file mode 100644 index 0000000..365bc13 --- /dev/null +++ b/website/apps.py @@ -0,0 +1,10 @@ +"""Apps configuration for website app.""" + +from django.apps import AppConfig + + +class WebsiteConfig(AppConfig): + """Website app configuration.""" + + default_auto_field = "django.db.models.BigAutoField" + name = "website" diff --git a/website/migrations/__init__.py b/website/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/website/templates/website/index.html b/website/templates/website/index.html new file mode 100644 index 0000000..79d4473 --- /dev/null +++ b/website/templates/website/index.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block title %}Website{% endblock title %} + +{% block content %} +

Welcome!

+

This is the homepage of the website.

+{% endblock content %} diff --git a/website/test_views.py b/website/test_views.py new file mode 100644 index 0000000..33880b0 --- /dev/null +++ b/website/test_views.py @@ -0,0 +1,12 @@ +import pytest +from django.urls import reverse + +from pytest_django.asserts import assertTemplateUsed + + +def test_index_view(client): + url = reverse("website:index") + response = client.get(url) + assert response.status_code == 200 + assert b"Welcome" in response.content + assertTemplateUsed(response, "website/index.html") diff --git a/website/urls.py b/website/urls.py new file mode 100644 index 0000000..d83051c --- /dev/null +++ b/website/urls.py @@ -0,0 +1,11 @@ +"""Website URLs file.""" + +from django.urls import path + +from website.views import index + +app_name = "website" + +urlpatterns = [ + path("", index, name="index"), +] diff --git a/website/views.py b/website/views.py new file mode 100644 index 0000000..e4aa15a --- /dev/null +++ b/website/views.py @@ -0,0 +1,13 @@ +"""Website views file.""" + +import logging + +from django.http import HttpRequest, HttpResponse +from django.shortcuts import render + +logger = logging.getLogger(__name__) + + +def index(request: HttpRequest) -> HttpResponse: + """View for the index page.""" + return render(request, "website/index.html")