Skip to content

Commit

Permalink
merged in ricks changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
percious committed Sep 29, 2009
2 parents 26bdc59 + 388325f commit 624c53f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
16 changes: 14 additions & 2 deletions tg/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(self, controller):
self.render_custom_format = None
self.validation = None
self.error_handler = None
self.is_default_controller = False
self.is_lookup_controller = False
self.hooks = dict(before_validate=[],
before_call=[],
before_render=[],
Expand All @@ -53,7 +55,7 @@ def get_decoration(cls, func):

def exposed(self):
return bool(self.engines)
expose = property(exposed)
exposed = property(exposed)

def run_hooks(self, hook, *l, **kw):
for func in self.hooks[hook]:
Expand Down Expand Up @@ -371,6 +373,17 @@ def __call__(self, func):
deco.validation = self
return func

def default(func):
'''Registers a method as the "default" controller method'''
deco = Decoration.get_decoration(func)
deco.is_default_controller = True
return func

def lookup(func):
'''Registers a method as the "lookup" controller method'''
deco = Decoration.get_decoration(func)
deco.is_lookup_controller = True
return func

class paginate(object):
"""Paginate a given collection.
Expand Down Expand Up @@ -537,7 +550,6 @@ def sample(self, *args):
redirect(request.url+'/')
return func(*args, **kwargs)


#{ Authorization decorators


Expand Down
36 changes: 0 additions & 36 deletions tg/test_stack/rendering/test_custom_format.py

This file was deleted.

26 changes: 25 additions & 1 deletion tg/tests/test_tg_controller_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tg, pylons
from tg.controllers import TGController, CUSTOM_CONTENT_TYPE, \
WSGIAppController, RestController
from tg.decorators import expose, validate, override_template
from tg.decorators import expose, validate, override_template, lookup, default
from routes import Mapper
from routes.middleware import RoutesMiddleware
from formencode import validators
Expand Down Expand Up @@ -127,6 +127,18 @@ class LoookupController(TGController):
def lookup(self, a, *args):
return LookupHelper(a), args

class DecoDefaultController(TGController):

@default
def __0(self, *args):
return ("recieved the following args (from the url): %s" %list(args))

class DecoLookupController(TGController):

@lookup
def __0(self, a, *args):
return LookupHelper(a), args

class RemoteErrorHandler(TGController):
@expose()
def errors_here(self, *args, **kw):
Expand All @@ -140,6 +152,8 @@ class BasicTGController(TGController):
error_controller = RemoteErrorHandler()

lookup = LoookupController()
deco_lookup = DecoLookupController()
deco_default = DecoDefaultController()
lookup_with_args = LoookupControllerWithArgs()

@expose()
Expand Down Expand Up @@ -293,6 +307,16 @@ def test_lookup_with_args(self):
msg = 'got_here'
assert r.body==msg, r

def test_new_lookup(self):
r = self.app.get('/deco_lookup/EYE')
msg = 'EYE'
assert msg in r, r

def test_new_default(self):
r = self.app.get('/deco_default/EYE')
msg = 'EYE'
assert msg in r, r

def test_validated_int(self):
r = self.app.get('/validated_int/1')
assert '{"response": 1}' in r, r
Expand Down

0 comments on commit 624c53f

Please sign in to comment.