1
0
mirror of https://github.com/djohnlewis/stackdump synced 2025-04-04 16:53:27 +00:00

Added an alias for questions for StackExchange style URLs.

This means site_key/questions/question_id is redirected to site_key/question_id.
This commit is contained in:
Samuel Lai 2012-08-18 20:23:14 +10:00
parent 5fc56e4329
commit e776e95d84

@ -15,7 +15,7 @@ except ImportError:
# For Python >= 2.6 # For Python >= 2.6
import json import json
from bottle import get, run, static_file, debug, request, error, HTTPError from bottle import get, run, static_file, debug, request, error, HTTPError, redirect
from jinja2 import Environment, PackageLoader from jinja2 import Environment, PackageLoader
from sqlobject import sqlhub, connectionForURI, AND, OR, IN, SQLObjectNotFound from sqlobject import sqlhub, connectionForURI, AND, OR, IN, SQLObjectNotFound
from sqlobject.dberrors import OperationalError from sqlobject.dberrors import OperationalError
@ -381,6 +381,14 @@ def view_question(site_key, question_id):
return render_template('question.html', context) return render_template('question.html', context)
@get('/:site_key#[\w\.]+#/questions/:question_id#\d+#')
def view_question_redirect(site_key, question_id):
'''
Redirects users from the long-form, proper URLs to the shorter one used
by Stackdump.
'''
redirect('%s%s/%s' % (settings['APP_URL_ROOT'], site_key, question_id))
# END WEB REQUEST METHODS # END WEB REQUEST METHODS