mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-03 23:18:40 +00:00
torrent_add:options
This commit is contained in:
parent
b0a9bf49fe
commit
0b306717b6
7 changed files with 69 additions and 30 deletions
|
@ -37,6 +37,7 @@ from render import render
|
||||||
from lib.webpy022.http import seeother
|
from lib.webpy022.http import seeother
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import utils
|
||||||
|
|
||||||
groups = []
|
groups = []
|
||||||
blocks = forms.utils.datastructures.SortedDict()
|
blocks = forms.utils.datastructures.SortedDict()
|
||||||
|
@ -90,18 +91,7 @@ class config_page:
|
||||||
@deco.deluge_page
|
@deco.deluge_page
|
||||||
def POST(self,name):
|
def POST(self,name):
|
||||||
|
|
||||||
form_class = self.get_form_class(name)
|
form_data = utils.get_newforms_data(form_class)
|
||||||
fields = form_class.base_fields.keys()
|
|
||||||
form_data = web.Storage()
|
|
||||||
vars = web.input()
|
|
||||||
for field in fields:
|
|
||||||
form_data[field] = vars.get(field)
|
|
||||||
#DIRTY HACK: (for multiple-select)
|
|
||||||
if isinstance(form_class.base_fields[field],
|
|
||||||
forms.MultipleChoiceField):
|
|
||||||
form_data[field] = web.input(**{field:[]})[field]
|
|
||||||
#/DIRTY HACK
|
|
||||||
|
|
||||||
form = form_class(form_data)
|
form = form_class(form_data)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
ws.log.debug('save config %s' % form_data)
|
ws.log.debug('save config %s' % form_data)
|
||||||
|
|
|
@ -10,9 +10,14 @@ from newforms.forms import BoundField
|
||||||
|
|
||||||
import sys, os
|
import sys, os
|
||||||
|
|
||||||
|
|
||||||
import webpy022 as web #todo:remove this dependency.
|
import webpy022 as web #todo:remove this dependency.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Form
|
#Form
|
||||||
class FilteredForm(newforms.Form):
|
class FilteredForm(newforms.Form):
|
||||||
"""
|
"""
|
||||||
|
@ -99,7 +104,6 @@ class Form(FilteredForm):
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
#convenience Input Fields.
|
#convenience Input Fields.
|
||||||
class CheckBox(newforms.BooleanField):
|
class CheckBox(newforms.BooleanField):
|
||||||
"Non Required BooleanField,why the f is it required by default?"
|
"Non Required BooleanField,why the f is it required by default?"
|
||||||
|
|
|
@ -93,7 +93,7 @@ $for torrent in torrent_list:
|
||||||
<td>$fsize(torrent.total_size)</td>
|
<td>$fsize(torrent.total_size)</td>
|
||||||
<td class="progress_bar">
|
<td class="progress_bar">
|
||||||
<div class="progress_bar_outer">
|
<div class="progress_bar_outer">
|
||||||
<div class="progress_bar" style="width:$(torrent.progress)%">
|
<div class="progress_bar" style="width:$(torrent.progress)%;overflow:hidden">
|
||||||
$torrent.message $int(torrent.progress) %
|
$torrent.message $int(torrent.progress) %
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
$def with (add_form, options_form)
|
$def with (add_form, options_form, error)
|
||||||
$: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">
|
||||||
<input type="hidden" name="redir" value="$get('redir')">
|
<input type="hidden" name="redir" value="$get('redir')">
|
||||||
|
|
||||||
|
|
||||||
|
$if error:
|
||||||
|
<div class="error">$error</div>
|
||||||
<div id="torrent_add" >
|
<div id="torrent_add" >
|
||||||
<table>
|
<table>
|
||||||
$:add_form.as_table()
|
$:add_form.as_table()
|
||||||
|
@ -83,10 +85,17 @@ function toggle_options(){
|
||||||
el = document.getElementById("torrent_add_options");
|
el = document.getElementById("torrent_add_options");
|
||||||
if (el.style.display == "block"){
|
if (el.style.display == "block"){
|
||||||
el.style.display = "none";
|
el.style.display = "none";
|
||||||
|
setCookie("torrent_add_options","hide");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
el.style.display = "block";
|
el.style.display = "block";
|
||||||
|
setCookie("torrent_add_options","show");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getCookie("torrent_add_options") == "show") {
|
||||||
|
el = document.getElementById("torrent_add_options");
|
||||||
|
el.style.display = "block";
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
$:render.footer()
|
$:render.footer()
|
||||||
|
|
|
@ -30,10 +30,11 @@
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
#
|
#
|
||||||
from webserver_common import ws
|
from webserver_common import ws
|
||||||
from utils import *
|
import utils
|
||||||
from render import render, error_page
|
from render import render, error_page
|
||||||
import page_decorators as deco
|
import page_decorators as deco
|
||||||
import lib.newforms_plus as forms
|
import lib.newforms_plus as forms
|
||||||
|
import lib.webpy022 as web
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
class OptionsForm(forms.Form):
|
class OptionsForm(forms.Form):
|
||||||
|
@ -57,19 +58,27 @@ class OptionsForm(forms.Form):
|
||||||
return ws.proxy.get_config()
|
return ws.proxy.get_config()
|
||||||
|
|
||||||
class AddForm(forms.Form):
|
class AddForm(forms.Form):
|
||||||
url = forms.CharField(label=_("Url"),
|
url = forms.CharField(label=_("Url"), required=False,
|
||||||
widget=forms.TextInput(attrs={'size':60}))
|
widget=forms.TextInput(attrs={'size':60}))
|
||||||
torrent = forms.CharField(label=_("Upload torrent"),
|
torrent = forms.CharField(label=_("Upload torrent"), required=False,
|
||||||
widget=forms.FileInput(attrs={'size':60}))
|
widget=forms.FileInput(attrs={'size':60}))
|
||||||
hash = forms.CharField(label=_("Hash"),
|
hash = forms.CharField(label=_("Hash"), required=False,
|
||||||
widget=forms.TextInput(attrs={'size':60}))
|
widget=forms.TextInput(attrs={'size':60}))
|
||||||
ret = forms.CheckBox(_('Add more'))
|
ret = forms.CheckBox(_('Add more'))
|
||||||
|
|
||||||
class torrent_add:
|
class torrent_add:
|
||||||
|
|
||||||
|
def add_page(self,error = None):
|
||||||
|
form_data = utils.get_newforms_data(AddForm)
|
||||||
|
options_data = None
|
||||||
|
if error:
|
||||||
|
options_data = utils.get_newforms_data(OptionsForm)
|
||||||
|
return render.torrent_add(AddForm(form_data),OptionsForm(options_data), error)
|
||||||
|
|
||||||
@deco.deluge_page
|
@deco.deluge_page
|
||||||
def GET(self, name):
|
def GET(self, name):
|
||||||
return render.torrent_add(AddForm(),OptionsForm())
|
return self.add_page()
|
||||||
|
|
||||||
|
|
||||||
@deco.check_session
|
@deco.check_session
|
||||||
def POST(self, name):
|
def POST(self, name):
|
||||||
|
@ -80,8 +89,14 @@ class torrent_add:
|
||||||
*posting of data as string(for greasemonkey-private)
|
*posting of data as string(for greasemonkey-private)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
vars = web.input(url = None, torrent = {})
|
options = dict(utils.get_newforms_data(OptionsForm))
|
||||||
|
options_form = OptionsForm(options)
|
||||||
|
if not options_form.is_valid():
|
||||||
|
print self.add_page(error = _("Error in torrent options."))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
vars = web.input(url = None, torrent = {})
|
||||||
torrent_name = None
|
torrent_name = None
|
||||||
torrent_data = None
|
torrent_data = None
|
||||||
if vars.torrent.filename:
|
if vars.torrent.filename:
|
||||||
|
@ -89,14 +104,17 @@ class torrent_add:
|
||||||
torrent_data = vars.torrent.file.read()
|
torrent_data = vars.torrent.file.read()
|
||||||
|
|
||||||
if vars.url and torrent_name:
|
if vars.url and torrent_name:
|
||||||
error_page(_("Choose an url or a torrent, not both."))
|
#error_page(_("Choose an url or a torrent, not both."))
|
||||||
|
print self.add_page(error = _("Choose an url or a torrent, not both."))
|
||||||
|
return
|
||||||
if vars.url:
|
if vars.url:
|
||||||
ws.proxy.add_torrent_url(vars.url)
|
ws.proxy.add_torrent_url(vars.url, options)
|
||||||
do_redirect()
|
utils.do_redirect()
|
||||||
elif torrent_name:
|
elif torrent_name:
|
||||||
data_b64 = base64.b64encode(torrent_data)
|
data_b64 = base64.b64encode(torrent_data)
|
||||||
#b64 because of strange bug-reports related to binary data
|
#b64 because of strange bug-reports related to binary data
|
||||||
ws.proxy.add_torrent_filecontent(vars.torrent.filename, data_b64)
|
ws.proxy.add_torrent_filecontent(vars.torrent.filename, data_b64, options)
|
||||||
do_redirect()
|
utils.do_redirect()
|
||||||
else:
|
else:
|
||||||
error_page(_("no data, press back button and try again"))
|
print self.add_page(error = _("No data"))
|
||||||
|
return
|
||||||
|
|
|
@ -296,6 +296,24 @@ def get_category_choosers(torrent_list):
|
||||||
|
|
||||||
return filter_tabs, category_tabs
|
return filter_tabs, category_tabs
|
||||||
|
|
||||||
|
def get_newforms_data(form_class):
|
||||||
|
"""
|
||||||
|
glue for using web.py and newforms.
|
||||||
|
returns a storified dict with name/value of the post-data.
|
||||||
|
"""
|
||||||
|
import lib.newforms_plus as forms
|
||||||
|
fields = form_class.base_fields.keys()
|
||||||
|
form_data = web.Storage()
|
||||||
|
vars = web.input()
|
||||||
|
for field in fields:
|
||||||
|
form_data[field] = vars.get(field)
|
||||||
|
#DIRTY HACK: (for multiple-select)
|
||||||
|
if isinstance(form_class.base_fields[field],
|
||||||
|
forms.MultipleChoiceField):
|
||||||
|
form_data[field] = web.input(**{field:[]})[field]
|
||||||
|
#/DIRTY HACK
|
||||||
|
return form_data
|
||||||
|
|
||||||
#/utils
|
#/utils
|
||||||
|
|
||||||
class WebUiError(Exception):
|
class WebUiError(Exception):
|
||||||
|
|
|
@ -178,7 +178,7 @@ class Ws:
|
||||||
|
|
||||||
|
|
||||||
#MONKEY PATCH, TODO->REMOVE!!!
|
#MONKEY PATCH, TODO->REMOVE!!!
|
||||||
def add_torrent_filecontent(name , data_b64):
|
def add_torrent_filecontent(name , data_b64, options):
|
||||||
self.log.debug('monkeypatched add_torrent_filecontent:%s,len(data:%s))' %
|
self.log.debug('monkeypatched add_torrent_filecontent:%s,len(data:%s))' %
|
||||||
(name , len(data_b64)))
|
(name , len(data_b64)))
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ class Ws:
|
||||||
f.write(base64.b64decode(data_b64))
|
f.write(base64.b64decode(data_b64))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self.proxy.add_torrent_file([filename])
|
self.proxy.add_torrent_file([filename] , options)
|
||||||
|
|
||||||
self.proxy.add_torrent_filecontent = add_torrent_filecontent
|
self.proxy.add_torrent_filecontent = add_torrent_filecontent
|
||||||
self.log.debug('cfg-file %s' % self.config_file)
|
self.log.debug('cfg-file %s' % self.config_file)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue