]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/readers.py
Redirect to the correct question if there is no match in the id but there is one...
[osqa.git] / forum / views / readers.py
index b260343d19e97e6b79e51b13f73c27a1cbb59263..5f583444e2d80e44505df9413cd559ddbe1b4943 100644 (file)
@@ -56,7 +56,7 @@ def _get_tags_cache_json():#service routine used by views requiring tag list in
 
 @decorators.render('index.html')
 def index(request):
-    return question_list(request, Question.objects.all(), sort='latest', base_path=reverse('questions'))
+    return question_list(request, Question.objects.all(), sort='active', base_path=reverse('questions'))
 
 @decorators.render('questions.html', 'unanswered')
 def unanswered(request):
@@ -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))