Well, there's a lot of issues here.

First up, if you're using Rest, why not use the RestController itself? It
handles all of this for you already. If you're just looking for something
that *looks* like Rest, you might wanna read the code for it instead, since
that will show you a great deal of how it was accomplished and allow you to
modify as needed to accomplish your real goal.

On Tue, Sep 13, 2011 at 3:42 PM, Sean DiZazzo <[email protected]>wrote:

> Hi,
>
> I'm trying to do something I remember using from TG1.  Basically using
> the default() function to create a simple rest controller.  URLs are
> something like this "http://0.0.0.0:0/<type of object>/<record number>/
> <action>"
>
> This is my default function:
>
> @expose()
> def default(self, _id, action):
>    try:
>        frames = DBSession.query(model.Frame)
>        record = frames.filter_by(id=_id).one()
>    except NoResultFound:
>        flash("Could not find record for frame id: %s" % _id, 'error')
>        redirect(url("/frame"))
>
>    if action == "load":
>         return self.load(record)
>    elif action == "view":
>         return self.view(record)
>
> and then ...
>
> @expose()
> def load(self, record):
>     ...
>    return "some html"
>
> @expose("lts.templates.view")
> def view(self, record):
>    ...
>    return dict(record=record, etc=...)
>
> As you can see, in the "view" method, I need it to render the page
> using the template, but in the load method I don't need to use a
> template.  Well, the view method does not render the page using the
> template, it just prints out the dict's keys on the screen.
>
> The best way I see of doing this is to forget about the @expose
> decorator on the view function and to manually apply the arguments to
> the template and return the html.  How can I do that?
>
> What am I doing wrong?!?  What's the right way?  Thanks.
>
> ~Sean
>
> Two questions?  What is the proper way to use the default method like
> this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
>


-- 
Michael J. Pedersen
My IM IDs: Jabber/[email protected], AIM/pedermj022171
          Yahoo/pedermj2002, MSN/[email protected]
My Online Resume: http://www.icelus.org/
Twitter: pedersentg

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

Reply via email to