Multiple expose

17 views
Skip to first unread message

pkraus

unread,
Feb 13, 2012, 12:03:52 PM2/13/12
to turbo...@googlegroups.com
I have a controller method that needs to return json if its an ajax request (from jquery get,post,ajax) or return a template.

    @expose('json')
    @expose('erp.templates.search.customer')
    def customer(self,query,came_from,search_type):
        log.debug("(%s) %s"%(search_type,query))
        if search_type == 'query':
            pass
        elif search_type == 'by_id':
            customer = m_ar.Customer.by_code(query)
            override_template(Search.customer,'json:')
            return {'customer_id':customer.customer_id}
        return dict(customers = customers)

This doesn't work. I am not sure i need the override but without it the actual genshi template is returned. Without i get errors about identity not being able to translate into json.

How should I best go about this? I could split this into two methods search at call time i know if its json i want or the template however i am still curious about how this could work.

PK

Alessandro Molina

unread,
Feb 13, 2012, 4:21:12 PM2/13/12
to turbo...@googlegroups.com
Using override_template should not be required if you GET
/customer.json instead of /customer. The page extension will be used
to choose which engine to use.

> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/turbogears/-/XvS0ssADkqUJ.
> 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.

Reply all
Reply to author
Forward
0 new messages