prepare for plugins

This commit is contained in:
Martijn Voncken 2008-02-28 19:35:45 +00:00
parent 8a4bf3ab15
commit d844337cbb
9 changed files with 79 additions and 88 deletions

View File

@ -29,6 +29,8 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
#TODO: rename to config_manager.py
import lib.newforms_plus as forms
import page_decorators as deco
import lib.webpy022 as web

View File

@ -42,6 +42,11 @@ from config import config_page
from torrent_options import torrent_options
from torrent_move import torrent_move
#plugin like api's
import menu_manager
from menu_manager import TB
#import forms
#
from debugerror import deluge_debugerror
@ -61,6 +66,39 @@ import os
#special/complex pages:
from torrent_add import torrent_add
#plugin-like api's : register
menu_manager.register_admin_page("config", _("Config"), "/config/")
menu_manager.register_admin_page("connect", _("Connect"), "/connect")
menu_manager.register_admin_page("about", _("About"), "/about")
menu_manager.register_admin_page("logout", _("Logout"), "/logout")
menu_manager.register_detail_tab("details", _("Details"), "tab_meta")
menu_manager.register_detail_tab("files", _("Files"), "tab_files")
menu_manager.register_detail_tab("options", _("Options"), "tab_options")
menu_manager.register_toolbar_item("add", _("Add"), "list-add.png" , TB.generic,
"GET","/torrent/add/", True)
menu_manager.register_toolbar_item("delete",_("Delete"), "list-remove.png" ,TB.torrent_list,
"GET","/torrent/delete/" , True)
menu_manager.register_toolbar_item("stop",_("Stop"), "pause.png" ,TB.torrent_list,
"POST","/torrent/stop/", True)
menu_manager.register_toolbar_item("start",_("Start"), "start.png" ,TB.torrent_list,
"POST","/torrent/start/", True)
menu_manager.register_toolbar_item("queue_up",_("Up"), "queue-up.png" ,TB.torrent_list,
"POST","/torrent/queue/up/", True)
menu_manager.register_toolbar_item("queue_down",_("Down"), "queue-down.png" ,TB.torrent_list,
"POST","/torrent/queue/down/", True)
menu_manager.register_toolbar_item("details",_("Details"), "details.png" ,TB.torrent,
"GET","/torrent/info/", True)
menu_manager.register_toolbar_item("move",_("Move"), "move.png" ,TB.torrent_list,
"POST","/torrent/move/", True)
menu_manager.register_toolbar_item("reannounce",_("Reannounce"), "view-refresh.png" ,TB.torrent_list,
"POST","'/torrent/reannounce/", False)
menu_manager.register_toolbar_item("recheck",_("Recheck"), "view-refresh.png" ,TB.torrent_list,
"POST","'/torrent/recheck/", False)
#routing:
urls = (
"/login", "login",

View File

@ -66,6 +66,10 @@ class subclassed_render(object):
else:
return getattr(self.base_template, attr)
def __getitem__(self, item):
"for plugins/templates"
return getattr(self, item)
render = subclassed_render()
def error_page(error):

View File

@ -12,51 +12,14 @@ $for t in torrent_list:
<div class="panel" id="toolbar">
<a class='toolbar_btn' href="#"
onclick='toolbar_get("/torrent/add/",0)'
title='$_("Add")'><img class='toolbar_btn'
src='/static/images/tango/list-add.png'></a>
$for id, title, image, flag, method, url, important in toolbar_items:
$if important:
<a class='toolbar_btn' href="#"
onclick='toolbar_$(method.lower()) ("$url",$flag)'
title='$title'><img class='toolbar_btn'
src='/static/images/tango/$image'></a>
<a class='toolbar_btn' href="#"
onclick='toolbar_get("/torrent/delete/",2)'><img class='toolbar_btn'
src='/static/images/tango/list-remove.png'
title='$_("Remove")'></a>
<a class='toolbar_btn' href="#"
onclick='toolbar_post("/torrent/stop/",2)'
title='$_("Pause")'><img class='toolbar_btn'
src='/static/images/tango/pause.png'
></a>
<a class='toolbar_btn' href="#"
onclick='toolbar_post("/torrent/start/",2)'
title='$_("Start")'><img class='toolbar_btn'
src='/static/images/tango/start.png'></a>
<a class='toolbar_btn' href="#"
onclick='toolbar_post("/torrent/queue/up/",2)'
title='$_("Up")'><img class='toolbar_btn'
src='/static/images/tango/queue-up.png'></a>
<a class='toolbar_btn' href="#"
onclick='toolbar_post("/torrent/queue/down/",2)'
title='$_("Down")'><img class='toolbar_btn'
src='/static/images/tango/queue-down.png'></a>
<a class='toolbar_btn' href="#"
onclick='toolbar_get("/torrent/info/",1)'
title='$_("Details")'><img class='toolbar_btn'
src='/static/images/tango/details.png'></a>
<a class='toolbar_btn' href="#"
onclick='toolbar_get("/torrent/move/",2)'
title='$_("Move")'><img class='toolbar_btn'
src='/static/images/tango/move.png'></a>
$:category_tabs(all_torrents)
$:category_tabs(all_torrents)
</div>

View File

@ -7,16 +7,12 @@ $def with (torrent, active_tab)
</head>
<body class="inner">
$:render.part_tab_button('details', _("Details"), active_tab)
$:render.part_tab_button('files', _("Files"), active_tab)
$:render.part_tab_button('options', _("Options"), active_tab)
$for id, title, tab in detail_tabs:
$:render.part_tab_button(id, title, active_tab)
$if active_tab == 'details':
$:render.tab_meta(torrent)
$if active_tab == 'files':
$:render.tab_files(torrent)
$if active_tab == 'options':
$:render.tab_options(torrent)
$for id, title, tab in detail_tabs:
$if active_tab == id:
$:render[tab](torrent)
</body>
</html>

View File

@ -1,10 +1,10 @@
$def with (active_tab)
<div id="admin_toolbar" class="panel" style="width:98%;text-align:left">
<a href='/config/'>Config</a>
<!--<a href='/log'>Log</a>
<a href='/alerts'>Alerts</a>-->
<a href='/connect'>Connect</a>
<a href='/about'>About</a>
<a href='/logout'>Logout</a>
$for id, title, url in admin_pages:
<a
$if id == active_tab:
class="tab_button_active"
$else:
class="tab_button"
href='$url'>$title</a>
</div>

View File

@ -2,34 +2,13 @@ $def with (torrent)
$:(render.header(torrent.message + '/' + torrent.name))
<div class="panel">
$for id, title, image, flag, method, url, important in toolbar_items:
$if (flag > 0) and (id != 'details'):
$:render.part_button(method, (url + str(torrent.id)), title, 'tango/' + image)
$if (torrent.action == 'start'):
$:render.part_button('POST', '/torrent/start/' + str(torrent.id), _('Resume'), 'tango/start.png')
$else:
$:render.part_button('POST', '/torrent/stop/' + str(torrent.id), _('Pause'), 'tango/pause.png')
$:render.part_button('GET', '/torrent/delete/' + str(torrent.id), _('Remove'), 'tango/list-remove.png')
$:render.part_button('POST', '/torrent/reannounce/' + str(torrent.id), _('Reannounce'), 'tango/view-refresh.png')
$:render.part_button('POST', '/torrent/recheck/' + str(torrent.id), _('Recheck'), 'tango/view-refresh.png')
$:render.part_button('POST', '/torrent/queue/up/' + str(torrent.id), _('Queue Up'), 'tango/queue-up.png')
$:render.part_button('POST', '/torrent/queue/down/' + str(torrent.id), _('Queue Down'), 'tango/queue-down.png')
$:render.part_button('GET', '/torrent/move/' + str(torrent.id), _('Move'), 'tango/move.png')
<h3>$_('Details')</h3>
$:render.tab_meta(torrent)
<h3>$_('Options')</h3>
$:render.tab_options(torrent)
<h3>$_('Files')</h3>
$:render.tab_files(torrent)
$for id, title, tab in detail_tabs:
<h3>$title</h3>
$:render[tab](torrent)
<br>
<!--

View File

@ -331,6 +331,15 @@ def daemon_start_localhost(port):
# Spawn a local daemon
os.popen("deluged -p %s" % port)
def logcall(func):
"log a function/method-call"
def deco(*args, **kwargs):
log.debug("call: %s<%s,%s>" % (func.__name__, args, kwargs))
return func(*args, **kwargs) #logdeco
return deco
#exceptions:
class WebUiError(Exception):
"""the message of these exceptions will be rendered in

View File

@ -56,7 +56,7 @@ try:
except:
import gettext
gettext.install('~/')
#log.error('no translations :(')
log.error('no translations :(')
#constants