1 # -*- coding: utf-8 -*-
4 Consists of functions to typically be used within templates, but also
5 available to Controllers. This module is available to both as 'h'.
7 # Import helpers as desired, or define your own, ie:
8 # from webhelpers.html.tags import checkbox, password
9 from webhelpers
import *
10 from routes
import url_for
, redirect_to
11 from pylons
import url
13 # Scaffolding helper imports
14 from webhelpers
.html
.tags
import *
15 from webhelpers
.html
import literal
16 from webhelpers
.pylonslib
import Flash
17 import sqlalchemy
.types
as types
21 def get_object_or_404(model
, **kw
):
22 from pylons
.controllers
.util
import abort
24 Returns object, or raises a 404 Not Found is object is not in db.
25 Uses elixir-specific `get_by()` convenience function (see elixir source:
26 http://elixir.ematia.de/trac/browser/elixir/trunk/elixir/entity.py#L1082)
27 Example: user = get_object_or_404(model.User, id = 1)
29 obj
= model
.get_by(**kw
)
34 def get_comment_owner_url(**route
):
35 """Given a view route, returns the owner_url route parameter for generating
38 # url() returns URLs beginning with a slash. We just need to strip it.
39 return url(**route
)[1:]