torrent_add:options ui

This commit is contained in:
Martijn Voncken 2008-02-11 19:09:23 +00:00
parent 9df4492083
commit 8f8a6e41aa
8 changed files with 50 additions and 53 deletions

View File

@ -1,8 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# deluge_webserver.py
#
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com> # Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify

View File

@ -58,9 +58,9 @@ class FilteredForm(newforms.Form):
output.append(str_hidden) output.append(str_hidden)
return u'\n'.join(output) return u'\n'.join(output)
def as_table(self , filter = None): def as_table(self , filter = None): #add class="newforms"
"Returns this form rendered as HTML <tr>s -- excluding the <table></table>." "Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
return self._html_output_filtered(u'<tr><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False, filter) return self._html_output_filtered(u'<tr><th class="newforms">%(label)s</th><td class="newforms">%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False, filter)
def as_ul(self, filter = None): def as_ul(self, filter = None):
"Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."
@ -70,7 +70,7 @@ class FilteredForm(newforms.Form):
"Returns this form rendered as HTML <p>s." "Returns this form rendered as HTML <p>s."
return self._html_output_filtered(u'<p>%(label)s %(field)s%(help_text)s</p>', u'<p>%s</p>', '</p>', u' %s', True, filter) return self._html_output_filtered(u'<p>%(label)s %(field)s%(help_text)s</p>', u'<p>%s</p>', '</p>', u' %s', True, filter)
class Form(newforms.Form): class Form(FilteredForm):
info = "" info = ""
title = "No Title" title = "No Title"
def __init__(self,data = None): def __init__(self,data = None):

View File

@ -54,6 +54,9 @@ import os
from json_api import json_api from json_api import json_api
#special/complex pages:
from torrent_add import torrent_add
#routing: #routing:
urls = ( urls = (
"/login", "login", "/login", "login",
@ -176,41 +179,6 @@ class torrent_reannounce:
ws.proxy.force_reannounce([torrent_id]) ws.proxy.force_reannounce([torrent_id])
do_redirect() do_redirect()
class torrent_add:
@deco.deluge_page
def GET(self, name):
return render.torrent_add()
@deco.check_session
def POST(self, name):
"""
allows:
*posting of url
*posting file-upload
*posting of data as string(for greasemonkey-private)
"""
vars = web.input(url = None, torrent = {})
torrent_name = None
torrent_data = None
if vars.torrent.filename:
torrent_name = vars.torrent.filename
torrent_data = vars.torrent.file.read()
if vars.url and torrent_name:
error_page(_("Choose an url or a torrent, not both."))
if vars.url:
ws.proxy.add_torrent_url(vars.url)
do_redirect()
elif torrent_name:
data_b64 = base64.b64encode(torrent_data)
#b64 because of strange bug-reports related to binary data
ws.proxy.add_torrent_filecontent(vars.torrent.filename, data_b64)
do_redirect()
else:
error_page(_("no data."))
class remote_torrent_add: class remote_torrent_add:
""" """
For use in remote scripts etc. For use in remote scripts etc.

View File

@ -48,6 +48,9 @@ class subclassed_render(object):
self.apply_cfg() self.apply_cfg()
def apply_cfg(self): def apply_cfg(self):
if not hasattr(ws,"config"):
print "render.py: WARNING,no config"
return
cache = ws.config.get('cache_templates') cache = ws.config.get('cache_templates')
self.base_template = template.render( self.base_template = template.render(
os.path.join(ws.webui_path, 'templates/deluge/'), os.path.join(ws.webui_path, 'templates/deluge/'),
@ -79,8 +82,11 @@ def category_tabs(torrent_list):
def template_crop(text, end): def template_crop(text, end):
try:
if len(text) > end: if len(text) > end:
return text[0:end - 3] + '...' return text[0:end - 3] + '...'
except:
return "[ERROR NOT A STRING:(%s)]" % text
return text return text
def template_sort_head(id,name): def template_sort_head(id,name):

View File

@ -318,6 +318,12 @@ ul.errorlist {
#torrent_list { #torrent_list {
-moz-border-radius:7px; -moz-border-radius:7px;
} }
th.newforms {
font-size: 12px;
text-align:right;
color:#FFFFFF;
}
/* Hides from IE-mac \*/ * html .clearfix {height: 1%;} .clearfix {display: block;} /* End hide from IE-mac */ /* Hides from IE-mac \*/ * html .clearfix {height: 1%;} .clearfix {display: block;} /* End hide from IE-mac */

View File

@ -1,3 +1,4 @@
$def with (add_form)
$:render.header(_("Add Torrent")) $:render.header(_("Add Torrent"))
<div class="panel"> <div class="panel">
<form method="POST" action="/torrent/add" ENCTYPE="multipart/form-data"> <form method="POST" action="/torrent/add" ENCTYPE="multipart/form-data">
@ -27,6 +28,28 @@ $if get_config('add_another'):
<input type="submit" name="submit" <input type="submit" name="submit"
value="$_('Submit')" class="form_input"> value="$_('Submit')" class="form_input">
<h2>Options</h2>
<div class="error">Options are not used yet!</div>
<h3>$_("Allocation/Location")</h3>
<table>
$:add_form.as_table(["download_location", "compact_allocation"])
</table>
<h3>$_("BandWidth")</h3>
<table>
$:add_form.as_table(["max_download_speed_per_torrent", "max_upload_speed_per_torrent", "max_connections_per_torrent", "max_upload_slots_per_torrent"])
</table>
</td>
<h3>$_("General")</h3>
<table>
$:add_form.as_table(["prioritize_first_last_pieces", "add_paused", "default_private"])
</table>
</div> </div>
</div> </div>
</form> </form>

View File

@ -68,14 +68,14 @@ start = time.time()
torrent_ids = ws.proxy.get_session_state() #Syc-api. torrent_ids = ws.proxy.get_session_state() #Syc-api.
torrent_dict = {} torrent_dict = {}
for id in torrent_ids: for id in torrent_ids:
async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, []) async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, ["name"])
async_proxy.force_call(block=True) async_proxy.force_call(block=True)
print "Async-list:",time.time() - start print "Async-list:",time.time() - start
print torrent_dict print torrent_dict[torrent_ids[0]].keys()
print torrent_dict[torrent_ids[0]]["name"]
print sorted(torrent_list[0].keys())

View File

@ -237,16 +237,12 @@ def get_torrent_list():
torrent_ids = ws.proxy.get_session_state() #Syc-api. torrent_ids = ws.proxy.get_session_state() #Syc-api.
torrent_dict = {} torrent_dict = {}
for id in torrent_ids: for id in torrent_ids:
ws.async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, []) ws.async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id,
TORRENT_KEYS)
ws.async_proxy.force_call(block=True) ws.async_proxy.force_call(block=True)
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): def get_categories(torrent_list):
trackers = [(torrent['category'] or 'unknown') for torrent in torrent_list] trackers = [(torrent['category'] or 'unknown') for torrent in torrent_list]
categories = {} categories = {}