Permalink
Browse files

fix the nasty level

git-svn-id: https://svn.bluedynamics.eu/svn/module/bda.bfg.tile/trunk@350 f119a143-da5b-4457-81e3-bee00661a780
  • Loading branch information...
1 parent bbb1f54 commit c7a9866fb7ce92f66b67941671e17b1cd2827d9e jensens committed Jan 4, 2010
Showing with 24 additions and 22 deletions.
  1. +3 −0 README.txt
  2. +15 −15 src/bda/bfg/tile/_api.py
  3. +6 −7 src/bda/bfg/tile/_api.txt
View
@@ -18,6 +18,9 @@ Changelog
1.1
---
+- fix the nasty caller_packages level.
+ (jensens, 2010-01-04)
+
- Tiles can now consume Forbidden and return emtpy string, default still
raises exception.
(jensens, 2009-12-31)
View
@@ -1,4 +1,5 @@
import os
+import cgi
from webob import Response
from webob.exc import HTTPFound
from zope.interface import (
@@ -120,11 +121,11 @@ def __init__(self, model, request):
self.model, self.request = model, request
def __call__(self, name):
- try:
- tile = getMultiAdapter((self.model, self.request), ITile, name=name)
- except ComponentLookupError, e:
- return u"Tile with name '%s' not found:<br /><pre>%s</pre>" % \
- (name, e)
+ #try:
+ tile = getMultiAdapter((self.model, self.request), ITile, name=name)
+ #except ComponentLookupError, e:
+ # return u"Tile with name '%s' not found:<br /><pre>%s</pre>" % \
+ # (name, cgi.escape(str(e)))
return tile
def _consume_unauthorized(tile):
@@ -145,7 +146,7 @@ def consumer(context, request):
# Registration
def registerTile(name, path=None, attribute='render',
interface=Interface, _class=Tile,
- permission='view', strict=True):
+ permission='view', strict=True, _level=2):
"""registers a tile.
``name``
@@ -175,11 +176,16 @@ def registerTile(name, path=None, attribute='render',
Wether to raise ``Forbidden`` or not. Defaults to ``True``. If set to
``False`` the exception is consumed and an empty unicode string is
returned.
+
+ ``_level``
+ is a bit special to make doctests pass the magic path-detection.
+ you must never touch it in application code.
"""
if path:
if not (':' in path or os.path.isabs(path)):
- caller = caller_package(level=1)
+ caller = caller_package(_level)
path = '%s:%s' % (caller.__name__, path)
+ #print "register tile %s" % [name, path, interface]
view = _class(path, attribute)
registry = get_current_registry()
if permission is not None:
@@ -197,20 +203,14 @@ class tile(object):
def __init__(self, name, path=None, attribute='render',
interface=Interface, permission='view',
- strict=True, level=2):
+ strict=True, _level=2):
""" see ``registerTile`` for details on the other parameters.
-
- ``level``
- is a bit special to make doctests pass the magic path-detection.
- you must never touch it in application code.
-
-
"""
self.name = name
self.path = path
if path:
if not (':' in path or os.path.isabs(path)):
- caller = caller_package(level)
+ caller = caller_package(_level)
self.path = '%s:%s' % (caller.__name__, path)
self.attribute = attribute
self.interface = interface
View
@@ -29,28 +29,27 @@ The pure Tile itself. Normally you do not create this directly, this is done
due registration, see below.
::
- >>> tile1pt = 'bda.bfg.tile:testdata/tile1.pt'
- >>> mytile = Tile(tile1pt, None)
+ >>> mytile = Tile('bda.bfg.tile:testdata/tile1.pt', None)
>>> mytile(model, request)
u'<span>Tile One</span>'
Register a tile using the prior template testtemplate. When no object is given,
-the default tile is instanciated as above.
+the default tile is instanciated as above. ``_level=1`` is needed for the
+doctest only to reduce the module level.
::
- >>> registerTile('tileone', tile1pt)
+ >>> registerTile('tileone', 'testdata/tile1.pt', _level=1)
Render the already registered tile.
::
>>> TileRenderer(model, request)('tileone')
u'<span>Tile One</span>'
-Now the decorator - level=1 is needed for the doctest only to reduce the module
-level.
+Now the decorator (ignore the ``_level``)
::
- >>> @tile('tiletwo', 'testdata/tile2.pt', level=1)
+ >>> @tile('tiletwo', 'testdata/tile2.pt', _level=1)
... class Tile2(Tile):
... data = u'custom'
>>> TileRenderer(model, request)('tiletwo')

0 comments on commit c7a9866

Please sign in to comment.