reduce code in /index

This commit is contained in:
Martijn Voncken 2008-03-24 22:02:27 +00:00
parent f8cbcd9184
commit a9238995ce
1 changed files with 11 additions and 19 deletions

View File

@ -127,31 +127,22 @@ 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 ,state=None , tracker=None,keyword=None) vars = web.input(sort=None, order=None)
organize_filters = {} organize_filters = {}
if 'Organize' in proxy.get_enabled_plugins(): if 'Organize' in proxy.get_enabled_plugins():
filter_dict = {} filter_dict = {}
#organize-filters #organize-filters
#todo: DRY (in less lines of code) for filter_name in ["state","tracker","keyword"]:
if vars.state: value = getattr(web.input(**{filter_name:None}), filter_name)
filter_dict['state'] = vars.state if value and value <> "All":
setcookie("state", vars.state) filter_dict[filter_name] = value
else: setcookie(filter_name, vars.state)
setcookie("filter", "") else:
setcookie(filter_name, "")
if vars.tracker:
filter_dict['tracker'] = vars.tracker
setcookie("tracker", vars.tracker)
else:
setcookie("tracker", "")
if vars.keyword:
filter_dict['keyword'] = vars.keyword
setcookie("keyword", vars.keyword)
else:
setcookie("keyword", "")
log.debug(filter_dict)
torrent_ids = proxy.organize_get_session_state(filter_dict) torrent_ids = proxy.organize_get_session_state(filter_dict)
organize_filters = Storage(proxy.organize_all_filter_items()) organize_filters = Storage(proxy.organize_all_filter_items())
@ -174,6 +165,7 @@ class index:
setcookie("sort", vars.sort) setcookie("sort", vars.sort)
return render.index(torrent_list, organize_filters) return render.index(torrent_list, organize_filters)
class torrent_info: class torrent_info:
@deco.deluge_page @deco.deluge_page
@deco.auto_refreshed @deco.auto_refreshed