mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-04 15:38:43 +00:00
webui:move filter-logic to organize-plugin
This commit is contained in:
parent
8cf72ca2dc
commit
db24c543fe
5 changed files with 66 additions and 118 deletions
|
@ -162,39 +162,53 @@ class index:
|
||||||
@deco.deluge_page
|
@deco.deluge_page
|
||||||
@deco.auto_refreshed
|
@deco.auto_refreshed
|
||||||
def GET(self, name):
|
def GET(self, name):
|
||||||
vars = web.input(sort=None, order=None ,filter=None , category=None)
|
vars = web.input(sort=None, order=None ,state=None , tracker=None,keyword=None)
|
||||||
|
|
||||||
torrent_list = get_torrent_list()
|
organize_filters = {}
|
||||||
all_torrents = torrent_list[:]
|
if 'Organize' in proxy.get_enabled_plugins():
|
||||||
|
filter_dict = {}
|
||||||
#filter-state
|
#organize-filters
|
||||||
if vars.filter:
|
#todo: DRY (in less lines of code)
|
||||||
torrent_list = filter_torrent_state(torrent_list, vars.filter)
|
if vars.state:
|
||||||
setcookie("filter", vars.filter)
|
filter_dict['state'] = vars.state
|
||||||
|
setcookie("state", vars.state)
|
||||||
else:
|
else:
|
||||||
setcookie("filter", "")
|
setcookie("filter", "")
|
||||||
|
|
||||||
#filter-cat
|
if vars.tracker:
|
||||||
if vars.category:
|
filter_dict['tracker'] = vars.tracker
|
||||||
torrent_list = [t for t in torrent_list if t.category == vars.category]
|
setcookie("tracker", vars.tracker)
|
||||||
setcookie("category", vars.category)
|
|
||||||
else:
|
else:
|
||||||
setcookie("category", "")
|
setcookie("tracker", "")
|
||||||
|
|
||||||
|
if vars.keyword:
|
||||||
|
filter_dict['keyword'] = vars.keyword
|
||||||
|
setcookie("keyword", vars.keyword)
|
||||||
|
else:
|
||||||
|
setcookie("keyword", "")
|
||||||
|
|
||||||
|
torrent_ids = proxy.organize_get_session_state(filter_dict)
|
||||||
|
organize_filters = Storage(proxy.organize_all_filter_items())
|
||||||
|
|
||||||
|
else:
|
||||||
|
torrent_ids = proxy.get_session_state()
|
||||||
|
|
||||||
|
torrent_list = utils.get_enhanced_torrent_list(torrent_ids)
|
||||||
|
|
||||||
#sorting:
|
#sorting:
|
||||||
if vars.sort:
|
if vars.sort:
|
||||||
try:
|
try:
|
||||||
torrent_list.sort(key=attrgetter(vars.sort))
|
torrent_list.sort(key=attrgetter(vars.sort))
|
||||||
except:
|
except:
|
||||||
log.debug('Sorting Failed')
|
log.error('Sorting Failed')
|
||||||
|
|
||||||
if vars.order == 'up':
|
if vars.order == 'up':
|
||||||
torrent_list = list(reversed(torrent_list))
|
torrent_list = list(reversed(torrent_list))
|
||||||
|
|
||||||
setcookie("order", vars.order)
|
setcookie("order", vars.order)
|
||||||
setcookie("sort", vars.sort)
|
setcookie("sort", vars.sort)
|
||||||
|
log.debug("filters=%s,plugins=%s" % (organize_filters, proxy.get_enabled_plugins()))
|
||||||
return render.index(torrent_list, all_torrents)
|
return render.index(torrent_list, organize_filters)
|
||||||
|
|
||||||
class torrent_info:
|
class torrent_info:
|
||||||
@deco.deluge_page
|
@deco.deluge_page
|
||||||
|
|
|
@ -93,10 +93,12 @@ def error_page(error):
|
||||||
print render.error(error)
|
print render.error(error)
|
||||||
|
|
||||||
#template-defs:
|
#template-defs:
|
||||||
|
"""
|
||||||
|
obsolete:
|
||||||
def category_tabs(torrent_list):
|
def category_tabs(torrent_list):
|
||||||
filter_tabs, category_tabs = get_category_choosers(torrent_list)
|
filter_tabs, category_tabs = get_category_choosers(torrent_list)
|
||||||
return render.part_categories(filter_tabs, category_tabs)
|
return render.part_categories(filter_tabs, category_tabs)
|
||||||
|
"""
|
||||||
|
|
||||||
def template_crop(text, end):
|
def template_crop(text, end):
|
||||||
try:
|
try:
|
||||||
|
@ -160,7 +162,6 @@ def ftime(val):
|
||||||
template.Template.globals.update({
|
template.Template.globals.update({
|
||||||
'sort_head': template_sort_head,
|
'sort_head': template_sort_head,
|
||||||
'part_stats':template_part_stats,
|
'part_stats':template_part_stats,
|
||||||
'category_tabs':category_tabs,
|
|
||||||
'crop': template_crop,
|
'crop': template_crop,
|
||||||
'crop_left': template_crop_left,
|
'crop_left': template_crop_left,
|
||||||
'_': _ , #gettext/translations
|
'_': _ , #gettext/translations
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
$def with (torrent_list, all_torrents)
|
$def with (torrent_list, organize_filters)
|
||||||
$:render.header(_('Torrent list'))
|
$:render.header(_('Torrent list'))
|
||||||
|
|
||||||
<script language="javascript">
|
<script language="javascript">
|
||||||
|
@ -19,7 +19,8 @@ $for id, title, image, flag, method, url, important in toolbar_items:
|
||||||
title='$title'><img class='toolbar_btn'
|
title='$title'><img class='toolbar_btn'
|
||||||
src='/static/images/tango/$image'></a>
|
src='/static/images/tango/$image'></a>
|
||||||
|
|
||||||
$:category_tabs(all_torrents)
|
$if organize_filters:
|
||||||
|
$:render.part_categories(organize_filters)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,28 @@
|
||||||
$def with (filter_tabs, category_tabs)
|
$def with (filters)
|
||||||
<form method="GET" id="category_form">
|
<form method="GET" id="category_form">
|
||||||
<input type="hidden" name="sort" value="$get('sort')">
|
<input type="hidden" name="sort" value="$get('sort')">
|
||||||
<input type="hidden" name="order" value="$get('order')">
|
<input type="hidden" name="order" value="$get('order')">
|
||||||
<select name='filter' id='filter'
|
<select name='state' id='state'
|
||||||
onchange="document.getElementById('category_form').submit()"
|
onchange="document.getElementById('category_form').submit()"
|
||||||
title="$_('Filter on state')">
|
title="$_('Filter on state')">
|
||||||
$for tab in filter_tabs:
|
$for state, num in filters.state:
|
||||||
<option value="$tab.filter"
|
<option value="$state"
|
||||||
$if tab.filter == get('filter'):
|
$if state == get('state'):
|
||||||
selected
|
selected
|
||||||
>
|
>
|
||||||
$tab.title
|
$_(state) ($num)
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<select name='category' id='category'
|
<select name='tracker' id='tracker'
|
||||||
onchange="document.getElementById('category_form').submit()"
|
onchange="document.getElementById('category_form').submit()"
|
||||||
title="$_('Filter on Tracker')">
|
title="$_('Filter on Tracker')">
|
||||||
$for tab in category_tabs:
|
<option value="">$_('Trackers')</option>
|
||||||
<option value="$tab.category"
|
$for tracker, num in filters.tracker:
|
||||||
$if tab.category == get('category'):
|
<option value="$tracker"
|
||||||
|
$if tracker == get('tracker'):
|
||||||
selected
|
selected
|
||||||
>
|
>
|
||||||
$tab.title
|
$tracker ($num)
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
@ -67,22 +67,10 @@ def start_session():
|
||||||
log.debug('start session')
|
log.debug('start session')
|
||||||
session_id = str(random.random())
|
session_id = str(random.random())
|
||||||
ws.SESSIONS.append(session_id)
|
ws.SESSIONS.append(session_id)
|
||||||
#if len(ws.SESSIONS) > 20: #save max 20 sessions?
|
|
||||||
# ws.SESSIONS = ws.SESSIONS[-20:]
|
|
||||||
#not thread safe! , but a verry rare bug.
|
|
||||||
#f = open(ws.session_file,'wb')
|
|
||||||
#pickle.dump(ws.SESSIONS, f)
|
|
||||||
#f.close()
|
|
||||||
setcookie("session_id", session_id)
|
setcookie("session_id", session_id)
|
||||||
|
|
||||||
def end_session():
|
def end_session():
|
||||||
session_id = getcookie("session_id")
|
session_id = getcookie("session_id")
|
||||||
#if session_id in ws.SESSIONS:
|
|
||||||
# ws.SESSIONS.remove(session_id)
|
|
||||||
#not thread safe! , but a verry rare bug.
|
|
||||||
#f = open(ws.session_file,'wb')
|
|
||||||
#pickle.dump(ws.SESSIONS, f)
|
|
||||||
#f.close()
|
|
||||||
setcookie("session_id","")
|
setcookie("session_id","")
|
||||||
|
|
||||||
def do_redirect():
|
def do_redirect():
|
||||||
|
@ -91,25 +79,33 @@ def do_redirect():
|
||||||
ck = cookies()
|
ck = cookies()
|
||||||
url_vars = {}
|
url_vars = {}
|
||||||
|
|
||||||
|
#redirect to a non-default page.
|
||||||
if vars.redir:
|
if vars.redir:
|
||||||
seeother(vars.redir)
|
seeother(vars.redir)
|
||||||
return
|
return
|
||||||
#todo:cleanup
|
|
||||||
|
#for the filters:
|
||||||
if ("order" in ck and "sort" in ck):
|
if ("order" in ck and "sort" in ck):
|
||||||
url_vars.update({'sort':ck['sort'] ,'order':ck['order'] })
|
url_vars.update({'sort':ck['sort'] ,'order':ck['order'] })
|
||||||
if ("filter" in ck) and ck['filter']:
|
|
||||||
url_vars['filter'] = ck['filter']
|
|
||||||
if ("category" in ck) and ck['category']:
|
|
||||||
url_vars['category'] = ck['category']
|
|
||||||
|
|
||||||
|
if 'Organize' in proxy.get_enabled_plugins():
|
||||||
|
#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.
|
||||||
seeother(url("/index", **url_vars))
|
seeother(url("/index", **url_vars))
|
||||||
|
|
||||||
def getcookie(key, default = None):
|
def getcookie(key, default = None):
|
||||||
|
"because i'm too lazy to type 3 lines for something this simple"
|
||||||
key = str(key).strip()
|
key = str(key).strip()
|
||||||
ck = cookies()
|
ck = cookies()
|
||||||
return ck.get(key, default)
|
return ck.get(key, default)
|
||||||
|
|
||||||
|
|
||||||
def get_stats():
|
def get_stats():
|
||||||
stats = Storage()
|
stats = Storage()
|
||||||
|
|
||||||
|
@ -126,13 +122,8 @@ def get_stats():
|
||||||
|
|
||||||
async_proxy.force_call(block=True)
|
async_proxy.force_call(block=True)
|
||||||
|
|
||||||
#log.debug(str(stats))
|
|
||||||
|
|
||||||
stats.download_rate = fspeed(stats.download_rate)
|
stats.download_rate = fspeed(stats.download_rate)
|
||||||
stats.upload_rate = fspeed(stats.upload_rate)
|
stats.upload_rate = fspeed(stats.upload_rate)
|
||||||
#stats.max_upload = stats.max_upload
|
|
||||||
#stats.max_download = stats.max_download
|
|
||||||
|
|
||||||
|
|
||||||
if stats.max_upload < 0:
|
if stats.max_upload < 0:
|
||||||
stats.max_upload = _("∞")
|
stats.max_upload = _("∞")
|
||||||
|
@ -153,6 +144,7 @@ def enhance_torrent_status(torrent_id,status):
|
||||||
"""
|
"""
|
||||||
status = Storage(status)
|
status = Storage(status)
|
||||||
#add missing values for deluge 0.6:
|
#add missing values for deluge 0.6:
|
||||||
|
#todo : Remove this!, and clean up the rest
|
||||||
for key in TORRENT_KEYS:
|
for key in TORRENT_KEYS:
|
||||||
if not key in status:
|
if not key in status:
|
||||||
status[key] = 0
|
status[key] = 0
|
||||||
|
@ -222,75 +214,14 @@ def get_torrent_status(torrent_id):
|
||||||
status = proxy.get_torrent_status(torrent_id,TORRENT_KEYS)
|
status = proxy.get_torrent_status(torrent_id,TORRENT_KEYS)
|
||||||
return enhance_torrent_status(torrent_id, status)
|
return enhance_torrent_status(torrent_id, status)
|
||||||
|
|
||||||
def get_torrent_list():
|
def get_enhanced_torrent_list(torrent_ids):
|
||||||
"""
|
"""
|
||||||
returns a list of storified-torrent-dicts.
|
returns a list of storified-torrent-dicts.
|
||||||
"""
|
"""
|
||||||
torrent_dict = proxy.get_torrents_status(
|
torrent_dict = proxy.get_torrents_status(torrent_ids, TORRENT_KEYS)
|
||||||
proxy.get_session_state(), 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 torrent_dict.iteritems()]
|
||||||
|
|
||||||
def get_categories(torrent_list):
|
|
||||||
trackers = [(torrent['category'] or 'unknown') for torrent in torrent_list]
|
|
||||||
categories = {}
|
|
||||||
for tracker in trackers:
|
|
||||||
categories[tracker] = categories.get(tracker,0) + 1
|
|
||||||
return categories
|
|
||||||
|
|
||||||
def filter_torrent_state(torrent_list,filter_name):
|
|
||||||
#redesign filters on status field.
|
|
||||||
filters = {
|
|
||||||
'allocating': lambda t: (t.state == 'Allocating'),
|
|
||||||
'checking': lambda t: (t.state == 'Checking'),
|
|
||||||
'downloading': lambda t: (t.state == 'Downloadig'),
|
|
||||||
'seeding':lambda t: (t.state == 'Seeding'),
|
|
||||||
'paused':lambda t: (t.state == 'Paused'),
|
|
||||||
'error':lambda t: (t.state == 'Error'),
|
|
||||||
'queued':lambda t: (t.state == 'Queued'),
|
|
||||||
'traffic':lambda t: (t.download_rate > 0 or t.upload_rate > 0)
|
|
||||||
}
|
|
||||||
filter_func = filters[filter_name]
|
|
||||||
return [t for t in torrent_list if filter_func(t)]
|
|
||||||
|
|
||||||
def get_category_choosers(torrent_list):
|
|
||||||
"""
|
|
||||||
todo: split into 2 parts...
|
|
||||||
"""
|
|
||||||
categories = get_categories(torrent_list)
|
|
||||||
|
|
||||||
filter_tabs = [Storage(title='All (%s)' % len(torrent_list),
|
|
||||||
filter='', category=None)]
|
|
||||||
|
|
||||||
#static filters
|
|
||||||
for title, filter_name in [
|
|
||||||
(_('Allocating'),'allocating') ,
|
|
||||||
(_('Checking'),'checking') ,
|
|
||||||
(_('Downloading'),'downloading') ,
|
|
||||||
(_('Seeding'),'seeding') ,
|
|
||||||
(_('Paused'),'paused'),
|
|
||||||
(_('Error'),'error'),
|
|
||||||
(_('Queued'),'queued'),
|
|
||||||
(_('Traffic'),'traffic')
|
|
||||||
]:
|
|
||||||
title += ' (%s)' % (
|
|
||||||
len(filter_torrent_state(torrent_list, filter_name)), )
|
|
||||||
filter_tabs.append(Storage(title=title, filter=filter_name))
|
|
||||||
|
|
||||||
categories = [x for x in get_categories(torrent_list).iteritems()]
|
|
||||||
categories.sort()
|
|
||||||
|
|
||||||
#trackers:
|
|
||||||
category_tabs = []
|
|
||||||
category_tabs.append(
|
|
||||||
Storage(title=_('Trackers'),category=''))
|
|
||||||
for title,count in categories:
|
|
||||||
category = title
|
|
||||||
title += ' (%s)' % (count, )
|
|
||||||
category_tabs.append(Storage(title=title, category=category))
|
|
||||||
|
|
||||||
return filter_tabs, category_tabs
|
|
||||||
|
|
||||||
def get_newforms_data(form_class):
|
def get_newforms_data(form_class):
|
||||||
"""
|
"""
|
||||||
glue for using web.py and newforms.
|
glue for using web.py and newforms.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue