Changes between Version 3 and Version 4 of Development/Plugins/WebUi/Examples


Ignore:
Timestamp:
09/19/2008 07:44:59 PM (16 years ago)
Author:
mvoncken
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Development/Plugins/WebUi/Examples

    v3 v4  
    4242    def export_get_df(self): 
    4343        "returns the result of 'df -h' as a string" 
    44         import subprocess 
    45         return subprocess.call(["df","-h"]) 
     44        import commands 
     45        return commands.getoutput('df -h') 
    4646}}} 
    4747 
     
    6363Fix any errors until the test outputs the desired result. 
    6464 
     65== Add the template == 
     66~/prj/deluge/plugins/Df/df/templates/df.html 
     67{{{ 
     68$def with (df_result) 
     69<h1>df -h</h1> 
     70<pre> 
     71$df_result 
     72</pre> 
     73}}} 
     74== Webui plugin == 
     75Edit ~/prj/deluge/plugins/Df/df/webui.py and add this above ConfigForm 
     76{{{ 
     77#!python 
     78template_dir = os.path.join(os.path.dirname(__file__),"template") 
     79 
     80class df_page(): 
     81    #@api.deco.deluge_page #requires  login, see page_decorators.py for more decorators, 
     82    @api.deco.deluge_page_noauth #<-- this is easier for testing until i implement persistent sessions. 
     83    def GET(self, args): 
     84        df_result = sclient.df_get_df() 
     85        return api.render.df(df_result) #push data to templates/df.html 
     86 
     87class WebUI(object): #replace/remove the old WebUI class 
     88    def __init__(self, plugin_api, plugin_name): 
     89        log.debug("Df plugin initalized..") 
     90        self.plugin = plugin_api 
     91 
     92    def enable(self): 
     93        api.config_page_manager.register('plugins','df',ConfigForm) 
     94        api.render.register_template_path(template_dir) #<--added 
     95        api.page_manager.register_page('/df', df_page)  #<--added 
     96 
     97    def disable(self): 
     98        api.config_page_manager.unregister('df') 
     99        api.render.unregister_template_path(template_dir) #<--added 
     100        api.page_manager.unregister_page('/df')   #<--added 
     101}}} 
    65102 
    66103 
    67 == todo, webui part == 
     104== Test webui page == 
     105{{{killall deluge & deluge -u web &}}} 
     106visit http://localhost:8112/df 
     107 
     108 
     109== Notes/Future ==  
     110 * (template_dir/path) is a convention, it will be automagic somewhere in the future. 
     111 *  
    68112 
    69113 
    70114 
    71115 
     116 
     117 
     118