From: hernani Date: Thu, 8 Jul 2010 14:19:44 +0000 (+0000) Subject: Relaxes the question url a bit, but issues redirects to the correct url. X-Git-Tag: live~632 X-Git-Url: https://git.openstreetmap.org/osqa.git/commitdiff_plain/914442cbeb4f84cb0a54c2b99ee2562c51ec6b2e Relaxes the question url a bit, but issues redirects to the correct url. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@502 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/urls.py b/forum/urls.py index 92c0d6b..5f3fbc5 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -93,6 +93,7 @@ urlpatterns += patterns('', url(r'^%s(?P\d+)/(?P[\w-]*)$' % _('question/'), 'django.views.generic.simple.redirect_to', {'url': '/questions/%(id)s/%(slug)s'}), + url(r'^%s(?P\d+)/?$' % _('questions/'), app.readers.question, name='question'), url(r'^%s(?P\d+)/(?P[\w-]*)$' % _('questions/'), app.readers.question, name='question'), url(r'^%s(?P\d+)/(?P[\w-]*)/(?P\d+)$' % _('questions/'), app.readers.question), diff --git a/forum/views/readers.py b/forum/views/readers.py index 69ef208..da881d7 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -280,7 +280,7 @@ def answer_redirect(request, answer): answer.question.get_absolute_url(), _('page'), page, answer.id)) @decorators.render("question.html", 'questions') -def question(request, id, slug, answer=None): +def question(request, id, slug=None, answer=None): try: question = Question.objects.get(id=id) except: @@ -305,6 +305,9 @@ def question(request, id, slug, answer=None): return answer_redirect(request, answer) + if (not slug) or (slug != urlquote(slugify(question.title))): + return HttpResponsePermanentRedirect(question.get_absolute_url()) + if request.POST: answer_form = AnswerForm(question, request.POST) else: