Commits

Rick Copeland committed 62c3c2c

Everything required for @lookup and @default decorators EXCEPT for the actual dispatch logic

  • Participants
  • Parent commits ecdc7e3

Comments (0)

Files changed (2)

File tg/decorators.py

         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=[],
 
     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]:
         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.
         redirect(request.url+'/')
     return func(*args, **kwargs)
 
-
 #{ Authorization decorators
 
 

File tg/tests/test_tg_controller_dispatch.py

 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
     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):
     error_controller = RemoteErrorHandler()
     
     lookup = LoookupController()
+    deco_lookup = DecoLookupController()
+    deco_default = DecoDefaultController()
     lookup_with_args = LoookupControllerWithArgs()
     
     @expose()
         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