RestController

17 views
Skip to first unread message

AF

unread,
Nov 23, 2009, 6:10:55 PM11/23/09
to TurboGears
Hello,

A few questions:

1) Does RestController support relationships? [
http://microformats.org/wiki/rest/urls#Follow_a_Relationship ]

2) What is the relationship between "post_delete", "get_delete", and
"delete"? I am not sure I understand the example urls in the docs.
What does "GET /movies/delete" even mean? [
http://turbogears.org/2.1/docs/modules/tgcontroller.html#tg.controllers.RestController
]

3) Where would I look if I wanted to examine the source code for
RestController?

Thank you,
AF

Mark Ramm

unread,
Nov 23, 2009, 7:38:16 PM11/23/09
to turbo...@googlegroups.com
Rest Controller is just a placeholder, to understand how the dispatch
happens, you'll need to look at the dispatch code itself.

Are you using 2.0.x or 2.1 either way it's in tg.controllers, but in
2.1 it's isolated out into a separate module...

--Mark Ramm
> --
>
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=.
>
>
>



--
Mark Ramm-Christensen
email: mark at compoundthinking dot com
blog: www.compoundthinking.com/blog

AF

unread,
Nov 24, 2009, 11:05:15 AM11/24/09
to TurboGears


On Nov 23, 7:38 pm, Mark Ramm <mark.mchristen...@gmail.com> wrote:
> Rest Controller is just a placeholder, to understand how the dispatch
> happens, you'll need to look at the dispatch code itself.
>
> Are you using 2.0.x or 2.1 either way it's in tg.controllers, but in
> 2.1 it's isolated out into a separate module...
>


Thanks Mark.

From looking at 2.1's tg.controllers, it seems that RestController
extends DecoratedController, but where is the actual routing code I
should inspect? Is it in TG or Pylons?

Thank you,
AF


Diez B. Roggisch

unread,
Nov 24, 2009, 11:31:47 AM11/24/09
to turbo...@googlegroups.com
tg.controllers.

Diez

AF

unread,
Nov 24, 2009, 1:01:27 PM11/24/09
to TurboGears
Diez,

I am already looking at tg.controllers... but I am not familiar
enough with TG's architecture to make heads for tails out of it.

Can you point me to the section of code that is doing the routing for
RestController? It certainly is not in RestController itself, since
its only a few lines of code.

thanks

Mark Ramm

unread,
Nov 24, 2009, 1:35:46 PM11/24/09
to turbo...@googlegroups.com
In 2.0 look at the class ObjectDispatcher(Dispatcher), in dispatcher.py

The root controller is always an ObjectDispatcher and it's what starts
the dispatch.
> --
>
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.

AF

unread,
Nov 24, 2009, 2:11:06 PM11/24/09
to TurboGears


On Nov 24, 1:35 pm, Mark Ramm <mark.mchristen...@gmail.com> wrote:
> In 2.0 look at the class ObjectDispatcher(Dispatcher), in dispatcher.py
>
> The root controller is always an ObjectDispatcher and it's what starts
> the dispatch.
>
>


Ok, will do this a bit later today. I am actually using 2.1 at the
moment... has the location changed?

Mark Ramm

unread,
Nov 24, 2009, 2:24:27 PM11/24/09
to turbo...@googlegroups.com
Oops, I meant 2.1. IN 2.0 it's in the one controllers file.

--Mark Ramm

AF

unread,
Nov 24, 2009, 2:54:34 PM11/24/09
to TurboGears


> > On Nov 24, 1:35 pm, Mark Ramm <mark.mchristen...@gmail.com> wrote:
> >> In 2.0 look at the class ObjectDispatcher(Dispatcher), in dispatcher.py
>
> >> The root controller is always an ObjectDispatcher and it's what starts
> >> the dispatch.
>
> > Ok, will do this a bit later today.  I am actually using 2.1 at the
> > moment...  has the location changed?
>
> Oops, I meant 2.1. IN 2.0 it's in the one controllers file.
>

Quick question:

Where do I find the 2.1 code? :)

The code at http://trac.turbogears.org/browser/trunk/tg does not seem
to have a dispatcher.py file, nor does that trac seem to know about
any 2.1 branch.


Lee McFadden

unread,
Nov 24, 2009, 3:19:09 PM11/24/09
to turbo...@googlegroups.com
On Tue, Nov 24, 2009 at 11:54 AM, AF <allen....@yahoo.com> wrote:
>
> Where do I find the 2.1 code?  :)
>
> The code at http://trac.turbogears.org/browser/trunk/tg does not seem
> to have a dispatcher.py file, nor does that trac seem to know about
> any 2.1 branch.
>

TG 2.x has been moved to mercurial, hosted at bitbucket:

http://hg.turbogears.org/tg-dev/ is the trunk for 2.1,
http://hg.turbogears.org/tg-2_0/ is the 2.0 branch.

--
Lee McFadden

blog: http://www.splee.co.uk
twitter: http://twitter.com/splee

AF

unread,
Nov 24, 2009, 4:21:06 PM11/24/09
to TurboGears
Thanks Lee!

Will take a look later.



On Nov 24, 3:19 pm, Lee McFadden <splee...@gmail.com> wrote:
> On Tue, Nov 24, 2009 at 11:54 AM, AF <allen.fow...@yahoo.com> wrote:
>
> > Where do I find the 2.1 code?  :)
>
> > The code athttp://trac.turbogears.org/browser/trunk/tgdoes not seem
> > to have a dispatcher.py file, nor does that trac seem to know about
> > any 2.1 branch.
>
> TG 2.x has been moved to mercurial, hosted at bitbucket:
>
> http://hg.turbogears.org/tg-dev/is the trunk for 2.1,http://hg.turbogears.org/tg-2_0/is the 2.0 branch.

AF

unread,
Nov 25, 2009, 1:12:23 AM11/25/09
to TurboGears
Still trying to grock the TG dispatch code, but I do have a quick
question...

Is there an error in the way 2.1 RestController supports invoking
custom actions?

[ See: http://microformats.org/wiki/rest/urls#Invoke_Custom_Actions ]

Assuming a method "promote(self, id)" defined in People
(RestController):

1) Calling "GET /people/1/promote" yields a 404.
2) Calling "GET /people/promote/1" works fine.

I would have expected #1 to work, and #2 to fail with "too many args"
to get_one().

As a work around, I've defined "get_one(id, action=None)", and routed
from there.



AF

unread,
Nov 25, 2009, 6:26:11 PM11/25/09
to TurboGears
> Assuming a method "myaction(self, id)" under People(RestController):
>
> 1) Calling "GET /people/1/myaction" yields a 404.
> 2) Calling "GET /people/myaction/1" calls myaction(self,1)
>

Can someone more familiar with the code confirm if the above behaviour
is correct or not?

(I would assume not. Based on http://microformats.org/wiki/rest/urls#Invoke_Custom_Actions
)

Thank you,
:)

AF

unread,
Nov 30, 2009, 2:15:05 AM11/30/09
to TurboGears

> Assuming a method "myaction(self, id)" under People(RestController):
>
> 1) Calling "GET /people/1/myaction" yields a 404.
> 2) Calling "GET /people/myaction/1" calls myaction(self,1)
>
> Can someone more familiar with the code confirm if the above behaviour
> is correct or not?
>
> Based on my understanding of:
> http://microformats.org/wiki/rest/urls#Invoke_Custom_Actions
> The above is not correct. But, I am not sure.
>

Anyone?

Wesley Dyk

unread,
Nov 30, 2009, 2:24:21 PM11/30/09
to turbo...@googlegroups.com
--

You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbo...@googlegroups.com.
To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.


This is a convenience of which neither implementation is RESTful.  The way RESTController is designed, your get_one is never called.  The dispatch found your myaction method in the People class, so it calls it with the argument.  There is a Movie/MovieDirector example in
http://turbogears.org/2.0/docs/main/RestControllers.html
that shows how to get the URLs to work according to #1.  Using the promote example, you would want to create a Promotion RESTController.  This way you can give a People object a Promotion by sending the state to the post method of that object and it would follow the RESTful design guidelines of not putting verbs in your URLs.  Another, perhaps more representative way of accomplishing this would be to use a JobTitle RESTController rather than a Promotion controller.  Giving someone a promotion would just entail posting a jobtitle/<job title id> to a particular people/<people id>.

Wes

AF

unread,
Dec 1, 2009, 4:55:06 PM12/1/09
to TurboGears


On Nov 30, 2:24 pm, Wesley Dyk <aus...@gmail.com> wrote:
> On Mon, Nov 30, 2009 at 12:15 AM, AF <allen.fow...@yahoo.com> wrote:
>
> > > Assuming a method "myaction(self, id)" under People(RestController):
>
> > > 1) Calling "GET /people/1/myaction" yields a 404.
> > > 2) Calling "GET /people/myaction/1" calls myaction(self,1)
>
> > > Can someone more familiar with the code confirm if the above behaviour
> > > is correct or not?
>
> > > Based on my understanding of:
> > >http://microformats.org/wiki/rest/urls#Invoke_Custom_Actions
> > > The above is not correct.  But, I am not sure.
>
> > Anyone?
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "TurboGears" group.
> > To post to this group, send email to turbo...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > turbogears+...@googlegroups.com<turbogears%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/turbogears?hl=en.
>
> > This is a convenience of which neither implementation is RESTful.  The way
>
> RESTController is designed, your get_one is never called.  The dispatch
> found your myaction method in the People class, so it calls it with the
> argument.  There is a Movie/MovieDirector example inhttp://turbogears.org/2.0/docs/main/RestControllers.html
> that shows how to get the URLs to work according to #1.  Using the promote
> example, you would want to create a Promotion RESTController.  This way you
> can give a People object a Promotion by sending the state to the post method
> of that object and it would follow the RESTful design guidelines of not
> putting verbs in your URLs.  Another, perhaps more representative way of
> accomplishing this would be to use a JobTitle RESTController rather than a
> Promotion controller.  Giving someone a promotion would just entail posting
> a jobtitle/<job title id> to a particular people/<people id>.
>
>

Hi Wes,

Thanks for the help. Can you point me to the docs you are referring
to that will get example #1 to work?

-- AF

Wesley Dyk

unread,
Dec 1, 2009, 6:26:43 PM12/1/09
to turbo...@googlegroups.com
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
>
>



AF,
Look for the Nesting Resources with REST Controllers example in the
page at this address:

http://turbogears.org/2.0/docs/main/RestControllers.html

The example doesn't show everything, but if you put the
MovieController together with the second MovieDirectorController
listing, you should be able to make it work.  I tried this example by
checking out the source and was able to make it work with the changes
described in the article.

Wes
Reply all
Reply to author
Forward
0 new messages