Hi all,

I'm writing a RESTful app and want to expose different aspects of an
object using different methods depending on part of the URL:

/product/1/overview

should provide text/html from a kid template

/product/1/image

should provide image/jpg from binary data held as part of the model.

I read somewhere (I think in the TurboGears book) that you can return
tg_format as part of the result dictionary to do this, but its not
working for me. Here's what I have:


    @expose(content_type = "image/jpg", as_format = "image")
    @expose(fragment = True)
    def default(self, *args, **kwargs):
        if len(args) != 2:
            raise Exception("Invalid use of product controller - must
provide ID and action. You provided %d args: %s" % (len(args), str
(args)))
        id, action = args
        id = int(id)
        product = Product.get(id)
        if action == 'overview':
            return dict(product = product, tg_template =
"doublesweb.templates.product_overview")
        elif action == 'details':
            return dict(product = product, tg_template =
"doublesweb.templates.product_details")
        elif action == 'image':
            response.body = product.image
            return dict(tg_format = "image")
        raise Exception("Unknown action: %s for product ID: %d" %
(action, id))

It returns the correct content_type when I add ?tg_format=image to the
URL obtaining the image, but IMHO it would be more elegant to let the
controller decide what kind of response it wants to give.

The other problem I'm having is that I'm not actually getting the
image data returned - but that's for another post (unless someone
spots it and can provide me that info too :)).

Thanks in advance for any help / hints / tips :D

Cheers,
C
--~--~---------~--~----~------------~-------~--~----~
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