mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-14 21:44:28 +00:00
config plugins
This commit is contained in:
parent
03c9806b40
commit
350cad9f3f
@ -81,6 +81,20 @@ class WebCfgForm(Form):
|
|||||||
def post_save(self):
|
def post_save(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class CookieCfgForm(Form):
|
||||||
|
"config base for webui"
|
||||||
|
def initial_data(self):
|
||||||
|
return ws.config
|
||||||
|
|
||||||
|
def save(self, data):
|
||||||
|
ws.config.update(data)
|
||||||
|
ws.save_config()
|
||||||
|
self.post_save()
|
||||||
|
|
||||||
|
def post_save(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CfgForm(Form):
|
class CfgForm(Form):
|
||||||
"config base for deluge-cfg"
|
"config base for deluge-cfg"
|
||||||
@ -90,8 +104,7 @@ class CfgForm(Form):
|
|||||||
ws.proxy.set_config(dict(data))
|
ws.proxy.set_config(dict(data))
|
||||||
|
|
||||||
|
|
||||||
#convenience Fields.
|
#convenience Input Fields.
|
||||||
|
|
||||||
class _IntInput(forms.TextInput):
|
class _IntInput(forms.TextInput):
|
||||||
"""
|
"""
|
||||||
because deluge-floats are edited as ints.
|
because deluge-floats are edited as ints.
|
||||||
@ -99,6 +112,8 @@ class _IntInput(forms.TextInput):
|
|||||||
def render(self, name, value, attrs=None):
|
def render(self, name, value, attrs=None):
|
||||||
try:
|
try:
|
||||||
value = int(float(value))
|
value = int(float(value))
|
||||||
|
if value == -1:
|
||||||
|
value = _("Unlimited")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return forms.TextInput.render(self, name, value, attrs)
|
return forms.TextInput.render(self, name, value, attrs)
|
||||||
@ -125,10 +140,23 @@ class DelugeInt(forms.IntegerField):
|
|||||||
forms.IntegerField.__init__(self, label=label, min_value=-1,
|
forms.IntegerField.__init__(self, label=label, min_value=-1,
|
||||||
max_value=sys.maxint, widget=_IntInput, **kwargs)
|
max_value=sys.maxint, widget=_IntInput, **kwargs)
|
||||||
|
|
||||||
|
def clean(self, value):
|
||||||
|
if str(value).lower() == _('Unlimited').lower():
|
||||||
|
value = -1
|
||||||
|
return int(forms.IntegerField.clean(self, value))
|
||||||
|
|
||||||
class DelugeFloat(DelugeInt):
|
class DelugeFloat(DelugeInt):
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
return int(DelugeInt.clean(self, value))
|
return int(DelugeInt.clean(self, value))
|
||||||
|
|
||||||
|
class MultipleChoice(forms.MultipleChoiceField):
|
||||||
|
#temp/test
|
||||||
|
def __init__(self, label, choices, **kwargs):
|
||||||
|
forms.MultipleChoiceField.__init__(self, label=label, choices=choices,
|
||||||
|
widget=forms.CheckboxSelectMultiple, required=False)
|
||||||
|
|
||||||
|
|
||||||
|
#/fields
|
||||||
|
|
||||||
class config_page:
|
class config_page:
|
||||||
"""
|
"""
|
||||||
@ -159,6 +187,11 @@ class config_page:
|
|||||||
vars = web.input()
|
vars = web.input()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
form_data[field] = vars.get(field)
|
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():
|
||||||
@ -170,7 +203,7 @@ class config_page:
|
|||||||
ws.log.debug(e.message)
|
ws.log.debug(e.message)
|
||||||
return self.render(form , name, error = e.message)
|
return self.render(form , name, error = e.message)
|
||||||
else:
|
else:
|
||||||
return self.render(form , name, error= _('Please correct the errors above and try again'))
|
return self.render(form , name, error= _('Correct the errors above and try again'))
|
||||||
|
|
||||||
def render(self, f , name , message = '' , error=''):
|
def render(self, f , name , message = '' , error=''):
|
||||||
return render.config(groups, blocks, f, name , message , error)
|
return render.config(groups, blocks, f, name , message , error)
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
import lib.newforms as forms
|
import lib.newforms as forms
|
||||||
import config
|
import config
|
||||||
import utils
|
import utils
|
||||||
|
from webserver_common import ws
|
||||||
|
|
||||||
|
|
||||||
class ServerFolderField(forms.CharField):
|
class ServerFolderField(forms.CharField):
|
||||||
@ -54,10 +54,12 @@ class NetworkPorts(config.CfgForm ):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def save(self,data):
|
def save(self,data):
|
||||||
data['listen_ports'] = [data['_port_from'] , data['_port_to'] ]
|
|
||||||
if (data['_port_to'] < data['_port_from']):
|
if (data['_port_to'] < data['_port_from']):
|
||||||
raise ValidationError('"Port from" must be greater than "Port to"')
|
raise ValidationError('"Port from" must be greater than "Port to"')
|
||||||
config.CfgForm.save()
|
data['listen_ports'] = [data['_port_from'] , data['_port_to'] ]
|
||||||
|
del(data['_port_from'])
|
||||||
|
del(data['_port_to'])
|
||||||
|
config.CfgForm.save(self, data)
|
||||||
|
|
||||||
config.register_block('network','ports', NetworkPorts)
|
config.register_block('network','ports', NetworkPorts)
|
||||||
|
|
||||||
@ -121,4 +123,10 @@ class Daemon(config.CfgForm):
|
|||||||
|
|
||||||
config.register_block('deluge','daemon', Daemon)
|
config.register_block('deluge','daemon', Daemon)
|
||||||
|
|
||||||
|
class Plugins(config.CfgForm):
|
||||||
|
title = _("Enabled Plugins")
|
||||||
|
|
||||||
|
_choices = [(p,p) for p in ws.proxy.get_available_plugins()]
|
||||||
|
enabled_plugins = config.MultipleChoice(_(""), _choices)
|
||||||
|
|
||||||
|
config.register_block('deluge','plugins', Plugins)
|
||||||
|
@ -289,6 +289,9 @@ form { /*all forms!*/
|
|||||||
|
|
||||||
#config_panel {
|
#config_panel {
|
||||||
height:60%;
|
height:60%;
|
||||||
|
float:left;
|
||||||
|
width:500px;
|
||||||
|
margin-left:20px;
|
||||||
}
|
}
|
||||||
#config_panel th {
|
#config_panel th {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
@ -222,9 +222,10 @@ class TestIntegration(TestWebUiBase):
|
|||||||
self.assertEqual(len(self.torrent_ids), 3)
|
self.assertEqual(len(self.torrent_ids), 3)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
#test correctness of existing-list
|
if ws.env <> '0.6':
|
||||||
for url in self.urls:
|
#test correctness of existing-list
|
||||||
self.assert_500('/torrent/add',{'url':url,'torrent':None})
|
for url in self.urls:
|
||||||
|
self.assert_500('/torrent/add',{'url':url,'torrent':None})
|
||||||
|
|
||||||
def testPauseResume(self):
|
def testPauseResume(self):
|
||||||
#pause all
|
#pause all
|
||||||
@ -353,13 +354,24 @@ class TestIntegration(TestWebUiBase):
|
|||||||
,'/torrent/info/' + torrent_id, post = 1)
|
,'/torrent/info/' + torrent_id, post = 1)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def testConfig(self):
|
||||||
|
#0.6 only
|
||||||
|
if ws.env <> '0.6':
|
||||||
|
return
|
||||||
|
#
|
||||||
|
import WebUi.config_tabs_webui #auto registers
|
||||||
|
import WebUi.config_tabs_deluge #auto registers
|
||||||
|
import WebUi.config as config
|
||||||
|
|
||||||
|
for name in config.blocks:
|
||||||
|
self.assert_exists("/config/%s" % name)
|
||||||
|
|
||||||
|
#todo->post page with current values.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
if True:
|
|
||||||
cfg = ws.proxy.get_config()
|
|
||||||
for key in sorted(cfg.keys()):
|
|
||||||
print key,cfg[key]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user