mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-27 03:36:16 +00:00
simplify do_redirect
This commit is contained in:
parent
649fd2495d
commit
7e076a82a0
@ -80,6 +80,8 @@ class json_rpc:
|
||||
|
||||
if method.startswith("system."):
|
||||
result = self.exec_system_method(method, params,id)
|
||||
elif method == ("list_torrents"):
|
||||
result = self.list_torrents(method, params,id)
|
||||
else:
|
||||
result = self.exec_client_method(method, params,id)
|
||||
|
||||
@ -122,6 +124,77 @@ class json_rpc:
|
||||
return self.exec_client_method("list_methods", params, id)
|
||||
raise Exception('Unknown method:%s', method)
|
||||
|
||||
|
||||
def list_torrents(self,params,id):
|
||||
"""
|
||||
== torrent_list ==
|
||||
Composite call.
|
||||
Goal : limit the number of ajax calls
|
||||
|
||||
filter is only effective if the organize plugin is enabled.
|
||||
label is redirected to the tracker column, there will be a label feature in the future.
|
||||
cache_id = future feature, not effective yet.
|
||||
|
||||
=== input ===
|
||||
{{{
|
||||
{
|
||||
keys: [<like get_torrent_status>],
|
||||
filter: {
|
||||
/*ommitted keys are ignored*/
|
||||
"keyword":string
|
||||
"label":string,
|
||||
"state":string
|
||||
} ,
|
||||
cache_id: int
|
||||
}
|
||||
}}}
|
||||
|
||||
=== output ===
|
||||
{{{
|
||||
{
|
||||
torrents:
|
||||
[ {"id":string,"name":string, ..}, ..]
|
||||
states:
|
||||
[('string',int), ..]
|
||||
trackers:
|
||||
[('string',int), ..]
|
||||
stats:
|
||||
[upload_rate, download_rate, nu_connections, num_dht_nodes]
|
||||
}
|
||||
cache_id:int
|
||||
}
|
||||
}}}
|
||||
"""
|
||||
"""filter = params["filter"]
|
||||
keys = params["keys"]
|
||||
cache_id = params["cache_id"]
|
||||
organize_filters = {}
|
||||
|
||||
if 'Organize' in proxy.get_enabled_plugins():
|
||||
filter_dict = {}
|
||||
|
||||
for filter_name in ["state","tracker","keyword"]:
|
||||
value = get(filter,filter_name)
|
||||
if value and value <> "All":
|
||||
filter_dict[filter_name] = value
|
||||
|
||||
torrent_ids = proxy.organize_get_session_state(filter_dict)
|
||||
organize_filters = Storage(proxy.organize_all_filter_items())
|
||||
else:
|
||||
torrent_ids = proxy.get_session_state()
|
||||
organize_filters = {"state":[["All",-1]],"tracker":[]}
|
||||
|
||||
result = {
|
||||
"torrents":sclient.get_torrents_status(torrent_ids, keys),
|
||||
"state":organize_filters["state"],
|
||||
"tracker":organize_filters["tracker"],
|
||||
"stats":[0, 1, 2, 3], #todo
|
||||
"cache_id":cache_id
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
|
||||
def register():
|
||||
component.get("PageManager").register_page("/json/rpc",json_rpc)
|
||||
|
||||
|
@ -88,20 +88,23 @@ class index:
|
||||
@deco.deluge_page
|
||||
@deco.auto_refreshed
|
||||
def GET(self, name):
|
||||
vars = web.input(sort=None, order=None)
|
||||
vars = web.input(sort=None, order=None, state=None , tracker=None, keyword=None)
|
||||
|
||||
#cookies are a delicious delecacy.
|
||||
if not vars.sort: #no arguments, default to coockies.
|
||||
vars.update(cookies())
|
||||
else: #has arguments:set cookies from arguments.
|
||||
for key in ["sort", "order", "state", "tracker", "keyword"]:
|
||||
setcookie(key,getattr(vars,key))
|
||||
|
||||
#organize-filters
|
||||
organize_filters = {}
|
||||
if 'Organize' in proxy.get_enabled_plugins():
|
||||
filter_dict = {}
|
||||
|
||||
for filter_name in ["state","tracker","keyword"]:
|
||||
value = getattr(web.input(**{filter_name:None}), filter_name)
|
||||
value = getattr(vars, filter_name)
|
||||
if value and value <> "All":
|
||||
filter_dict[filter_name] = value
|
||||
setcookie(filter_name, getattr(vars, filter_name))
|
||||
else:
|
||||
setcookie(filter_name, "")
|
||||
|
||||
torrent_ids = proxy.organize_get_session_state(filter_dict)
|
||||
organize_filters = Storage(proxy.organize_all_filter_items())
|
||||
@ -121,8 +124,6 @@ class index:
|
||||
if vars.order == 'up':
|
||||
torrent_list = list(reversed(torrent_list))
|
||||
|
||||
setcookie("order", vars.order)
|
||||
setcookie("sort", vars.sort)
|
||||
return render.index(torrent_list, organize_filters)
|
||||
route('/index',index)
|
||||
|
||||
|
@ -138,6 +138,10 @@ def template_sort_head(id,name):
|
||||
active_down = False
|
||||
order = 'down'
|
||||
|
||||
if not vars.sort: #no arguments, default to coockies.
|
||||
vars.update(cookies())
|
||||
|
||||
|
||||
if vars.sort == id:
|
||||
if vars.order == 'down':
|
||||
order = 'up'
|
||||
|
@ -87,36 +87,14 @@ def self_url(**kwargs):
|
||||
return config["base"] + changequery(**kwargs)
|
||||
|
||||
def do_redirect():
|
||||
"""for redirects after a POST"""
|
||||
vars = web.input(redir = None)
|
||||
ck = cookies()
|
||||
url_vars = {}
|
||||
|
||||
"""go to /index unless the redir var is set."""
|
||||
vars = web.input(redir=None)
|
||||
if vars.redir:
|
||||
w_seeother(vars.redir) #redir variable contains base
|
||||
return
|
||||
|
||||
#for the filters:
|
||||
if ("order" in ck and "sort" in ck):
|
||||
url_vars.update({'sort':ck['sort'] ,'order':ck['order'] })
|
||||
|
||||
organize = False
|
||||
try:
|
||||
organize = ('Organize' in sclient.get_enabled_plugins())
|
||||
except:
|
||||
pass
|
||||
|
||||
if organize:
|
||||
#todo:DRY
|
||||
if ("state" in ck) and ck['state']:
|
||||
url_vars['state'] = ck['state']
|
||||
if ("tracker" in ck) and ck['tracker']:
|
||||
url_vars['tracker'] = ck['tracker']
|
||||
if ("keyword" in ck) and ck['keyword']:
|
||||
url_vars['keyword'] = ck['keyword']
|
||||
|
||||
#redirect.
|
||||
w_seeother(url("/index", **url_vars))
|
||||
#default:
|
||||
seeother('/index')
|
||||
|
||||
def getcookie(key, default = None):
|
||||
"because i'm too lazy to type 3 lines for something this simple"
|
||||
|
Loading…
x
Reference in New Issue
Block a user