Created
January 3, 2017 07:18
-
-
Save mazz/31e5f0499e7358e42214a30a606c8741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from websauna.system.http import Request | |
from websauna.utils.slug import slug_to_uuid | |
from websauna.system.core.route import simple_route | |
from pyramid.request import Response | |
from pyramid.httpexceptions import HTTPNotFound | |
from . import models | |
@simple_route("/questions/{question_uuid}", route_name="detail", renderer="myapp/detail.html") | |
def detail(request): | |
# Convert base64 encoded UUID string from request path to Python UUID object | |
question_uuid = slug_to_uuid(request.matchdict["question_uuid"]) | |
question = request.dbsession.query(models.Question).filter_by(uuid=question_uuid).one_or_none() | |
if not question: | |
raise HTTPNotFound() | |
return locals() | |
@simple_route("/", route_name="home", renderer="myapp/home.html") | |
def home(request: Request): | |
"""Render the site homepage.""" | |
latest_question_list = request.dbsession.query(models.Question).order_by(models.Question.published_at.desc()).all()[:5] | |
return locals() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment