Skip to content

Commit

Permalink
Merge pull request #242 from kyrias/invalidate-profile-update
Browse files Browse the repository at this point in the history
devel/views: Invalidate template fragment cache on profile update
  • Loading branch information
jelly authored Oct 4, 2019
2 parents 184bf56 + 2685a08 commit 767feb1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions devel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
user_passes_test)
from django.contrib.auth.models import Group, User
from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.db import transaction
from django.db.models import Count, Max
from django.http import Http404, HttpResponseRedirect
Expand Down Expand Up @@ -171,6 +173,12 @@ def change_profile(request):
with transaction.atomic():
request.user.save()
profile_form.save()

# Invalidate userlist.html template cache fragment.
for group in request.user.groups.all():
key = make_template_fragment_key('dev-tu-profiles', [group.name])
cache.delete(key)

return HttpResponseRedirect('/devel/')
else:
form = ProfileForm(initial={'email': request.user.email})
Expand Down

0 comments on commit 767feb1

Please sign in to comment.