Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Redirect to the correct URL if the slug doesn't match.

  • Loading branch information...
commit 5294c6f502d904105a53e5a5c72b9aaafd87c225 1 parent b2ed675
@avidal authored
Showing with 12 additions and 2 deletions.
  1. +12 −2 wotmad/scripts/views.py
View
14 wotmad/scripts/views.py
@@ -29,7 +29,7 @@ def form_valid(self, form):
script.add_version(form.cleaned_data.get('source'))
messages.success(request, "Score!")
- return redirect(script.get_absolute_url())
+ return redirect(script)
class UpdateScript(LoginRequiredMixin, UpdateView):
@@ -92,12 +92,22 @@ def form_valid(self, form):
msg = "Version {0} added. Thanks!"
messages.success(self.request,
msg.format(script.latest_version.version))
- return redirect(script.get_absolute_url())
+ return redirect(script)
class ScriptDetail(DetailView):
model = Script
+ def get(self, *args, **kwargs):
+ script = self.get_object()
+
+ # If the slug in the URL doesn't match the script slug,
+ # then redirect
+ if script.slug != kwargs.get('slug'):
+ return redirect(script, permanent=True)
+
+ return super(ScriptDetail, self).get(*args, **kwargs)
+
class ScriptList(ListView):
model = Script
Please sign in to comment.
Something went wrong with that request. Please try again.