[Twisted-web] Writing Nevow Plugins ... dont have a clue! ;)

Andreas De Stefani andreas.destefani at ucd.ie
Tue Jul 12 13:26:31 MDT 2005


Hey guys,

i was just wondering if this would be possible:

I generate a nevow application with one main template, then i simply 
plugin multiple sub websites which are using template fragments ... for 
example:

i got a main site which has navigation and content, simple so far ... 
then i have a plugin directory where i simply put my "sub websites" ...

webkit/plugins/login
webkit/plugins/andysgreatsite
webkit/plugins/acrapsite

after i restart the webserver there should be a link for each site in 
the navigation and the navigation fragment template and after a click on 
a link, the content should show the sub-site ... or at least render the 
sub-site

hmmm... i was trying a bit, but i think i took the wrong approach... 
probably i have to go one layer lower to inevow.IRequest, but i didnt 
really figure out how i could do that... or is it Realm or Portal ... 
i'm  a bit confused!

anyway this is what i tried: (i even got trouble with the automatic 
plugin loader, the modules werent imported correctly for some strange 
reason)


from nevow import loaders, rend, static, url, tags
import os

PLUGIN_PATH = './plugins'

webplugins = []

class WebKitRoot(rend.Page):
   
    docFactory = loaders.xmlfile('webkit.html')
   
    def __init__(self):
        """init the Root Page, load plugins"""
        self.__importPlugins()
   
    def __importPlugins(self):
        """retrieve the plugins from the plugin directory and import them"""
        plugindirs = os.listdir(PLUGIN_PATH)
        for p in plugindirs:
            if os.path.isdir(os.path.join(PLUGIN_PATH, p)):
                #constructing the plugin path --> ./plugins/login/login
                
webplugins.append(__import__(PLUGIN_PATH.split('/')[-1]+'.'+p+'.'+p))

   
    def childFactory(self, ctx, name):
        if name in ['login']:
            #just a simple test
            return webplugins[0].RootPage()


would be cool if somebody could give me some hints!

thanks a lot!

bye Andy



More information about the Twisted-web mailing list