]> git.openstreetmap.org Git - osqa.git/commitdiff
Redirect to the correct question if there is no match in the id but there is one...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 17 Apr 2010 15:43:31 +0000 (15:43 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 17 Apr 2010 15:43:31 +0000 (15:43 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@47 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/views/readers.py

index afe24bbb19c6bdd87bb75a55f819eae3418c1934..5f583444e2d80e44505df9413cd559ddbe1b4943 100644 (file)
@@ -198,10 +198,31 @@ def update_question_view_times(request, question):
 
     request.session['last_seen_in_question'][question.id] = datetime.datetime.now()
 
+def match_question_slug(slug):
+    slug_words = slug.split('-')
+    qs = Question.objects.filter(title__istartswith=slug_words[0])
+
+    for q in qs:
+        if slug == urlquote(slugify(q.title)):
+            return q
+
+    return None
+
 def question(request, id, slug):
-    question = get_object_or_404(Question, id=id)
+    try:
+        question = Question.objects.get(id=id)
+    except:
+        question = match_question_slug(slug)
+        if question is not None:
+            return HttpResponseRedirect(question.get_absolute_url())
+        else:
+            raise Http404()
 
     if slug != urlquote(slugify(question.title)):
+        match = match_question_slug(slug)
+        if match is not None:
+            return HttpResponseRedirect(match.get_absolute_url())    
+
         return HttpResponseRedirect(question.get_absolute_url())
 
     page = int(request.GET.get('page', 1))