/shabti/templates/auth/+package+/lib/helpers.py_tmpl
Unknown | 49 lines | 39 code | 10 blank | 0 comment | 0 complexity | 18d1ba4ca4d03cd9c1ceecbd50dcf0a2 MD5 | raw file
1# -*- coding: utf-8 -*-
2"""Helper functions
3
4Consists of functions to typically be used within templates, but also
5available to Controllers. This module is available to both as 'h'.
6"""
7import logging
8from pylons import url
9from pylons.controllers.util import redirect
10
11# Scaffolding helper imports
12from webhelpers.html.tags import *
13from webhelpers.html import literal
14from webhelpers.pylonslib import Flash as _Flash
15# End of.
16flash = _Flash()
17success_flash = _Flash('success')
18failure_flash = _Flash('failure')
19
20log = logging.getLogger(__name__)
21
22def get_object_or_404(model, **kw):
23 from pylons.controllers.util import abort
24 """
25 Returns object, or raises a 404 Not Found is object is not in db.
26 Uses elixir-specific `get_by()` convenience function (see elixir source:
27 http://elixir.ematia.de/trac/browser/elixir/trunk/elixir/entity.py#L1082)
28 Example: user = get_object_or_404(model.User, id = 1)
29 """
30 obj = model.get_by(**kw)
31 if obj is None:
32 abort(404)
33 return obj
34
35# Auth helpers
36
37from {{package}}.lib.auth import permissions
38from {{package}}.lib.auth import get_user
39
40def signed_in():
41 return permissions.SignedIn().check()
42
43def in_group(group_name):
44 return permissions.InGroup(group_name).check()
45
46def has_permission(perm):
47 return permissions.HasPermission(perm).check()
48
49# --- Overwritten by Shabti auth template