Skip to content

Commit 2685a08

Browse files
committed
devel/views: Invalidate template fragment cache on profile update
Closes #166. Signed-off-by: Johannes Löthberg <[email protected]>
1 parent 184bf56 commit 2685a08

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

devel/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
user_passes_test)
1010
from django.contrib.auth.models import Group, User
1111
from django.contrib.contenttypes.models import ContentType
12+
from django.core.cache import cache
13+
from django.core.cache.utils import make_template_fragment_key
1214
from django.db import transaction
1315
from django.db.models import Count, Max
1416
from django.http import Http404, HttpResponseRedirect
@@ -171,6 +173,12 @@ def change_profile(request):
171173
with transaction.atomic():
172174
request.user.save()
173175
profile_form.save()
176+
177+
# Invalidate userlist.html template cache fragment.
178+
for group in request.user.groups.all():
179+
key = make_template_fragment_key('dev-tu-profiles', [group.name])
180+
cache.delete(key)
181+
174182
return HttpResponseRedirect('/devel/')
175183
else:
176184
form = ProfileForm(initial={'email': request.user.email})

0 commit comments

Comments
 (0)