Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2526 (closed defect: migrated)

Opened 9 years ago

Last modified 8 years ago

Non-restful methods and subcontrollers not found in nested RestControllers

Reported by: nils Owned by:
Priority: normal Milestone: __unclassified__
Component: TurboGears Version: 2.0b7
Severity: normal Keywords:
Cc:

Description

When nesting RestControllers, the nested controllers don't dispatch requests to non-restful methods (subcontrollers are dispatched). E.g. using this set of controllers in a project "Foo":

from tg import expose, request
from tg.controllers import TGController, RestController

class MyTGController(TGController):

  @expose('json')
  def index(self, *p, **k):
    return dict(path=request.path, s=repr(self), m='index', p=p, k=k)


class MyNestedRestController(RestController):

  tg = MyTGController()

  @expose('json')
  def get_one(self, id):
    return dict(path=request.path, s=repr(self), m='get_one', id=id)

  @expose('json')
  def nonrestful(self, *p, **k):
    return dict(path=request.path, s=repr(self), m='nonrestful', p=p, k=k)


class MyRestController(RestController):

  nested = MyNestedRestController()

  tg = MyTGController()

  @expose('json')
  def get_one(self, id):
    return dict(path=request.path, s=repr(self), m='get_one', id=id)

  @expose('json')
  def nonrestful(self, *p, **k):
    return dict(path=request.path, s=repr(self), m='nonrestful', p=p, k=k)


class RootController(TGController):

  tg = MyTGController()

  rest = MyRestController()

  @expose('json')
  def index(self, *p, **k):
    return dict(path=request.path, s=repr(self), m='index', p=p, k=k)

Results:

/                    -> {"p": [], "s": "<foo.controllers.root.RootController object at 0x7f122c025090>", "path": "/", "k": {}, "m": "index"}
/rest/tg             -> {"p": [], "s": "<foo.controllers.root.MyTGController object at 0x7f122c015850>", "path": "/rest/tg", "k": {}, "m": "index"}
/rest/nonrestful     -> {"p": [], "s": "<foo.controllers.root.MyRestController object at 0x7f122c015990>", "path": "/rest/nonrestful", "k": {}, "m": "nonrestful"}
/rest/1              -> {"path": "/rest/1", "s": "<foo.controllers.root.MyRestController object at 0x7f122c015990>", "m": "get_one", "id": "1"}
/rest/1/tg           -> {"p": [], "s": "<foo.controllers.root.MyTGController object at 0x7f122c015850>", "path": "/rest/1/tg", "k": {}, "m": "index"}
/rest/1/nonrestful   -> 404

I guess this could be related to ticket #2500.

Change History

comment:1 Changed 9 years ago by nils

NB: This is the TG version currently included in Fedora 14, i.e. Hg rev 1048:0fb969ca9f0f (one before 2.1rc1) with 1046:2660f1d9ac18 backed out to remove kajiji dependency.

comment:2 Changed 8 years ago by pedersen

  • Status changed from new to closed
  • Resolution set to migrated
Note: See TracTickets for help on using tickets.