Skip to content

Commit 60b15e6

Browse files
authored
Feat: create runnable Django project (#29)
2 parents 6be0d73 + be2d9b1 commit 60b15e6

File tree

11 files changed

+237
-0
lines changed

11 files changed

+237
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@
1818
},
1919
// Add the IDs of extensions you want installed when the container is created.
2020
"extensions": [
21+
"batisteo.vscode-django",
2122
"bpruitt-goddard.mermaid-markdown-syntax-highlighting",
2223
"DavidAnson.vscode-markdownlint",
2324
"eamodio.gitlens",
2425
"esbenp.prettier-vscode",
2526
"mhutchie.git-graph",
27+
"monosans.djlint",
28+
"ms-python.python",
29+
"ms-python.black-formatter",
30+
"ms-python.flake8",
31+
"qwtel.sqlite-viewer",
2632
"tamasfe.even-better-toml"
2733
]
2834
}

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.git/
22
*.egg-info
3+
*.db

.env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Django storage
2+
DJANGO_STORAGE_DIR=.
3+
DJANGO_DB_FILE=django.db
4+
15
# uncomment to start the elasticstack services with compose
26
# COMPOSE_PROFILES=elasticstack
37

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 127

.vscode/launch.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Django: PeMS Client",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/manage.py",
12+
"args": ["runserver", "--insecure", "0.0.0.0:8000"],
13+
"django": true,
14+
"env": {
15+
"DJANGO_DEBUG": "true",
16+
"PYTHONWARNINGS": "default"
17+
}
18+
},
19+
{
20+
"name": "Django: PeMS Client, Debug=False",
21+
"type": "debugpy",
22+
"request": "launch",
23+
"program": "${workspaceFolder}/manage.py",
24+
"args": ["runserver", "--insecure", "0.0.0.0:8000"],
25+
"django": true,
26+
"env": {
27+
"DJANGO_DEBUG": "false",
28+
"DJANGO_STATICFILES_STORAGE": "django.contrib.staticfiles.storage.StaticFilesStorage"
29+
}
30+
}
31+
]
32+
}

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"[django-html][html]": {
3+
"editor.defaultFormatter": "monosans.djlint",
4+
"djlint.enableLinting": true,
5+
"djlint.profile": "django"
6+
},
27
"editor.formatOnSave": true,
38
"editor.defaultFormatter": "esbenp.prettier-vscode",
49
"files.associations": {
@@ -11,5 +16,12 @@
1116
"files.trimTrailingWhitespace": true,
1217
"[markdown]": {
1318
"editor.defaultFormatter": "esbenp.prettier-vscode"
19+
},
20+
"[python]": {
21+
"editor.defaultFormatter": "ms-python.black-formatter"
22+
},
23+
"python.languageServer": "Pylance",
24+
"workbench.editorAssociations": {
25+
"*.db": "sqlite-viewer.option"
1426
}
1527
}

manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pems.settings")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()

pems/settings.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
"""
2+
Django settings for pems project.
3+
"""
4+
5+
from pathlib import Path
6+
import os
7+
8+
9+
def _filter_empty(ls):
10+
return [s for s in ls if s]
11+
12+
13+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
14+
BASE_DIR = Path(__file__).resolve().parent.parent
15+
16+
# SECURITY WARNING: keep the secret key used in production secret!
17+
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "secret")
18+
19+
# SECURITY WARNING: don't run with debug turned on in production!
20+
DEBUG = os.environ.get("DJANGO_DEBUG", "False").lower() == "true"
21+
22+
ALLOWED_HOSTS = _filter_empty(os.environ.get("DJANGO_ALLOWED_HOSTS", "localhost").split(","))
23+
24+
25+
# Application definition
26+
27+
INSTALLED_APPS = [
28+
"django.contrib.admin",
29+
"django.contrib.auth",
30+
"django.contrib.contenttypes",
31+
"django.contrib.sessions",
32+
"django.contrib.messages",
33+
"django.contrib.staticfiles",
34+
]
35+
36+
MIDDLEWARE = [
37+
"django.middleware.security.SecurityMiddleware",
38+
"django.contrib.sessions.middleware.SessionMiddleware",
39+
"django.middleware.common.CommonMiddleware",
40+
"django.middleware.csrf.CsrfViewMiddleware",
41+
"django.contrib.auth.middleware.AuthenticationMiddleware",
42+
"django.contrib.messages.middleware.MessageMiddleware",
43+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
44+
]
45+
46+
ROOT_URLCONF = "pems.urls"
47+
48+
TEMPLATES = [
49+
{
50+
"BACKEND": "django.template.backends.django.DjangoTemplates",
51+
"DIRS": [],
52+
"APP_DIRS": True,
53+
"OPTIONS": {
54+
"context_processors": [
55+
"django.template.context_processors.debug",
56+
"django.template.context_processors.request",
57+
"django.contrib.auth.context_processors.auth",
58+
"django.contrib.messages.context_processors.messages",
59+
],
60+
},
61+
},
62+
]
63+
64+
WSGI_APPLICATION = "pems.wsgi.application"
65+
66+
67+
# Database
68+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
69+
70+
STORAGE_DIR = os.environ.get("DJANGO_STORAGE_DIR", BASE_DIR)
71+
DATABASES = {
72+
"default": {
73+
"ENGINE": "django.db.backends.sqlite3",
74+
"NAME": Path(STORAGE_DIR) / os.environ.get("DJANGO_DB_FILE", "django.db"),
75+
}
76+
}
77+
78+
79+
# Password validation
80+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
81+
82+
AUTH_PASSWORD_VALIDATORS = [
83+
{
84+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
85+
},
86+
{
87+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
88+
},
89+
{
90+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
91+
},
92+
{
93+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
94+
},
95+
]
96+
97+
98+
# Internationalization
99+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
100+
101+
LANGUAGE_CODE = "en-us"
102+
103+
TIME_ZONE = "UTC"
104+
105+
USE_I18N = True
106+
107+
USE_TZ = True
108+
109+
110+
# Static files (CSS, JavaScript, Images)
111+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
112+
113+
STATIC_URL = "static/"
114+
115+
# Default primary key field type
116+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
117+
118+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

pems/urls.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
URL configuration for pems project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.1/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
18+
from django.contrib import admin
19+
from django.urls import path
20+
21+
urlpatterns = [
22+
path("admin/", admin.site.urls),
23+
]

pems/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for pems project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pems.settings")
15+
16+
application = get_wsgi_application()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ maintainers = [
1010
{ name = "Compiler LLC", email = "dev@compiler.la" }
1111
]
1212
dependencies = [
13+
"Django==5.1.4"
1314
]
1415

1516
[project.optional-dependencies]

0 commit comments

Comments
 (0)