Skip to content

Commit 64b737e

Browse files
authored
fix: Ensure that Box content is rendered after update (#2638)
This resolves the underlying problem from #2631. When updated via Django's [`update_or_create`](https://docs.djangoproject.com/en/4.2/ref/models/querysets/#update-or-create), the new `content` for a `Box` is not rendered by django-markupfield's [`pre_save`](https://github.com/jamesturk/django-markupfield/blob/2.0.1/markupfield/fields.py#L163-L179) method unless `save()` is called. This is due to the fact that [`update`](https://docs.djangoproject.com/en/4.2/ref/models/querysets/#django.db.models.query.QuerySet.update) bypasses calls to `save`, `pre_save`, and `post_save`, from the docs: > Finally, realize that update() does an update at the SQL level and, thus, does not call any save() methods on your models, nor does it emit the pre_save or post_save signals (which are a consequence of calling Model.save())
1 parent ab7779f commit 64b737e

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

blogs/parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ def update_blog_supernav():
4848
pass
4949
else:
5050
rendered_box = _render_blog_supernav(latest_entry)
51-
box, _ = Box.objects.update_or_create(
51+
box, created = Box.objects.update_or_create(
5252
label='supernav-python-blog',
5353
defaults={
5454
'content': rendered_box,
5555
'content_markup_type': 'html',
5656
}
5757
)
58+
if not created:
59+
box.save()

downloads/models.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,15 @@ def update_supernav():
179179
'last_updated': timezone.now(),
180180
})
181181

182-
box, _ = Box.objects.update_or_create(
182+
box, created = Box.objects.update_or_create(
183183
label='supernav-python-downloads',
184184
defaults={
185185
'content': content,
186186
'content_markup_type': 'html',
187187
}
188188
)
189+
if not created:
190+
box.save()
189191

190192

191193
def update_download_landing_sources_box():
@@ -208,13 +210,15 @@ def update_download_landing_sources_box():
208210
return
209211

210212
source_content = render_to_string('downloads/download-sources-box.html', context)
211-
source_box, _ = Box.objects.update_or_create(
213+
source_box, created = Box.objects.update_or_create(
212214
label='download-sources',
213215
defaults={
214216
'content': source_content,
215217
'content_markup_type': 'html',
216218
}
217219
)
220+
if not created:
221+
source_box.save()
218222

219223

220224
def update_homepage_download_box():
@@ -234,13 +238,15 @@ def update_homepage_download_box():
234238

235239
content = render_to_string('downloads/homepage-downloads-box.html', context)
236240

237-
box, _ = Box.objects.update_or_create(
241+
box, created = Box.objects.update_or_create(
238242
label='homepage-downloads',
239243
defaults={
240244
'content': content,
241245
'content_markup_type': 'html',
242246
}
243247
)
248+
if not created:
249+
box.save()
244250

245251

246252
@receiver(post_save, sender=Release)

successstories/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ def update_successstories_supernav(sender, instance, created, **kwargs):
102102
'story': instance,
103103
})
104104

105-
box, _ = Box.objects.update_or_create(
105+
box, created = Box.objects.update_or_create(
106106
label='supernav-python-success-stories',
107107
defaults={
108108
'content': content,
109109
'content_markup_type': 'html',
110110
}
111111
)
112+
if not created:
113+
box.save()
112114

113115
# Purge Fastly cache
114116
purge_url('/box/supernav-python-success-stories/')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy