diff --git a/class-31/demo/things-api/.dockerignore b/class-31/demo/things-api/.dockerignore new file mode 100644 index 0000000..f32ebbe --- /dev/null +++ b/class-31/demo/things-api/.dockerignore @@ -0,0 +1,4 @@ +# .dockerignore +.venv +.git +.gitignore diff --git a/class-31/demo/things-api/Dockerfile b/class-31/demo/things-api/Dockerfile new file mode 100644 index 0000000..88e391b --- /dev/null +++ b/class-31/demo/things-api/Dockerfile @@ -0,0 +1,17 @@ +# Pull base image +FROM python:3.11.5-slim-bullseye + +# Set environment variables +ENV PIP_DISABLE_PIP_VERSION_CHECK 1 +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Set work directory +WORKDIR /code + +# Install dependencies +COPY ./requirements.txt . +RUN pip install -r requirements.txt + +# Copy project +COPY . . diff --git a/class-31/demo/things-api/db.sqlite3 b/class-31/demo/things-api/db.sqlite3 index 2b4ae20..7d45e32 100644 Binary files a/class-31/demo/things-api/db.sqlite3 and b/class-31/demo/things-api/db.sqlite3 differ diff --git a/class-31/demo/things-api/docker-compose.yml b/class-31/demo/things-api/docker-compose.yml new file mode 100644 index 0000000..2f4aaaf --- /dev/null +++ b/class-31/demo/things-api/docker-compose.yml @@ -0,0 +1,8 @@ +services: + web: + build: . + ports: + - "8000:8000" + command: python manage.py runserver 0.0.0.0:8000 + volumes: + - .:/code diff --git a/class-31/demo/things-api/requirements.txt b/class-31/demo/things-api/requirements.txt index 2dc0730..8cf7a1c 100644 --- a/class-31/demo/things-api/requirements.txt +++ b/class-31/demo/things-api/requirements.txt @@ -1,13 +1,5 @@ -asgiref==3.5.0 -click==8.0.4 -Django==4.0.3 -djangorestframework==3.13.1 -mccabe==0.6.1 -mypy-extensions==0.4.3 -pathspec==0.9.0 -platformdirs==2.5.1 -pycodestyle==2.8.0 -pyflakes==2.4.0 -pytz==2021.3 -sqlparse==0.4.2 -tomli==2.0.1 +asgiref==3.7.2 +Django==5.0.2 +djangorestframework==3.14.0 +pytz==2024.1 +sqlparse==0.4.4 diff --git a/class-31/demo/things-api/things/migrations/0001_initial.py b/class-31/demo/things-api/things/migrations/0001_initial.py index 726777d..7221ab2 100644 --- a/class-31/demo/things-api/things/migrations/0001_initial.py +++ b/class-31/demo/things-api/things/migrations/0001_initial.py @@ -1,8 +1,8 @@ -# Generated by Django 4.0.3 on 2022-03-03 23:09 +# Generated by Django 5.0.2 on 2024-02-17 16:54 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/class-31/demo/things-api/things_api_project/asgi.py b/class-31/demo/things-api/things_api_project/asgi.py index c1e36eb..e9fce96 100644 --- a/class-31/demo/things-api/things_api_project/asgi.py +++ b/class-31/demo/things-api/things_api_project/asgi.py @@ -4,7 +4,7 @@ It exposes the ASGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ +https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ """ import os diff --git a/class-31/demo/things-api/things_api_project/settings.py b/class-31/demo/things-api/things_api_project/settings.py index 45f44ba..52b3f76 100644 --- a/class-31/demo/things-api/things_api_project/settings.py +++ b/class-31/demo/things-api/things_api_project/settings.py @@ -1,13 +1,13 @@ """ Django settings for things_api_project project. -Generated by 'django-admin startproject' using Django 4.0.3. +Generated by 'django-admin startproject' using Django 5.0.2. For more information on this file, see -https://docs.djangoproject.com/en/4.0/topics/settings/ +https://docs.djangoproject.com/en/5.0/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/4.0/ref/settings/ +https://docs.djangoproject.com/en/5.0/ref/settings/ """ from pathlib import Path @@ -17,10 +17,10 @@ # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-ke)sw__nz&hzvq42cl)w8t8zt%_g1-g_8!ur3#%4)@$t)s-(5t" +SECRET_KEY = 'django-insecure-y0hx8ys-r4d0qr9jw_a&^=*f%h2kkvs-avlav1%0lx1t1tqdn&' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -31,85 +31,87 @@ # Application definition INSTALLED_APPS = [ - "django.contrib.admin", - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", - # third party - "rest_framework", - # local - "things", + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # 3rd party + 'rest_framework', + + # in house + 'things' ] MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", - "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", + 'django.middleware.security.SecurityMiddleware', + '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 = "things_api_project.urls" +ROOT_URLCONF = 'things_api_project.urls' TEMPLATES = [ { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], - "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", + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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 = "things_api_project.wsgi.application" +WSGI_APPLICATION = 'things_api_project.wsgi.application' # Database -# https://docs.djangoproject.com/en/4.0/ref/settings/#databases +# https://docs.djangoproject.com/en/5.0/ref/settings/#databases DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', } } # Password validation -# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization -# https://docs.djangoproject.com/en/4.0/topics/i18n/ +# https://docs.djangoproject.com/en/5.0/topics/i18n/ -LANGUAGE_CODE = "en-us" +LANGUAGE_CODE = 'en-us' -TIME_ZONE = "UTC" +TIME_ZONE = 'UTC' USE_I18N = True @@ -117,17 +119,11 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/4.0/howto/static-files/ +# https://docs.djangoproject.com/en/5.0/howto/static-files/ -STATIC_URL = "static/" +STATIC_URL = 'static/' # Default primary key field type -# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field +# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" - -REST_FRAMEWORK = { - "DEFAULT_PERMISSION_CLASSES": [ - "rest_framework.permissions.AllowAny", - ] -} +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/class-31/demo/things-api/things_api_project/urls.py b/class-31/demo/things-api/things_api_project/urls.py index 89b7d48..819fa91 100644 --- a/class-31/demo/things-api/things_api_project/urls.py +++ b/class-31/demo/things-api/things_api_project/urls.py @@ -1,7 +1,8 @@ -"""things_api_project URL Configuration +""" +URL configuration for things_api_project project. The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/4.0/topics/http/urls/ + https://docs.djangoproject.com/en/5.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views @@ -17,6 +18,6 @@ from django.urls import include, path urlpatterns = [ - path("admin/", admin.site.urls), + path('admin/', admin.site.urls), path("api/v1/things/", include("things.urls")), ] diff --git a/class-31/demo/things-api/things_api_project/wsgi.py b/class-31/demo/things-api/things_api_project/wsgi.py index 1e9570a..eab5e1e 100644 --- a/class-31/demo/things-api/things_api_project/wsgi.py +++ b/class-31/demo/things-api/things_api_project/wsgi.py @@ -4,7 +4,7 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/ """ import os