update file_prio+bugfixes

This commit is contained in:
Martijn Voncken 2008-02-16 13:56:04 +00:00
parent ed7b75b956
commit 89e2e3ae5c
8 changed files with 121 additions and 60 deletions

View File

@ -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

View File

@ -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 )

View File

@ -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')

View File

@ -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;

View File

@ -1,20 +1,27 @@
$def with (torrent)
<form method="POST" action="/torrent/files/$torrent.id">
<input type="hidden" name="redir" value="$self_url()">
<table width="95%">
<table width="100%">
$altrow(True)
<tr class="tab_$altrow()"><th>$_("File")</th><th>$_("Size")</th></tr>
<tr class="tab_$altrow()">
<th width="100%">$_("File")</th>
<th width="50px">$_("Size")</th>
<th width="50px">$_("Progress")</th></tr>
$for i, file in enumerate(torrent.files):
<tr class="tab_$altrow()" >
<td title="$file['path']">
<input type="checkbox"
$if (torrent.file_priorities[i]):
checked
>
$(crop_left(file["path"], 70))
</td>
<td>$fsize(file["size"])</td></tr>
<td title="$file['path']">
<input type="checkbox" name="file_priorities" id="file_priorities" value="$i"
$if (torrent.file_priorities[i]):
checked
>
$(crop_left(file["path"], 60))
</td>
<td>$fsize(file["size"])</td>
<td align="right">$int(torrent.file_progress[i] * 100)%</td>
</tr>
</table>
<input type="submit" value="$_('Update')" name="submit_files">
</form>
<div class="error">Save/update: Todo</div>

View File

@ -20,14 +20,15 @@ $:render.part_button('GET', '/torrent/move/' + str(torrent.id), _('Move'), 'tang
<h3>$_('Details')</h3>
$:render.tab_meta(torrent)
<h3>$_('Options')</h3>
$:render.tab_options(torrent)
<h3>$_('Files')</h3>
$:render.tab_files(torrent)
<h3>$_('Options')</h3>
$:render.tab_options(torrent)
<br>
<!--

View File

@ -12,7 +12,6 @@ $for torrent in torrent_list:
$if error:
<div class="error">$error</div>
-->
<div class="error">not working yet, but close..</div>
$:form.as_table()

View File

@ -85,14 +85,17 @@ NOT:is_seed,total_download,total_upload,uploaded_memory,queue_pos,user_paused
"""
STATE_MESSAGES = (_("Queued"),
_("Checking"),
_("Connecting"),
_("Downloading Metadata"),
_("Downloading"),
_("Finished"),
_("Seeding"),
_("Allocating"))
STATE_MESSAGES = [
"Allocating",
"Checking",
"Downloading",
"Seeding",
"Paused",
"Error"
]
CONFIG_DEFAULTS = {
"port":8112,