Searching for one tag works. Two tags acts like or and returns multiple copies.
[zzz-floof.git] / floof / lib / helpers.py
1 # -*- coding: utf-8 -*-
2 """Helper functions
3
4 Consists of functions to typically be used within templates, but also
5 available to Controllers. This module is available to both as 'h'.
6 """
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
12 # Scaffolding helper imports
13 from webhelpers.html.tags import *
14 from webhelpers.html import literal
15 from webhelpers.pylonslib import Flash
16 import sqlalchemy.types as types
17 flash = Flash()
18 # End of.
19
20 def get_object_or_404(model, **kw):
21 from pylons.controllers.util import abort
22 """
23 Returns object, or raises a 404 Not Found is object is not in db.
24 Uses elixir-specific `get_by()` convenience function (see elixir source:
25 http://elixir.ematia.de/trac/browser/elixir/trunk/elixir/entity.py#L1082)
26 Example: user = get_object_or_404(model.User, id = 1)
27 """
28 obj = model.get_by(**kw)
29 if obj is None:
30 abort(404)
31 return obj
32