diff --git a/deluge/ui/webui/webui_plugin/lib/newforms_plus.py b/deluge/ui/webui/webui_plugin/lib/newforms_plus.py index 16ef233ea..50f8c5ac9 100644 --- a/deluge/ui/webui/webui_plugin/lib/newforms_plus.py +++ b/deluge/ui/webui/webui_plugin/lib/newforms_plus.py @@ -156,7 +156,7 @@ class _DelugeIntInput(newforms.TextInput): def render(self, name, value, attrs=None): try: value = int(float(value)) - if value == -1: + if value == -1 or value == None: value = _("Unlimited") except: pass diff --git a/deluge/ui/webui/webui_plugin/page_decorators.py b/deluge/ui/webui/webui_plugin/page_decorators.py index ccb252606..023193329 100644 --- a/deluge/ui/webui/webui_plugin/page_decorators.py +++ b/deluge/ui/webui/webui_plugin/page_decorators.py @@ -14,8 +14,7 @@ from lib.webpy022 import changequery as self_url #deco's: def deluge_page_noauth(func): """ - add http headers - print result of func + add http headers;print result of func """ def deco(self, name = None): web.header("Content-Type", "text/html; charset=utf-8") @@ -27,8 +26,8 @@ def deluge_page_noauth(func): def check_session(func): """ - a decorator return func if session is valid, else redirect to login page. + mostly used for POST-pages. """ def deco(self, name = None): ws.log.debug('%s.%s(name=%s)' % (self.__class__.__name__, func.__name__, @@ -41,14 +40,49 @@ def check_session(func): seeother(url("/login",redir=self_url())) else: seeother("/login") #do not continue, and redirect to login page + deco.__name__ = func.__name__ return deco def deluge_page(func): + "deluge_page_noauth+check_session" return check_session(deluge_page_noauth(func)) #combi-deco's: +#decorators to use in combination with the ones above. +def torrent_ids(func): + """ + change page(self, name) to page(self, torrent_ids) + for pages that allow a list of torrents. + """ + def deco(self, name): + return func (self, name.split(',')) + deco.__name__ = func.__name__ + return deco + +def torrent_list(func): + """ + change page(self, name) to page(self, torrent_ids) + for pages that allow a list of torrents. + """ + def deco(self, name): + torrent_list = [get_torrent_status(id) for id in name.split(',')] + return func (self, torrent_list) + deco.__name__ = func.__name__ + return deco + +def torrent(func): + """ + change page(self, name) to page(self, get_torrent_status(torrent_id)) + """ + def deco(self, name): + torrent_id = name.split(',')[0] + torrent =get_torrent_status(torrent_id) + return func (self, torrent) + deco.__name__ = func.__name__ + return deco + def auto_refreshed(func): - "decorator:adds a refresh header" + "adds a refresh header" def deco(self, name = None): if getcookie('auto_refresh') == '1': web.header("Refresh", "%i ; url=%s" % @@ -58,7 +92,7 @@ def auto_refreshed(func): return deco def remote(func): - "decorator for remote api's" + "decorator for remote (string) api's" def deco(self, name = None): try: ws.log.debug('%s.%s(%s)' ,self.__class__.__name__, func.__name__,name ) diff --git a/deluge/ui/webui/webui_plugin/pages.py b/deluge/ui/webui/webui_plugin/pages.py index 30090a5d7..a8d48a18f 100644 --- a/deluge/ui/webui/webui_plugin/pages.py +++ b/deluge/ui/webui/webui_plugin/pages.py @@ -73,6 +73,7 @@ urls = ( "/torrent/move/(.*)", "torrent_move", "/torrent/queue/up/(.*)", "torrent_queue_up", "/torrent/queue/down/(.*)", "torrent_queue_down", + "/torrent/files/(.*)","torrent_files", "/pause_all", "pause_all", "/resume_all", "resume_all", "/refresh/set", "refresh_set", @@ -151,34 +152,34 @@ class index: class torrent_info: @deco.deluge_page @deco.auto_refreshed - def GET(self, name): - torrent_id = name.split(',')[0] - return render.torrent_info(get_torrent_status(torrent_id)) + @deco.torrent + def GET(self, torrent): + return render.torrent_info(torrent) class torrent_info_inner: @deco.deluge_page - def GET(self, torrent_ids): + @deco.torrent + def GET(self, torrent): vars = web.input(tab = None) if vars.tab: active_tab = vars.tab else: active_tab = getcookie("torrent_info_tab") or "details" setcookie("torrent_info_tab", active_tab) - torrent_ids = torrent_ids.split(',') - info = get_torrent_status(torrent_ids[0]) - return render.torrent_info_inner(info, active_tab) + + return render.torrent_info_inner(torrent, active_tab) class torrent_start: @deco.check_session - def POST(self, name): - torrent_ids = name.split(',') + @deco.torrent_ids + def POST(self, torrent_ids): ws.proxy.resume_torrent(torrent_ids) do_redirect() class torrent_stop: @deco.check_session - def POST(self, name): - torrent_ids = name.split(',') + @deco.torrent_ids + def POST(self, torrent_ids): ws.proxy.pause_torrent(torrent_ids) do_redirect() @@ -214,45 +215,60 @@ class remote_torrent_add: class torrent_delete: @deco.deluge_page - def GET(self, name): - torrent_ids = name.split(',') - torrent_list = [get_torrent_status(id) for id in torrent_ids] - return render.torrent_delete(name, torrent_list) + @deco.torrent_list + def GET(self, torrent_list): + torrent_str = ",".join([t.id for t in torrent_list]) + #todo: remove the ",".join! + return render.torrent_delete(torrent_str, torrent_list) @deco.check_session - def POST(self, name): - torrent_ids = name.split(',') + @deco.torrent_ids + def POST(self, torrent_ids): vars = web.input(data_also = None, torrent_also = None) data_also = bool(vars.data_also) torrent_also = bool(vars.torrent_also) ws.proxy.remove_torrent(torrent_ids, torrent_also, data_also) do_redirect() - class torrent_queue_up: @deco.check_session - def POST(self, name): + @deco.torrent_list + def POST(self, torrent_list): #a bit too verbose.. - torrent_ids = name.split(',') - torrents = [get_torrent_status(id) for id in torrent_ids] - torrents.sort(lambda x, y : x.queue_pos - y.queue_pos) - torrent_ids = [t.id for t in torrents] + torrent_list.sort(lambda x, y : x.queue_pos - y.queue_pos) + torrent_ids = [t.id for t in torrent_list] for torrent_id in torrent_ids: ws.proxy.queue_up(torrent_id) do_redirect() class torrent_queue_down: @deco.check_session - def POST(self, name): + @deco.torrent_list + def POST(self, torrent_list): #a bit too verbose.. - torrent_ids = name.split(',') - torrents = [get_torrent_status(id) for id in torrent_ids] - torrents.sort(lambda x, y : x.queue_pos - y.queue_pos) - torrent_ids = [t.id for t in torrents] + torrent_list.sort(lambda x, y : x.queue_pos - y.queue_pos) + torrent_ids = [t.id for t in torrent_list] for torrent_id in reversed(torrent_ids): ws.proxy.queue_down(torrent_id) do_redirect() +class torrent_files: + @deco.check_session + def POST(self, torrent_id): + torrent = get_torrent_status(torrent_id) + file_priorities = web.input(file_priorities=[]).file_priorities + + #ws.log.debug("file-prio:%s" % file_priorities) + #file_priorities contains something like ['0','2','3','4'] + #transform to: [1,0,1,1,1] + proxy_prio = [0 for x in xrange(len(torrent.file_priorities))] + for pos in file_priorities: + proxy_prio[int(pos)] = 1 + #ws.log.debug("proxy-prio:%s" % proxy_prio) + + ws.proxy.set_torrent_file_priorities(torrent_id, proxy_prio) + do_redirect() + class pause_all: @deco.check_session def POST(self, name): @@ -306,6 +322,7 @@ class logout: end_session() seeother('/login') + class static(static_handler): base_dir = os.path.join(os.path.dirname(__file__), 'static') diff --git a/deluge/ui/webui/webui_plugin/templates/advanced/static/advanced.css b/deluge/ui/webui/webui_plugin/templates/advanced/static/advanced.css index c2723b3ee..a7bcd23ce 100644 --- a/deluge/ui/webui/webui_plugin/templates/advanced/static/advanced.css +++ b/deluge/ui/webui/webui_plugin/templates/advanced/static/advanced.css @@ -286,7 +286,7 @@ form { /*all forms!*/ float: left; width:150px; text-align:left; - height:60%; + height:none; } #config_chooser ul { @@ -303,7 +303,7 @@ form { /*all forms!*/ } #config_panel { - height:60%; + height:none; float:left; width:500px; margin-left:20px; diff --git a/deluge/ui/webui/webui_plugin/templates/deluge/tab_files.html b/deluge/ui/webui/webui_plugin/templates/deluge/tab_files.html index 5567f12f9..9d62e9513 100644 --- a/deluge/ui/webui/webui_plugin/templates/deluge/tab_files.html +++ b/deluge/ui/webui/webui_plugin/templates/deluge/tab_files.html @@ -1,20 +1,27 @@ $def with (torrent) +