List Info

Thread: Specifying filters on a sub controller




Specifying filters on a sub controller
user name
2007-10-24 06:10:02
Hi,

I'd like to specify a filter for a sub controller. If I do this using _cp_filters, it prevents the filters on the parent controller being called. Is there a way I can specify filters in addition?

Note: I'm using CP 2.2.1 as this is a TurboGears app.

Thanks for any help,

Paul



import cherrypy
from cherrypy.filters.basefilter import BaseFilter

class MyFilter(BaseFilter):
    def before_request_body(self):
        print 999, "hello!"

class MyFilter2(BaseFilter):
    def before_request_body(self):
 ;       print 888, "hello!"


class Entry:
  _cp_filters = [ MyFilter2() ]
  def view(self, id):
    return 'xx9;
  view.exposed = True

class Root:
  _cp_filters = [ MyFilter() ]


cherrypy.root = Root()
cherrypy.root.entries = Entry()
cherrypy.server.start()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: Specifying filters on a sub controller
country flaguser name
United States
2007-10-24 11:44:43
Paul Johnston wrote:
> I'd like to specify a filter for a sub controller.
> If I do this using _cp_filters, it prevents the
filters
> on the parent controller being called. Is there a way
I
> can specify filters in addition?
> 
> Note: I'm using CP 2.2.1 as this is a TurboGears app.

Not that I can see. I think in CP 2 you just have to share
references. :/

import cherrypy
from cherrypy.filters.basefilter import BaseFilter

class MyFilter(BaseFilter):
    def before_request_body(self): 
        print 999, "hello!"
myfilter = MyFilter()

class MyFilter2(BaseFilter):
    def before_request_body(self):
        print 888, "hello!"
myfilter2 = MyFilter2()

class Entry:
  _cp_filters = [ myfilter, myfilter2 ]
  def view(self, id): 
    return 'xx'
  view.exposed = True

class Root:
  _cp_filters = [ myfilter ]


cherrypy.root = Root()
cherrypy.root.entries = Entry()
cherrypy.server.start()


Robert Brewer
fumanchuaminus.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )