Skip to content

Commit

Permalink
Merge pull request #601 from CTPUG/inheritable-talkview
Browse files Browse the repository at this point in the history
Make it easier to inherit from TalkView
  • Loading branch information
stefanor committed Jun 13, 2021
2 parents 18b3d94 + 92a14c3 commit 549371f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions wafer/talks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ def get_object(self, *args, **kwargs):
raise PermissionDenied
return object_

def canonical_url(self):
'''Return the canonical URL for this view'''
return self.object.get_absolute_url()

def render_to_response(self, *args, **kwargs):
'''Canonicalize the URL if the slug changed'''
if self.request.path != self.object.get_absolute_url():
return HttpResponseRedirect(self.object.get_absolute_url())
canonical_url = self.canonical_url()
if self.request.path != canonical_url:
return HttpResponseRedirect(canonical_url)
return super().render_to_response(*args, **kwargs)

def get_context_data(self, **kwargs):
Expand Down

0 comments on commit 549371f

Please sign in to comment.