Skip to content

Commit 445e4c4

Browse files
authored
Update project template (#604)
Basic template: * Add `CoderedEventPage` and `CoderedLocationPage` (and associated models) to the default template. This exposes those models to new projects without having to write additional code. * Add a pyproject.toml to prevent Django from trying to blacken migrations when starting a new project. At some point Django started doing this and it can potentially cause a huge slowdown. Sass template (renamed to "pro"): * Same changes from basic template * This will be designated as the "professional" template for use in real-world projects. Therefore, this template provides a full suite of pre-configured developer tooling. * Provide `ruff` with configuration. * Provide `mypy` with configuration. * Provide `pytest` with configuration. * Provides custom User, Image, and Document models by default. Related changes: * To further avoid lag from the Django template renderer, we now explicitly define files in project_template which are actually templates. * Add pipeline test matrix that checks both basic and pro templates.
1 parent fe2f16b commit 445e4c4

54 files changed

Lines changed: 49784 additions & 932 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

azure-pipelines.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,27 @@ stages:
3434
py3.8_wag5.0:
3535
PYTHON_VERSION: '3.8'
3636
WAGTAIL_VERSION: '5.0.*'
37+
TEMPLATE: 'basic'
3738
py3.9_wag5.0:
3839
PYTHON_VERSION: '3.9'
3940
WAGTAIL_VERSION: '5.0.*'
41+
TEMPLATE: 'basic'
4042
py3.10_wag5.0:
4143
PYTHON_VERSION: '3.10'
4244
WAGTAIL_VERSION: '5.0.*'
45+
TEMPLATE: 'basic'
4346
py3.11_wag5.1:
4447
PYTHON_VERSION: '3.11'
4548
WAGTAIL_VERSION: '5.1.*'
46-
py3.12_wag5.2:
49+
TEMPLATE: 'basic'
50+
py3.12_wag5.2_basic:
4751
PYTHON_VERSION: '3.12'
4852
WAGTAIL_VERSION: '5.2.*'
53+
TEMPLATE: 'basic'
54+
py3.12_wag5.2_pro:
55+
PYTHON_VERSION: '3.12'
56+
WAGTAIL_VERSION: '5.2.*'
57+
TEMPLATE: 'pro'
4958

5059
steps:
5160
- task: UsePythonVersion@0
@@ -57,9 +66,16 @@ stages:
5766
- script: python -m pip install -r requirements-ci.txt wagtail==$(WAGTAIL_VERSION)
5867
displayName: 'CR-QC: Install coderedcms from local repo'
5968

60-
- script: coderedcms start testproject
69+
- script: coderedcms start testproject --template $(TEMPLATE)
6170
displayName: 'CR-QC: Create starter project from template'
6271

72+
- script: |
73+
cd testproject/
74+
touch requirements-dev.txt
75+
python -m pip install -r requirements-dev.txt
76+
python manage.py makemigrations --check
77+
displayName: 'CR-QC: Check migrations'
78+
6379
- pwsh: ./ci/run-tests.ps1
6480
displayName: 'CR-QC: Run unit tests'
6581

@@ -101,14 +117,6 @@ stages:
101117
- pwsh: ./ci/spellcheck.ps1
102118
displayName: 'CR-QC: Spelling'
103119

104-
- script: coderedcms start testproject
105-
displayName: 'CR-QC: Generate a test project'
106-
107-
- script: |
108-
cd testproject/
109-
python manage.py makemigrations --check
110-
displayName: 'CR-QC: Check migrations'
111-
112120
- script: black --check .
113121
displayName: 'CR-QC: Black'
114122

coderedcms/bin/coderedcms.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,17 @@ def handle(self, **options):
6161
if os.path.isdir(template_path):
6262
options["template"] = template_path
6363

64+
# Assume all files are NOT Django templates.
65+
options["extensions"] = ["toml"]
6466
# Treat these files as Django templates to render the boilerplate.
65-
options["extensions"] = ["py", "md", "txt"]
66-
options["files"] = ["Dockerfile"]
67+
options["files"] = [
68+
"0002_initial_data.py",
69+
"base.py",
70+
"manage.py",
71+
"README.md",
72+
"requirements.txt",
73+
"wsgi.py",
74+
]
6775

6876
# Set options
6977
message = "Creating a Wagtail CRX project called %(project_name)s"

coderedcms/project_template/basic/.gitignore

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Created by https://www.gitignore.io, modified for use with CodeRed CMS.
1+
# Created by https://www.gitignore.io, modified for use with Wagtail CRX.
22

33
#######################################
44
### Editors
@@ -197,7 +197,7 @@ tags
197197
*.pyc
198198
__pycache__/
199199
local_settings.py
200-
db.sqlite3
200+
*.sqlite3
201201

202202
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
203203
# in your Git repository. Update and uncomment the following line accordingly.
@@ -315,6 +315,15 @@ dmypy.json
315315
# Pyre type checker
316316
.pyre/
317317

318+
# Ruff
319+
.ruff_cache/
320+
321+
322+
323+
#######################################
324+
### Operating Systems
325+
#######################################
326+
318327

319328
### OSX ###
320329

@@ -346,12 +355,6 @@ Temporary Items
346355
.apdisk
347356

348357

349-
350-
#######################################
351-
### Operating Systems
352-
#######################################
353-
354-
355358
### Windows ###
356359

357360
# Windows thumbnail cache files
@@ -381,19 +384,18 @@ $RECYCLE.BIN/
381384

382385

383386
#######################################
384-
### CodeRed CMS
387+
### Wagtail CRX
385388
#######################################
386389

387390

388-
#### CodeRed CMS defaults ###
389-
390391
# Cache
391392
cache/
392393

393394
# File uploads from forms
394-
protected/
395+
/protected/
396+
397+
# Media files
398+
/media/
395399

396-
# if you want to store original uploaded media files in version control,
397-
# replace "media/" with "media/images/"
398-
media/
399-
#media/images/
400+
# Collected static files
401+
/static/

coderedcms/project_template/basic/manage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import os
33
import sys
44

5+
56
if __name__ == "__main__":
67
os.environ.setdefault(
7-
"DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings.dev"
8+
"DJANGO_SETTINGS_MODULE",
9+
"{{ project_name }}.settings.dev",
810
)
911

1012
from django.core.management import execute_from_command_line

coderedcms/project_template/basic/project_name/settings/base.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/
1111
"""
1212

13-
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14-
import os
15-
from django.utils.translation import gettext_lazy as _
13+
from pathlib import Path
1614

17-
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
18-
BASE_DIR = os.path.dirname(PROJECT_DIR)
15+
16+
# Build paths inside the project like this: BASE_DIR / "subdir".
17+
BASE_DIR = Path(__file__).resolve().parent.parent.parent
1918

2019

2120
# Quick-start development settings - unsuitable for production
@@ -70,8 +69,6 @@
7069
"django.contrib.auth.middleware.AuthenticationMiddleware",
7170
"django.middleware.clickjacking.XFrameOptionsMiddleware",
7271
"django.middleware.security.SecurityMiddleware",
73-
# Error reporting. Uncomment this to receive emails when a 404 is triggered.
74-
# 'django.middleware.common.BrokenLinkEmailsMiddleware',
7572
# CMS functionality
7673
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
7774
# Fetch from cache. Must be LAST.
@@ -105,7 +102,7 @@
105102
DATABASES = {
106103
"default": {
107104
"ENGINE": "django.db.backends.sqlite3",
108-
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
105+
"NAME": BASE_DIR / "db.sqlite3",
109106
}
110107
}
111108

@@ -128,17 +125,15 @@
128125
},
129126
]
130127

128+
131129
# Internationalization
132130
# https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/
133131

134-
# To add or change language of the project, modify the list below.
135132
LANGUAGE_CODE = "en-us"
136133

137-
LANGUAGES = [("en-us", _("English"))]
138-
139134
TIME_ZONE = "America/New_York"
140135

141-
USE_I18N = True
136+
USE_I18N = False
142137

143138
USE_TZ = True
144139

@@ -151,10 +146,10 @@
151146
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
152147
]
153148

154-
STATIC_ROOT = os.path.join(BASE_DIR, "static")
149+
STATIC_ROOT = BASE_DIR / "static"
155150
STATIC_URL = "/static/"
156151

157-
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
152+
MEDIA_ROOT = BASE_DIR / "media"
158153
MEDIA_URL = "/media/"
159154

160155

@@ -170,11 +165,6 @@
170165

171166
WAGTAIL_ENABLE_UPDATE_CHECK = False
172167

173-
WAGTAILSEARCH_BACKENDS = {
174-
"default": {
175-
"BACKEND": "wagtail.search.backends.database",
176-
}
177-
}
178168

179169
# Base URL to use when referring to full URLs within the Wagtail admin backend -
180170
# e.g. in notification emails. Don't include '/admin' or a trailing slash

coderedcms/project_template/basic/project_name/settings/prod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
CACHES = {
3333
"default": {
3434
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
35-
"LOCATION": os.path.join(BASE_DIR, "cache"), # noqa
35+
"LOCATION": BASE_DIR / "cache", # noqa
3636
"KEY_PREFIX": "coderedcms",
3737
"TIMEOUT": 14400, # in seconds
3838
}

coderedcms/project_template/basic/project_name/urls.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from django.conf import settings
2-
from django.urls import include, path
3-
from django.contrib import admin
4-
from wagtail.documents import urls as wagtaildocs_urls
51
from coderedcms import admin_urls as crx_admin_urls
62
from coderedcms import search_urls as crx_search_urls
73
from coderedcms import urls as crx_urls
4+
from django.conf import settings
5+
from django.contrib import admin
6+
from django.urls import include
7+
from django.urls import path
8+
from wagtail.documents import urls as wagtaildocs_urls
9+
810

911
urlpatterns = [
1012
# Admin
@@ -24,10 +26,11 @@
2426
]
2527

2628

29+
# fmt: off
2730
if settings.DEBUG:
2831
from django.conf.urls.static import static
29-
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
3032

3133
# Serve static and media files from development server
32-
urlpatterns += staticfiles_urlpatterns()
33-
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
34+
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) # type: ignore
35+
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # type: ignore
36+
# fmt: on

coderedcms/project_template/basic/project_name/wsgi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
from django.core.wsgi import get_wsgi_application
1313

14+
1415
os.environ.setdefault(
15-
"DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings.dev"
16+
"DJANGO_SETTINGS_MODULE",
17+
"{{ project_name }}.settings.dev",
1618
)
1719

1820
application = get_wsgi_application()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[tool.black]
2+
line-length = 80
3+
extend-exclude = ["migrations"]
4+
5+
[tool.django-stubs]
6+
django_settings_module = "{{ project_name }}.settings.dev"
7+
8+
[tool.mypy]
9+
ignore_missing_imports = true
10+
plugins = ["mypy_django_plugin.main"]
11+
exclude = [
12+
'^\..*',
13+
'migrations',
14+
'node_modules',
15+
'venv',
16+
]
17+
18+
[tool.pytest.ini_options]
19+
DJANGO_SETTINGS_MODULE = "{{ project_name }}.settings.dev"
20+
addopts = "--cov --cov-report html"
21+
python_files = "tests.py test_*.py"
22+
23+
[tool.ruff]
24+
extend-exclude = ["migrations"]
25+
line-length = 80
26+
27+
[tool.ruff.lint]
28+
extend-select = ["I"]
29+
30+
[tool.ruff.lint.isort]
31+
case-sensitive = false
32+
force-single-line = true
33+
lines-after-imports = 2

0 commit comments

Comments
 (0)