label-filtering to core-filtering for webui and json

This commit is contained in:
Martijn Voncken 2008-08-30 11:52:41 +00:00
parent 4abaa514fe
commit 1ef26beeea
4 changed files with 26 additions and 69 deletions

View File

@ -81,12 +81,9 @@ class json_rpc:
* methods : http://dev.deluge-torrent.org/wiki/Development/UiClient#Remoteapi * methods : http://dev.deluge-torrent.org/wiki/Development/UiClient#Remoteapi
""" """
#extra exposed methods #extra exposed methods
json_exposed = ["update_ui","get_stats","set_torrent_options","system_listMethods", json_exposed = ["update_ui","get_stats","system_listMethods",
"get_webui_config","set_webui_config","get_webui_templates"] "get_webui_config","set_webui_config","get_webui_templates"]
cache = {} cache = {}
torrent_options = ["trackers","max_connections","max_upload_slots","max_upload_speed",
"max_download_speed","file_priorities","prioritize_first_last","auto_managed","stop_at_ratio",
"stop_ratio","remove_at_ratio"]
def GET(self): def GET(self):
return json_error("only POST is supported") return json_error("only POST is supported")
@ -144,8 +141,8 @@ class json_rpc:
def get_stats(self): def get_stats(self):
""" """
todo: move to core.
returns: returns:
{{{
{ {
'download_rate':float(), 'download_rate':float(),
'upload_rate':float(), 'upload_rate':float(),
@ -155,7 +152,6 @@ class json_rpc:
'max_num_connections':int(), 'max_num_connections':int(),
'dht_nodes',int() 'dht_nodes',int()
} }
}}}
""" """
stats = {} stats = {}
@ -180,58 +176,25 @@ class json_rpc:
Goal : limit the number of ajax calls Goal : limit the number of ajax calls
input: input:
{{{ keys: see get_torrents_status
keys: see get_torrent_status filter_dict: see get_torrents_status
filter_dict: see label_get_filtered_ids # only effective if the label plugin is enabled.
cache_id: # todo cache_id: # todo
}}}
returns: returns:
{{{
{ {
"torrents": see get_torrent_status "torrents": see get_torrent_status
"filters": see label_get_filters "filters": see get_filter_tree
"stats": see get_stats "stats": see get_stats
"cache_id":int # todo "cache_id":int # todo
} }
}}}
""" """
if 'Label' in sclient.get_enabled_plugins(): filters = sclient.get_filter_tree()
torrent_ids = sclient.label_get_filtered_ids(filter_dict)
filters = sclient.label_filter_items()
else:
torrent_ids = sclient.get_session_state()
filters = {"state":[["All",-1]],"tracker":[],"label":[]}
return { return {
"torrents":sclient.get_torrents_status({"id":torrent_ids}, keys), "torrents":sclient.get_torrents_status(filter_dict , keys),
"filters":filters, "filters":filters,
"stats":self.get_stats(), "stats":self.get_stats(),
"cache_id":-1 "cache_id":-1
} }
def set_torrent_options(self, torrent_id, options_dict):
"""
Composite call.
Goal: limit the number of ajax calls
input:
{{{
torrent_id: the id of the torrent who's options are to be changed
options_dict: a dictionary inwhich the options to be changed are contained
}}}
"""
for option in options_dict:
if option in self.torrent_options:
value = options_dict[option]
if type(value) == str:
try:
value = float(value)
except:
pass
func = getattr(sclient, 'set_torrent_' + option)
func(torrent_id, value)
def get_webui_config(self): def get_webui_config(self):
return dict([x for x in utils.config.get_config().iteritems() if not x[0].startswith("pwd")]) return dict([x for x in utils.config.get_config().iteritems() if not x[0].startswith("pwd")])

View File

@ -106,19 +106,15 @@ class index:
#organize-filters #organize-filters
label_filters = {} label_filters = {}
#disable label plugin for now..
if False and 'label' in [pl.lower() for pl in proxy.get_enabled_plugins()]:
filter_dict = {} filter_dict = {}
if vars.filter_cat and vars.filter_value and vars.filter_value <> "All": if vars.filter_cat and vars.filter_value and vars.filter_value <> "All":
filter_dict = {vars.filter_cat:vars.filter_value} filter_dict = {vars.filter_cat:vars.filter_value}
torrent_ids = proxy.label_get_filtered_ids(filter_dict) torrents = proxy.get_torrents_status(filter_dict, TORRENT_KEYS)
label_filters = proxy.label_filter_items() label_filters = proxy.get_filter_tree()
else: torrent_list = utils.get_enhanced_torrent_list(torrents)
torrent_ids = proxy.get_session_state()
torrent_list = utils.get_enhanced_torrent_list(torrent_ids)
#sorting: #sorting:
if vars.sort: if vars.sort:

View File

@ -23,14 +23,11 @@ document.onkeydown = torrent_table.keydown;
$:(sort_head('name', _('Name'))) $:(sort_head('name', _('Name')))
$:(sort_head('total_size', _('Size'))) $:(sort_head('total_size', _('Size')))
$:(sort_head('progress', _('Progress'))) $:(sort_head('progress', _('Progress')))
<!--
$if label_filters: $#if label_filters:
<!--HACK: $#:(sort_head('label', _('Label')))
abusing label_filters to check if the Orgnize plugin is enabled
--> -->
$:(sort_head('label', _('Label')))
$:(sort_head('tracker_host', _('Tracker'))) $:(sort_head('tracker_host', _('Tracker')))
$:(sort_head('num_seeds', _('Seeders'))) $:(sort_head('num_seeds', _('Seeders')))
$:(sort_head('num_peers', _('Peers'))) $:(sort_head('num_peers', _('Peers')))
$:(sort_head('download_payload_rate', _('Download'))) $:(sort_head('download_payload_rate', _('Download')))
@ -69,8 +66,10 @@ $for torrent in torrent_list:
</div> </div>
</div> </div>
</td> </td>
$if label_filters: <!--
<td>$torrent.label</td> $#if label_filters:
<td>$#torrent.label</td>
-->
<td>$torrent.tracker_host</td> <td>$torrent.tracker_host</td>
<td> <td>
$if torrent.total_seeds != -1: $if torrent.total_seeds != -1:

View File

@ -133,7 +133,7 @@ def get_stats():
return stats return stats
def enhance_torrent_status(torrent_id,status): def enhance_torrent_status(torrent_id, status):
""" """
in: raw torrent_status in: raw torrent_status
out: enhanced torrent_staus out: enhanced torrent_staus
@ -162,13 +162,12 @@ def get_torrent_status(torrent_id):
status = sclient.get_torrent_status(torrent_id,TORRENT_KEYS) status = sclient.get_torrent_status(torrent_id,TORRENT_KEYS)
return enhance_torrent_status(torrent_id, status) return enhance_torrent_status(torrent_id, status)
def get_enhanced_torrent_list(torrent_ids): def get_enhanced_torrent_list(torrents):
""" """
returns a list of storified-torrent-dicts. returns a list of storified-torrent-dicts.
""" """
torrent_dict = sclient.get_torrents_status({"id":torrent_ids}, TORRENT_KEYS)
return [enhance_torrent_status(id, status) return [enhance_torrent_status(id, status)
for id, status in torrent_dict.iteritems()] for id, status in torrents.iteritems()]
def get_newforms_data(form_class): def get_newforms_data(form_class):
""" """