Skip to content

Commit

Permalink
feat!: Upgrade backend (Python, Django, Wagtail) (#350)
Browse files Browse the repository at this point in the history
* Upgrade to Django 4.0

* Drop django-compressor and django-libsass

* Upgrade to Wagtail 4.2

* Upgrade to Django 4.1

* Upgrade to Python 3.11

* Test a simple search query

* Upgrade to Wagtail 5.0

* Upgrade to Django 4.2

* Upgrade to Wagtail 5.1

* Upgrade to Wagtail 5.2

* Upgrade to Python 3.12

* Switch from psycopg2-binary to psycopg2

* Remove unhelpful version pins
  • Loading branch information
mgax authored Dec 5, 2023
1 parent 3425133 commit baca04e
Show file tree
Hide file tree
Showing 21 changed files with 194 additions and 101 deletions.
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CMD ["yarn", "start"]
# BASE
# ---------------------------------------------------------------------
# Base backend
FROM python:3.10-alpine as base
FROM python:3.12-alpine as base
ENV PYCURL_SSL_LIBRARY openssl

RUN apk update && apk add postgresql-libs postgresql-client libevent libjpeg openjpeg zlib
Expand Down Expand Up @@ -85,7 +85,7 @@ COPY docker/init-dev.sh /app/docker/

ADD https://raw.githubusercontent.com/mrako/wait-for/d9699cb9fe8a4622f05c4ee32adf2fd93239d005/wait-for /usr/local/bin/
USER root
RUN apk add --no-cache bash
RUN apk add --no-cache bash postgresql-dev
RUN pip3 install -r requirements/dev.txt
RUN chmod +rx /usr/local/bin/wait-for
USER www
Expand Down
3 changes: 2 additions & 1 deletion ietf/bibliography/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def save(self, *args, **kwargs):
recreate_bibliography_items = False

if recreate_bibliography_items:
self.bibliography_items.all().delete()
if self.pk is not None:
self.bibliography_items.all().delete()

all_content = "".join(
[
Expand Down
2 changes: 1 addition & 1 deletion ietf/bibliography/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def register_references_menu_item():
return MenuItem(
"References",
reverse("referenced_types"),
classnames="icon icon-folder-inverse",
classname="icon icon-folder-inverse",
order=10000,
)
2 changes: 1 addition & 1 deletion ietf/home/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def register_resource_menu_item():
return MenuItem(
"Documentation",
reverse("django-admindocs-docroot"),
classnames="icon icon-folder-inverse",
classname="icon icon-folder-inverse",
order=10000,
)
24 changes: 24 additions & 0 deletions ietf/images/migrations/0003_wagtail_42_wagtailimagefield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.0.10 on 2023-11-29 10:19

from django.db import migrations
import wagtail.images.models


class Migration(migrations.Migration):

dependencies = [
('images', '0002_alter_ietfimage_file_hash'),
]

operations = [
migrations.AlterField(
model_name='ietfimage',
name='file',
field=wagtail.images.models.WagtailImageField(height_field='height', upload_to=wagtail.images.models.get_upload_to, verbose_name='file', width_field='width'),
),
migrations.AlterField(
model_name='ietfrendition',
name='file',
field=wagtail.images.models.WagtailImageField(height_field='height', upload_to=wagtail.images.models.get_rendition_upload_to, width_field='width'),
),
]
19 changes: 19 additions & 0 deletions ietf/images/migrations/0004_django_42_rendition_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.7 on 2023-11-29 12:17

from django.db import migrations
import wagtail.images.models


class Migration(migrations.Migration):

dependencies = [
('images', '0003_wagtail_42_wagtailimagefield'),
]

operations = [
migrations.AlterField(
model_name='ietfrendition',
name='file',
field=wagtail.images.models.WagtailImageField(height_field='height', storage=wagtail.images.models.get_rendition_storage, upload_to=wagtail.images.models.get_rendition_upload_to, width_field='width'),
),
]
3 changes: 2 additions & 1 deletion ietf/search/templates/search/search.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends settings.utils.LayoutSettings.base_template %}
{% load static wagtailcore_tags %}
{% load static wagtailcore_tags wagtailsearchpromotions_tags %}

{% block title %}Search{% endblock %}

Expand Down Expand Up @@ -38,6 +38,7 @@ <h1>Search results for {{ SITE.hostname }}</h1>
<div class="col-12 col-lg-8 pt-3 pt-lg-3 pe-lg-3">
<div class="u-max-text-width pb-4">

{% get_search_promotions search_query as search_picks %}
{% if search_picks %}
<h2 class="visually-hidden">Search results{% if search_query %} for "{{ search_query }}"{% endif %}</h2>
<ul class="list-unstyled">
Expand Down
58 changes: 58 additions & 0 deletions ietf/search/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from django.test import TestCase
from django.urls import reverse
from wagtail.models import Page, Site

from ..blog.models import BlogIndexPage, BlogPage
from ..home.models import HomePage


class SearchTests(TestCase):
def test_search(self):

root = Page.get_first_root_node()

home = HomePage(
slug="homepageslug",
title="home page title",
heading="home page heading",
introduction="home page introduction",
request_for_comments_section_body="rfc section body",
working_groups_section_body="wg section body",
)

root.add_child(instance=home)

Site.objects.all().delete()

Site.objects.create(
hostname="localhost",
root_page=home,
is_default_site=True,
site_name="testingsitename",
)

blogindex = BlogIndexPage(
slug="blog",
title="blog index title",
)
home.add_child(instance=blogindex)

blog = BlogPage(
slug="blogpost",
title="blog title",
introduction="blog introduction",
body='[{"id": "1", "type": "rich_text", "value": "<p>blog body</p>"}]',
)
blogindex.add_child(instance=blog)

home.button_text = "blog button text"
home.button_link = blog
home.save()

resp = self.client.get(f"{reverse('search')}?query=introduction")

self.assertEqual(resp.context["search_query"], "introduction")
self.assertEqual(
list(resp.context["search_results"]),
[Page.objects.get(pk=blog.pk)],
)
12 changes: 2 additions & 10 deletions ietf/search/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.shortcuts import render
from wagtail.contrib.search_promotions.models import SearchPromotion
from wagtail.models import Page
from wagtail.search.models import Query
from wagtail.contrib.search_promotions.models import Query


def search(request):
Expand All @@ -12,16 +11,10 @@ def search(request):
# Search
if search_query and "\x00" not in search_query:
search_results = Page.objects.live().search(search_query)
query = Query.get(search_query)
Query.get(search_query).add_hit()

# Record hit
query.add_hit()

# Get search picks
search_picks = query.editors_picks.all()
else:
search_results = Page.objects.none()
search_picks = SearchPromotion.objects.none()

# Pagination
paginator = Paginator(search_results, 10)
Expand All @@ -38,6 +31,5 @@ def search(request):
{
"search_query": search_query,
"search_results": search_results,
"search_picks": search_picks,
},
)
20 changes: 9 additions & 11 deletions ietf/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
"wagtail.contrib.settings",
"wagtail.contrib.table_block",
"wagtail.contrib.routable_page",
"wagtail.contrib.modeladmin",
"wagtail_modeladmin",
"wagtail.contrib.typed_table_block",
"modelcluster",
"compressor",
"taggit",
"django.contrib.admin",
"django.contrib.auth",
Expand Down Expand Up @@ -129,8 +128,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand All @@ -140,12 +137,18 @@
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"compressor.finders.CompressorFinder",
)

STATICFILES_DIRS = (os.path.join(PROJECT_DIR, "static"),)

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
},
}

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
Expand All @@ -157,11 +160,6 @@
# https://docs.djangoproject.com/en/3.2/ref/settings/#file-upload-permissions
FILE_UPLOAD_PERMISSIONS = 0o664

# Django compressor settings
# http://django-compressor.readthedocs.org/en/latest/settings/

COMPRESS_PRECOMPILERS = (("text/x-scss", "django_libsass.SassCompiler"),)


CACHES = {
"default": {
Expand Down
10 changes: 0 additions & 10 deletions ietf/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
DEBUG = False


# Compress static files offline and minify CSS
# http://django-compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
COMPRESS_OFFLINE = True
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.CSSMinFilter',
]
COMPRESS_CSS_HASHING_METHOD = 'content'


# Configuration from environment variables
# Alternatively, you can set these in a local.py file on the server

Expand Down
Loading

0 comments on commit baca04e

Please sign in to comment.