config plugins

This commit is contained in:
Martijn Voncken 2008-01-15 23:44:30 +00:00
parent 03c9806b40
commit 350cad9f3f
4 changed files with 70 additions and 14 deletions

View File

@ -81,6 +81,20 @@ class WebCfgForm(Form):
def post_save(self):
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):
"config base for deluge-cfg"
@ -90,8 +104,7 @@ class CfgForm(Form):
ws.proxy.set_config(dict(data))
#convenience Fields.
#convenience Input Fields.
class _IntInput(forms.TextInput):
"""
because deluge-floats are edited as ints.
@ -99,6 +112,8 @@ class _IntInput(forms.TextInput):
def render(self, name, value, attrs=None):
try:
value = int(float(value))
if value == -1:
value = _("Unlimited")
except:
pass
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,
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):
def 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:
"""
@ -159,6 +187,11 @@ class config_page:
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)
if form.is_valid():
@ -170,7 +203,7 @@ class config_page:
ws.log.debug(e.message)
return self.render(form , name, error = e.message)
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=''):
return render.config(groups, blocks, f, name , message , error)

View File

@ -34,7 +34,7 @@
import lib.newforms as forms
import config
import utils
from webserver_common import ws
class ServerFolderField(forms.CharField):
@ -54,10 +54,12 @@ class NetworkPorts(config.CfgForm ):
return data
def save(self,data):
data['listen_ports'] = [data['_port_from'] , data['_port_to'] ]
if (data['_port_to'] < data['_port_from']):
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)
@ -121,4 +123,10 @@ class Daemon(config.CfgForm):
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)

View File

@ -289,6 +289,9 @@ form { /*all forms!*/
#config_panel {
height:60%;
float:left;
width:500px;
margin-left:20px;
}
#config_panel th {
font-size: 12px;

View File

@ -222,6 +222,7 @@ class TestIntegration(TestWebUiBase):
self.assertEqual(len(self.torrent_ids), 3)
else:
if ws.env <> '0.6':
#test correctness of existing-list
for url in self.urls:
self.assert_500('/torrent/add',{'url':url,'torrent':None})
@ -353,13 +354,24 @@ class TestIntegration(TestWebUiBase):
,'/torrent/info/' + torrent_id, post = 1)
"""
def testConfig(self):
#0.6 only
if ws.env <> '0.6':
return
#
if True:
cfg = ws.proxy.get_config()
for key in sorted(cfg.keys()):
print key,cfg[key]
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.