X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/c33e4ebdf5f88e91946e0f643ef63e3394ea5dfc..47bc0543a1d3f25ec90311883b4e28186a3ddd7e:/forum/views/readers.py diff --git a/forum/views/readers.py b/forum/views/readers.py index afe24bb..5f58344 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -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))