Skip to content

Commit

Permalink
Upgraded wagtail to 2.9.3, added image rendition caching
Browse files Browse the repository at this point in the history
  • Loading branch information
gsidebo committed Dec 9, 2020
1 parent ffa6379 commit 51fe040
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 31 deletions.
8 changes: 8 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,14 @@
"description": "Employee key for international vouchers",
"required": false
},
"WAGTAIL_CACHE_MAX_ENTRIES": {
"description": "The maximum number of cache entries for Wagtail images",
"required": false
},
"WAGTAIL_CACHE_URL": {
"description": "URL for Wagtail image renditions cache",
"required": false
},
"ZENDESK_HELP_WIDGET_ENABLED": {
"description": "Enabled/disable state for Zendesk web help widget.",
"required": false
Expand Down
5 changes: 4 additions & 1 deletion cms/migrations/0029_setup_course_program_index_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ def unnest_detail_and_delete_index_pages(apps, schema_editor):

class Migration(migrations.Migration):

dependencies = [("cms", "0028_course_program_index_pages")]
dependencies = [
("cms", "0028_course_program_index_pages"),
("wagtailcore", "0043_lock_fields"),
]

operations = [
migrations.RunPython(
Expand Down
20 changes: 10 additions & 10 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,12 @@ def _get_child_page_of_type(self, cls):
child = self.get_children().type(cls).live().first()
return child.specific if child else None

def save(self, *args, **kwargs):
def save(self, clean=True, **kwargs):
"""If featured is True then set False in any existing product page(s)."""
if self.featured:
for child_class in ProductPage.__subclasses__():
child_class.objects.filter(featured=True).update(featured=False)
super().save(*args, **kwargs)
super().save(clean=clean, **kwargs)

@property
def product(self):
Expand Down Expand Up @@ -946,12 +946,12 @@ def can_create_at(cls, parent):
and parent.get_children().type(cls).count() == 0
)

def save(self, *args, **kwargs):
def save(self, clean=True, **kwargs):
# autogenerate a unique slug so we don't hit a ValidationError
if not self.title:
self.title = self.__class__._meta.verbose_name.title()
self.slug = slugify("{}-{}".format(self.get_parent().id, self.title))
super().save(*args, **kwargs)
super().save(clean=clean, **kwargs)

def get_url_parts(self, request=None):
"""
Expand Down Expand Up @@ -1336,11 +1336,11 @@ class FrequentlyAskedQuestionPage(CourseProgramChildPage):

content_panels = [InlinePanel("faqs", label="Frequently Asked Questions")]

def save(self, *args, **kwargs):
def save(self, clean=True, **kwargs):
# autogenerate a unique slug so we don't hit a ValidationError
self.title = "Frequently Asked Questions"
self.slug = slugify("{}-{}".format(self.get_parent().id, self.title))
super().save(*args, **kwargs)
super().save(clean=clean, **kwargs)


class FrequentlyAskedQuestion(Orderable):
Expand Down Expand Up @@ -1434,13 +1434,13 @@ class Meta:
ImageChooserPanel("signature_image"),
]

def save(self, *args, **kwargs):
def save(self, clean=True, **kwargs):
# auto generate a unique slug so we don't hit a ValidationError
if not self.title:
self.title = self.__class__._meta.verbose_name.title() + "-" + self.name

self.slug = slugify("{}-{}".format(self.title, self.id))
super().save(*args, **kwargs)
super().save(clean=clean, **kwargs)

def serve(self, request, *args, **kwargs):
"""
Expand Down Expand Up @@ -1509,7 +1509,7 @@ def __init__(self, *args, **kwargs):
self.certificate = None
super().__init__(*args, **kwargs)

def save(self, *args, **kwargs):
def save(self, clean=True, **kwargs):
# auto generate a unique slug so we don't hit a ValidationError
self.title = (
self.__class__._meta.verbose_name.title()
Expand All @@ -1518,7 +1518,7 @@ def save(self, *args, **kwargs):
)

self.slug = slugify("certificate-{}".format(self.get_parent().id))
Page.save(self, *args, **kwargs)
Page.save(self, clean=clean, **kwargs)

def serve(self, request, *args, **kwargs):
"""
Expand Down
4 changes: 2 additions & 2 deletions cms/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Custom hooks to configure wagtail behavior"""
from wagtail.admin.api.endpoints import PagesAdminAPIEndpoint
from wagtail.api.v2.views import PagesAPIViewSet
from wagtail.core import hooks


Expand All @@ -11,7 +11,7 @@ def sort_pages_alphabetically(
return pages.order_by("title")


class OrderedPagesAPIEndpoint(PagesAdminAPIEndpoint):
class OrderedPagesAPIEndpoint(PagesAPIViewSet):
"""A clone of the default Wagtail admin API that additionally orders all responses by page title alphabetically"""

def filter_queryset(self, queryset):
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ def test_products_viewset_performance(
user_drf_client, coupon_product_ids, django_assert_num_queries
):
""" Test that the ProductViewSet returns the expected number of queries hit. """
with django_assert_num_queries(11):
with django_assert_num_queries(10):
response = user_drf_client.get(
reverse("products_api-detail", kwargs={"pk": coupon_product_ids[0]})
)
Expand Down
34 changes: 26 additions & 8 deletions mitxpro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.contrib.sites.middleware.CurrentSiteMiddleware",
"django_user_agents.middleware.UserAgentMiddleware",
"wagtail.core.middleware.SiteMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
)

Expand Down Expand Up @@ -728,8 +727,6 @@
description="The number of hours to delay automated certificate creation after a course run ends.",
)

# Celery
USE_CELERY = True
REDISCLOUD_URL = get_string(
name="REDISCLOUD_URL", default=None, description="RedisCloud connection url"
)
Expand All @@ -740,6 +737,10 @@
name="REDIS_URL", default=None, description="Redis URL for non-production use"
)

#

# Celery
USE_CELERY = True
CELERY_BROKER_URL = get_string(
name="CELERY_BROKER_URL",
default=_redis_url,
Expand Down Expand Up @@ -924,6 +925,22 @@
HIJACK_LOGOUT_REDIRECT_URL = "/admin/users/user"
HIJACK_REGISTER_ADMIN = False

# Wagtail
WAGTAIL_CACHE_URL = get_string(
name="WAGTAIL_CACHE_URL",
default=_redis_url,
description="URL for Wagtail image renditions cache",
)
WAGTAIL_CACHE_MAX_ENTRIES = get_int(
name="WAGTAIL_CACHE_MAX_ENTRIES",
default=200,
description="The maximum number of cache entries for Wagtail images",
)
WAGTAILEMBEDS_FINDERS = [
{"class": "cms.embeds.YouTubeEmbedFinder"},
{"class": "wagtail.embeds.finders.oembed"},
]

# django cache back-ends
CACHES = {
"default": {
Expand All @@ -935,6 +952,12 @@
"LOCATION": CELERY_BROKER_URL,
"OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"},
},
"renditions": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": WAGTAIL_CACHE_URL,
"TIMEOUT": 31_536_000, # 1 year
"OPTIONS": {"MAX_ENTRIES": WAGTAIL_CACHE_MAX_ENTRIES},
},
}

AUTHENTICATION_BACKENDS = (
Expand Down Expand Up @@ -1187,11 +1210,6 @@
name="HUBSPOT_ID_PREFIX", default="xpronew", description="Hub spot id prefix."
)

WAGTAILEMBEDS_FINDERS = [
{"class": "cms.embeds.YouTubeEmbedFinder"},
{"class": "wagtail.embeds.finders.oembed"},
]

# Sheets settings
DRIVE_SERVICE_ACCOUNT_CREDS = get_string(
name="DRIVE_SERVICE_ACCOUNT_CREDS",
Expand Down
6 changes: 3 additions & 3 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
beautifulsoup4==4.6.0
beautifulsoup4==4.8.2
celery==4.3.0
celery-redbeat==0.13.0
boto3==1.9.188
Expand Down Expand Up @@ -40,6 +40,6 @@ ua-parser==0.8.0
user-agents==2.0
user-util==0.1.5
uwsgi
wagtail==2.7.4
wagtail-metadata==2.0.1
wagtail==2.9.3
wagtail-metadata==3.3.0
zeep==3.4.0
15 changes: 9 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile
# pip-compile requirements.in
#
amqp==2.5.0 # via kombu
appdirs==1.4.3 # via zeep
attrs==19.1.0 # via zeep
backcall==0.1.0 # via ipython
beautifulsoup4==4.6.0 # via -r requirements.in, wagtail
beautifulsoup4==4.8.2 # via -r requirements.in, wagtail
billiard==3.6.0.0 # via celery
boto3==1.9.188 # via -r requirements.in
botocore==1.12.188 # via boto3, s3transfer
Expand Down Expand Up @@ -62,6 +62,7 @@ isodate==0.6.0 # via zeep
jedi==0.14.1 # via ipython
jmespath==0.9.4 # via boto3, botocore
kombu==4.6.3 # via celery, django-server-status
l18n==2020.6.1 # via wagtail
lxml==4.3.4 # via zeep
mitol-django-common==0.3.0 # via -r requirements.in
newrelic==4.20.1.121 # via -r requirements.in
Expand All @@ -86,17 +87,18 @@ pynacl==1.3.0 # via -r requirements.in
pyopenssl==17.5.0 # via django-server-status
python-dateutil==2.5.3 # via botocore, celery-redbeat, edx-api-client
python3-openid==3.1.0 # via social-auth-core
pytz==2019.1 # via celery, django, django-modelcluster, wagtail, zeep
pytz==2020.4 # via celery, django, django-modelcluster, l18n, zeep
redis==3.2.1 # via -r requirements.in, celery-redbeat, django-redis, django-server-status
requests-oauthlib==1.2.0 # via google-auth-oauthlib, social-auth-core
requests-toolbelt==0.9.1 # via zeep
requests==2.22.0 # via -r requirements.in, django-anymail, django-oauth-toolkit, edx-api-client, mitol-django-common, requests-oauthlib, requests-toolbelt, social-auth-core, wagtail, zeep
rsa==4.0 # via google-auth
s3transfer==0.2.1 # via boto3
sentry-sdk==0.10.1 # via -r requirements.in
six==1.12.0 # via cryptography, django-anymail, django-compat, django-server-status, edx-api-client, google-api-python-client, google-auth, html5lib, isodate, prompt-toolkit, pynacl, pyopenssl, python-dateutil, social-auth-app-django, social-auth-core, tenacity, traitlets, wagtail, zeep
six==1.12.0 # via cryptography, django-anymail, django-compat, django-server-status, edx-api-client, google-api-python-client, google-auth, html5lib, isodate, l18n, prompt-toolkit, pynacl, pyopenssl, python-dateutil, social-auth-app-django, social-auth-core, tenacity, traitlets, zeep
social-auth-app-django==3.1.0 # via -r requirements.in
social-auth-core==3.2.0 # via social-auth-app-django
soupsieve==2.0.1 # via beautifulsoup4
sqlparse==0.3.0 # via django
tenacity==6.1.0 # via celery-redbeat
traitlets==4.3.2 # via ipython
Expand All @@ -109,11 +111,12 @@ user-agents==2.0 # via -r requirements.in, django-user-agents
user-util==0.1.5 # via -r requirements.in
uwsgi==2.0.18 # via -r requirements.in
vine==1.3.0 # via amqp, celery
wagtail-metadata==2.0.1 # via -r requirements.in
wagtail==2.7.4 # via -r requirements.in, wagtail-metadata
wagtail-metadata==3.3.0 # via -r requirements.in
wagtail==2.9.3 # via -r requirements.in, wagtail-metadata
wcwidth==0.1.7 # via prompt-toolkit
webencodings==0.5.1 # via html5lib
willow==1.3 # via wagtail
xlsxwriter==1.3.7 # via wagtail
zeep==3.4.0 # via -r requirements.in

# The following packages are considered to be unsafe in a requirements file:
Expand Down

0 comments on commit 51fe040

Please sign in to comment.