From c3f682ca7682bbb2a36d99b0b4975b1a78d91b8d Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 12 Jun 2024 08:51:02 +1200 Subject: [PATCH 1/7] Fix unbound local error on CTA buttons When the secondary nav menu hasn't been created, it causes a 500 --- cdhweb/pages/templatetags/core_tags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cdhweb/pages/templatetags/core_tags.py b/cdhweb/pages/templatetags/core_tags.py index ccf5318a..eace6cf8 100644 --- a/cdhweb/pages/templatetags/core_tags.py +++ b/cdhweb/pages/templatetags/core_tags.py @@ -132,8 +132,8 @@ def _get_secondary_nav_cta_button(): secondary_nav = SecondaryNavigation.objects.prefetch_related("cta_button") if secondary_nav.exists(): - cta_button = secondary_nav.first().cta_button.all() - return cta_button + return secondary_nav.first().cta_button.all() + return [] @register.simple_tag() From 31c492e79b81d26cb912f7a50b4b5609b9a4283d Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 12 Jun 2024 09:17:59 +1200 Subject: [PATCH 2/7] Remove references to compressor from Django --- cdhweb/settings/components/base.py | 22 ++----------------- cdhweb/settings/environments/test.py | 9 -------- .../settings/local_settings.py.docker-sample | 8 +------ cdhweb/settings/local_settings.py.sample | 6 ----- docker/application/Dockerfile | 3 +-- requirements.lock | 2 -- requirements/prod.txt | 2 -- 7 files changed, 4 insertions(+), 48 deletions(-) diff --git a/cdhweb/settings/components/base.py b/cdhweb/settings/components/base.py index bb04411a..421a0600 100644 --- a/cdhweb/settings/components/base.py +++ b/cdhweb/settings/components/base.py @@ -1,6 +1,7 @@ """ Django settings for cdhweb. """ + from pathlib import Path ######### @@ -33,7 +34,7 @@ # Additional locations of static files # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. -STATICFILES_DIRS = () +STATICFILES_DIRS = [BASE_DIR / "static"] # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. @@ -115,27 +116,9 @@ # Increase file upload size to roughly 50 MB FILEBROWSER_MAX_UPLOAD_SIZE = 50000000 -# Use local node-sass installed via npm -COMPRESS_PRECOMPILERS = (("text/x-scss", "node_modules/.bin/sass {infile} {outfile}"),) - -# Use local postcss-cli and autoprefixer installed via npm -COMPRESS_AUTOPREFIXER_BINARY = "node_modules/postcss-cli/bin/postcss" - -COMPRESS_CSS_FILTERS = ( - "compressor.filters.css_default.CssAbsoluteFilter", - # NOTE: requires COMPRESS_ENABLED = True when DEBUG is True - "django_compressor_autoprefixer.AutoprefixerFilter", -) - -# use content hashing to ensure same url on both servers -COMPRESS_CSS_HASHING_METHOD = "content" - - STATICFILES_FINDERS = ( "django.contrib.staticfiles.finders.FileSystemFinder", "django.contrib.staticfiles.finders.AppDirectoriesFinder", - # other finders.. - "compressor.finders.CompressorFinder", ) # Package/module name to import the root urlpatterns from for the project. @@ -207,7 +190,6 @@ "modelcluster", "taggit", "adminsortable2", - "compressor", "fullurl", "django_cas_ng", "wagtailcodeblock", diff --git a/cdhweb/settings/environments/test.py b/cdhweb/settings/environments/test.py index 5d104559..81452c4b 100644 --- a/cdhweb/settings/environments/test.py +++ b/cdhweb/settings/environments/test.py @@ -22,14 +22,5 @@ # required for tests when DEBUG = False ALLOWED_HOSTS = ["*"] -# configure django-compressor to compress css & javascript -COMPRESS_ENABLED = True - -# compress to the sitemedia folder -COMPRESS_ROOT = BASE_DIR / "sitemedia" - -# run a full compress before e2e/a11y tests to serve statically -COMPRESS_OFFLINE = True - # override software version to avoid creating visual diffs in display SW_VERSION = "CI Build" diff --git a/cdhweb/settings/local_settings.py.docker-sample b/cdhweb/settings/local_settings.py.docker-sample index d37d44d0..9c6c71df 100644 --- a/cdhweb/settings/local_settings.py.docker-sample +++ b/cdhweb/settings/local_settings.py.docker-sample @@ -39,12 +39,6 @@ PUCAS_LDAP.update( } ) -# optional configuration for compress autoprefixer -# COMPRESS_AUTOPREFIXER_BINARY = '/usr/local/bin/postcss' -# COMPRESS_AUTOPREFIXER_ARGS = '--use autoprefixer' (default) - -COMPRESS_ENABLED = False - # sample logging config LOGGING = { "version": 1, @@ -70,4 +64,4 @@ LOGGING = { CSRF_TRUSTED_ORIGINS = ["http://localhost", "https://cdh.dev.springload.nz"] # disable feature detection in images -WAGTAILIMAGES_FEATURE_DETECTION_ENABLED = False \ No newline at end of file +WAGTAILIMAGES_FEATURE_DETECTION_ENABLED = False diff --git a/cdhweb/settings/local_settings.py.sample b/cdhweb/settings/local_settings.py.sample index 4e1b89fb..1bad57ab 100644 --- a/cdhweb/settings/local_settings.py.sample +++ b/cdhweb/settings/local_settings.py.sample @@ -40,12 +40,6 @@ PUCAS_LDAP.update( } ) -# optional configuration for compress autoprefixer -# COMPRESS_AUTOPREFIXER_BINARY = '/usr/local/bin/postcss' -# COMPRESS_AUTOPREFIXER_ARGS = '--use autoprefixer' (default) - -COMPRESS_ENABLED = False - # sample logging config LOGGING = { "version": 1, diff --git a/docker/application/Dockerfile b/docker/application/Dockerfile index 085be71c..bbb62ad5 100644 --- a/docker/application/Dockerfile +++ b/docker/application/Dockerfile @@ -70,11 +70,10 @@ ENV DJANGO_SETTINGS_MODULE cdhweb.settings ADD --chmod=755 https://github.com/mrako/wait-for/releases/download/v1.0.0/wait-for /usr/local/bin/ -# TODO: Frontend: Remove npm install once deps are built without compressor RUN --mount=type=cache,target=/var/lib/apt/lists \ --mount=type=cache,target=/var/cache/apt \ apt-get update -y && apt-get install --no-install-recommends -y \ - netcat npm + netcat RUN --mount=type=cache,target=/root/.cache/pip \ pip3 install -r /app/requirements/dev.txt \ diff --git a/requirements.lock b/requirements.lock index 801cbdf2..2c88c7ae 100644 --- a/requirements.lock +++ b/requirements.lock @@ -22,8 +22,6 @@ django-appconf==1.0.4 django-apptemplates==1.5 django-cas-ng==4.1.1 django-cogwheels==0.3 -django-compressor==2.4.1 -django-compressor-autoprefixer==0.1.0 django-contrib-comments==2.0.0 django-dbml @ git+git://github.com/thatbudakguy/django-dbml@334ead74c8c4fa4ae997adeccaa5f3d5367f17b2 django-debug-toolbar==3.2 diff --git a/requirements/prod.txt b/requirements/prod.txt index 45b3bdb7..cb80416b 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -1,8 +1,6 @@ Django>=4.2,<5.1 pillow>=9.1.0 wagtail>=5.2,<6.0 -django-compressor -django-compressor-autoprefixer psycopg2-binary django-admin-sortable2 # wagtail 4.2 requires taggit<5.0 From 51535d13c554102e09ee797398b9b7acf46b061e Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 12 Jun 2024 09:18:39 +1200 Subject: [PATCH 3/7] Remove the compressor references, and npm tooling from unit tests CI --- .github/workflows/unit_tests.yml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index d9a35ba5..5336b234 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -33,30 +33,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # We need node to install the JS dependencies used to build static assets. - # Because some unit tests use Django's test client to visit pages, we need - # to have JS and styles ready to be loaded on those pages or there will be - # errors. - # Uses the node version specified in package.json - - name: Setup node - uses: actions/setup-node@v4 - - # Basing the cache on the hash of the lockfile means that the cache should - # only ever be invalidated when we update package-lock.json, which happens - # as part of a release. For more info, see: - # https://docs.github.com/en/free-pro-team@latest/actions/guides/caching-dependencies-to-speed-up-workflows - - name: Cache node modules - uses: actions/cache@v2 - with: - path: ~/.npm - key: npm-${{ hashFiles('package-lock.json') }} - restore-keys: | - npm-${{ hashFiles('package-lock.json') }} - npm- - - - name: Install JS dependencies - run: npm ci - # Python version to use is stored in the .python-version file, which is the # convention for pyenv (https://github.com/pyenv/pyenv) # setup-python automatically picks up version from .python-version @@ -80,9 +56,6 @@ jobs: - name: Setup local_settings.py run: python -c "import uuid; print('SECRET_KEY = \'%s\'' % uuid.uuid4())" >> cdhweb/settings/local_settings.py - - name: Build static assets - run: python manage.py compress - - name: Run pytest run: pytest --cov=./ --cov-config=.coveragerc --cov-report=xml From d922cafb7b074fa786c502034a97e876e3588b10 Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 12 Jun 2024 09:19:20 +1200 Subject: [PATCH 4/7] Remove frontend build from dockerfile It's usually only used for the Springload docker-based deploy, so it's not useful here --- docker/application/Dockerfile | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/docker/application/Dockerfile b/docker/application/Dockerfile index bbb62ad5..f4aacf06 100644 --- a/docker/application/Dockerfile +++ b/docker/application/Dockerfile @@ -1,31 +1,8 @@ # syntax=docker/dockerfile:1.4 -## Frontend TODO once Springload approach added -# # frontend assets -# FROM node:20-alpine as frontend - -# RUN apk add --update git - -# WORKDIR /app - -# # Install packages -# COPY package.json package-lock.json /app/ -# RUN --mount=type=cache,target=/root/.npm NPM_CACHE_FOLDER=/root/.npm \ -# npm ci - -# # Copy config/build files -# COPY webpack.config.js webpack.fix-django-paths.js tsconfig.json /app/ -# COPY core/static_src /app/core/static_src -# COPY core/templates_src /app/core/templates_src - -# RUN npm run build - -# CMD ["npm", "run build"] - - ## ----- # Base backend -# On Debian, as their prod is Ubuntu +# On Debian, as prod is Ubuntu FROM --platform=linux/x86_64 python:3.11-slim-bullseye as base ENV PROJECT cdh-web From ac0069f05a5dc258989f3a58371fc062b268b8db Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 12 Jun 2024 09:36:00 +1200 Subject: [PATCH 5/7] Add dev routes for 404 and 500 pages --- cdhweb/urls.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cdhweb/urls.py b/cdhweb/urls.py index 3159acb7..25bc61a8 100644 --- a/cdhweb/urls.py +++ b/cdhweb/urls.py @@ -78,8 +78,6 @@ # wagtail paths path("cms/", include(wagtailadmin_urls)), path("documents/", include(wagtaildocs_urls)), - # let wagtail handle everything else - path("", include(wagtail_urls)), ] if settings.DEBUG: @@ -90,6 +88,13 @@ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += staticfiles_urlpatterns() + # Serve 404 and 500 page templates(seeing as errors are masked with debug) + urlpatterns.extend( + [ + path("404/", TemplateView.as_view(template_name="404.html")), + path("500/", TemplateView.as_view(template_name="500.html")), + ] + ) try: import debug_toolbar @@ -97,3 +102,8 @@ urlpatterns.insert(0, path("__debug__/", include(debug_toolbar.urls))) except ImportError: pass + +urlpatterns.append( + # let wagtail handle everything else + path("", include(wagtail_urls)), +) From e47b5107b356fd717bf3dcb6b3d9c56dfb1bd98f Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 12 Jun 2024 09:44:36 +1200 Subject: [PATCH 6/7] Fix up the references to people index in projects tests Looks like an overzealous refactor added extra words --- cdhweb/projects/tests/test_pages.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cdhweb/projects/tests/test_pages.py b/cdhweb/projects/tests/test_pages.py index 18fb4b89..02b2a07a 100644 --- a/cdhweb/projects/tests/test_pages.py +++ b/cdhweb/projects/tests/test_pages.py @@ -5,9 +5,9 @@ from cdhweb.projects.models import ( Grant, GrantType, - PeopleLandingPageArchivedArchived, Project, ProjectRelatedLink, + ProjectsLandingPageArchived, ) @@ -94,18 +94,18 @@ def test_sitemap(self, rf, derrida): class TestProjectPage(WagtailPageTestCase): def test_parent_pages(self): """project can only be created under projects link page""" - self.assertAllowedParentPageTypes(Project, [PeopleLandingPageArchivedArchived]) + self.assertAllowedParentPageTypes(Project, [ProjectsLandingPageArchived]) def test_subpages(self): """project page can't have children""" self.assertAllowedSubpageTypes(Project, []) -class TestPeopleLandingPageArchived(WagtailPageTestCase): +class TestProjectsLandingPageArchived(WagtailPageTestCase): def test_parentpage_types(self): """projects link page should not be creatable in admin""" - self.assertAllowedParentPageTypes(PeopleLandingPageArchived, []) + self.assertAllowedParentPageTypes(ProjectsLandingPageArchived, []) def test_subpage_types(self): """projects link page only allowed child is project page""" - self.assertAllowedSubpageTypes(PeopleLandingPageArchived, [Project, LinkPage]) + self.assertAllowedSubpageTypes(ProjectsLandingPageArchived, [Project, LinkPage]) From 43d1227ad92d23e607e0246d7ac2a084df23aaa6 Mon Sep 17 00:00:00 2001 From: Haydn Greatnews Date: Wed, 12 Jun 2024 09:49:26 +1200 Subject: [PATCH 7/7] Update version to 4.0.0-dev, and add placeholder changelog --- CHANGELOG.rst | 10 +++++++--- cdhweb/__init__.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2644ec8a..9bf00793 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ CHANGELOG ========= +4.0.0-dev1 +----- +- Redesigned and rebuilt +- TODO + 3.5.3 ----- @@ -30,7 +35,7 @@ Maintenance release: npm package updates - updated to django 4.2 and wagtail 5.0 - updated to python 3.8+ (tested against 3.8-3.11) - updated node version 18 -- removed editoria11y v1 integration +- removed editoria11y v1 integration - removed Percy visual testing workflow 3.4.4 @@ -41,7 +46,7 @@ Maintenance release: npm package updates 3.4.3 ----- -* Update to include Humanities + Data Science Institute instructors and participants as +* Update to include Humanities + Data Science Institute instructors and participants as affiliates and student affiliates * bugfixes: * correct Event ordering on semester archive pages @@ -401,4 +406,3 @@ Other Content Import ~~~~~~ * As an admin, I want an import of content from the previous version of the site so that all the information available on the old site is migrated to the new version. - diff --git a/cdhweb/__init__.py b/cdhweb/__init__.py index 0f6037dc..6428f99b 100644 --- a/cdhweb/__init__.py +++ b/cdhweb/__init__.py @@ -1,4 +1,4 @@ -__version_info__ = (3, 5, 3, None) +__version_info__ = (4, 0, 0, "dev1") # Dot-connect all but the last. Last is dash-connected if not None.