config pages
This commit is contained in:
parent
20cce5aa68
commit
03c9806b40
|
@ -37,6 +37,7 @@ import lib.webpy022 as web
|
|||
from webserver_common import ws
|
||||
from render import render
|
||||
from lib.webpy022.http import seeother
|
||||
import sys
|
||||
|
||||
groups = []
|
||||
blocks = forms.utils.datastructures.SortedDict()
|
||||
|
@ -85,8 +86,48 @@ class CfgForm(Form):
|
|||
"config base for deluge-cfg"
|
||||
def initial_data(self):
|
||||
return ws.proxy.get_config()
|
||||
def save(data):
|
||||
ws.proxy.set_config(data)
|
||||
def save(self, data):
|
||||
ws.proxy.set_config(dict(data))
|
||||
|
||||
|
||||
#convenience Fields.
|
||||
|
||||
class _IntInput(forms.TextInput):
|
||||
"""
|
||||
because deluge-floats are edited as ints.
|
||||
"""
|
||||
def render(self, name, value, attrs=None):
|
||||
try:
|
||||
value = int(float(value))
|
||||
except:
|
||||
pass
|
||||
return forms.TextInput.render(self, name, value, attrs)
|
||||
|
||||
class CheckBox(forms.BooleanField):
|
||||
"Non Required ChoiceField"
|
||||
def __init__(self,label, **kwargs):
|
||||
forms.BooleanField.__init__(self,label=label,required=False,**kwargs)
|
||||
|
||||
class IntCombo(forms.ChoiceField):
|
||||
"""
|
||||
choices are the display-values
|
||||
returns int for the chosen display-value.
|
||||
"""
|
||||
def __init__(self, label, choices, **kwargs):
|
||||
forms.ChoiceField.__init__(self, label=label, choices=enumerate(choices)
|
||||
, **kwargs)
|
||||
|
||||
def clean(self, value):
|
||||
return int(forms.ChoiceField.clean(self, value))
|
||||
|
||||
class DelugeInt(forms.IntegerField):
|
||||
def __init__(self, label , **kwargs):
|
||||
forms.IntegerField.__init__(self, label=label, min_value=-1,
|
||||
max_value=sys.maxint, widget=_IntInput, **kwargs)
|
||||
|
||||
class DelugeFloat(DelugeInt):
|
||||
def clean(self, value):
|
||||
return int(DelugeInt.clean(self, value))
|
||||
|
||||
|
||||
class config_page:
|
||||
|
@ -129,7 +170,7 @@ class config_page:
|
|||
ws.log.debug(e.message)
|
||||
return self.render(form , name, error = e.message)
|
||||
else:
|
||||
return self.render(form , name, _('Please correct errors and try again'))
|
||||
return self.render(form , name, error= _('Please correct the errors above and try again'))
|
||||
|
||||
def render(self, f , name , message = '' , error=''):
|
||||
return render.config(groups, blocks, f, name , message , error)
|
||||
|
|
|
@ -36,11 +36,89 @@ import config
|
|||
import utils
|
||||
|
||||
|
||||
class BandWidth(config.CfgForm):
|
||||
title = _("Bandwidth")
|
||||
up = forms.IntegerField(label = "TODO")
|
||||
|
||||
config.register_block('deluge','bandwidth',BandWidth)
|
||||
class ServerFolderField(forms.CharField):
|
||||
pass
|
||||
|
||||
|
||||
class NetworkPorts(config.CfgForm ):
|
||||
title = _("Ports")
|
||||
info = _("Restart daemon after changing these values.")
|
||||
_port_from = forms.IntegerField(_("From"))
|
||||
_port_to = forms.IntegerField(_("To"))
|
||||
random_port = config.CheckBox(_("Random"))
|
||||
|
||||
def initial_data(self):
|
||||
data = config.CfgForm.initial_data(self)
|
||||
data['_port_from'] , data['_port_to'] = data['listen_ports']
|
||||
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()
|
||||
|
||||
config.register_block('network','ports', NetworkPorts)
|
||||
|
||||
class NetworkExtra(config.CfgForm ):
|
||||
title = _("Extra's")
|
||||
dht = config.CheckBox(_("Mainline DHT"))
|
||||
upnp = config.CheckBox(_("UpNP"))
|
||||
natpmp = config.CheckBox(_("NAT-PMP"))
|
||||
utpex = config.CheckBox(_("Peer-Exchange"))
|
||||
lsd = config.CheckBox(_("LSD"))
|
||||
|
||||
config.register_block('network','extra', NetworkExtra)
|
||||
|
||||
class NetworkEnc(config.CfgForm ):
|
||||
title = _("Encryption")
|
||||
|
||||
_enc_choices = [_("Forced"),_("Enabled"),_("Disabled")]
|
||||
_level_choices = [_("Handshake"), _("Full") , _("Either")]
|
||||
|
||||
enc_in_policy = config.IntCombo(_("Inbound"), _enc_choices)
|
||||
enc_out_policy = config.IntCombo(_("Outbound"), _enc_choices)
|
||||
enc_level = config.IntCombo(_("Level"), _level_choices)
|
||||
enc_prefer_rc4 = config.CheckBox("Prefer to encrypt entire stream")
|
||||
|
||||
config.register_block('network','encryption', NetworkEnc)
|
||||
|
||||
|
||||
class BandwithGlobal(config.CfgForm):
|
||||
title = _("Global")
|
||||
info = _("-1 = Unlimited")
|
||||
max_connections_global = config.DelugeInt(_("Maximum Connections"))
|
||||
max_download_speed = config.DelugeFloat(_("Maximum Download Speed (Kib/s)"))
|
||||
max_upload_speed = config.DelugeFloat(_("Maximum Upload Speed (Kib/s)"))
|
||||
max_upload_slots_global = config.DelugeInt(_("Maximum Upload Slots"))
|
||||
|
||||
config.register_block('bandwidth','global', BandwithGlobal)
|
||||
|
||||
class BandwithTorrent(config.CfgForm):
|
||||
title = _("Per Torrent")
|
||||
info = _("-1 = Unlimited")
|
||||
max_connections_per_torrent = config.DelugeInt(_("Maximum Connections"))
|
||||
max_upload_slots_per_torrent = config.DelugeInt(_("Maximum Upload Slots"))
|
||||
|
||||
config.register_block('bandwidth','torrent', BandwithTorrent)
|
||||
|
||||
|
||||
class Download(config.CfgForm):
|
||||
title = _("Download")
|
||||
download_location = ServerFolderField(_("Store all downoads in"))
|
||||
torrentfiles_location = ServerFolderField(_("Save .torrent files to"))
|
||||
autoadd_location = ServerFolderField(_("Auto Add folder") , required=False)
|
||||
compact_allocation = config.CheckBox(_('Use Compact Allocation'))
|
||||
prioritize_first_last_pieces = config.CheckBox(_('Prioritize first and last pieces'))
|
||||
|
||||
config.register_block('deluge','download', Download)
|
||||
|
||||
class Daemon(config.CfgForm):
|
||||
title = _("Daemon")
|
||||
daemon_port = forms.IntegerField(_("Port"))
|
||||
allow_remote = config.CheckBox(_("Allow Remote Connections"))
|
||||
|
||||
config.register_block('deluge','daemon', Daemon)
|
||||
|
||||
|
||||
|
|
|
@ -41,42 +41,40 @@ from webserver_common import ws
|
|||
class Template(config.WebCfgForm):
|
||||
title = _("Template")
|
||||
|
||||
template = forms.ChoiceField( label=_("Template"),
|
||||
choices = [(t,t) for t in ws.get_templates()])
|
||||
_templates = [(t,t) for t in ws.get_templates()]
|
||||
_button_choices = [_('Text and image'), _('Image Only'), _('Text Only')]
|
||||
|
||||
button_style = forms.ChoiceField( label=_("Button style"),
|
||||
choices=[
|
||||
(0,_('Text and image')),
|
||||
(1, _('Image Only')),
|
||||
(2, _('Text Only'))])
|
||||
|
||||
cache_templates = forms.BooleanField(label = _("Cache templates"),
|
||||
required=False)
|
||||
template = forms.ChoiceField( label=_("Template"), choices = _templates)
|
||||
button_style = config.IntCombo(_("Button style"),_button_choices)
|
||||
cache_templates = config.CheckBox(_("Cache templates"))
|
||||
|
||||
def post_save(self):
|
||||
render.apply_cfg()
|
||||
|
||||
|
||||
class Server(config.WebCfgForm):
|
||||
info = _("Restart webui after changing these values.")
|
||||
title = _("Server")
|
||||
|
||||
port = forms.IntegerField(label = _("Port"),min_value=80)
|
||||
use_https = forms.BooleanField(label = _("Use https") , required=False)
|
||||
use_https = config.CheckBox(_("Use https"))
|
||||
|
||||
def post_save(self):
|
||||
pass
|
||||
#raise forms.ValidationError(_("Manually restart server to apply these changes."))
|
||||
|
||||
class Password(config.Form):
|
||||
title = _("Password")
|
||||
old_pwd = forms.CharField(widget = forms.PasswordInput
|
||||
,label = _("Current Password"), required=False)
|
||||
,label = _("Current Password"))
|
||||
|
||||
new1 = forms.CharField(widget = forms.PasswordInput
|
||||
,label = _("New Password"), required=False)
|
||||
,label = _("New Password"))
|
||||
|
||||
new2 = forms.CharField(widget = forms.PasswordInput
|
||||
,label = _("New Password (Confirm)"), required=False)
|
||||
,label = _("New Password (Confirm)"))
|
||||
|
||||
def initial_data(self):
|
||||
return {}
|
||||
return None
|
||||
|
||||
def save(self,data):
|
||||
if not ws.check_pwd(data.old_pwd):
|
||||
|
@ -87,8 +85,10 @@ class Password(config.Form):
|
|||
ws.update_pwd(data.new1)
|
||||
ws.save_config()
|
||||
|
||||
|
||||
def post_save(self):
|
||||
utils.end_session()
|
||||
#raise forms.ValidationError(_("Password changed,please login again"))
|
||||
|
||||
config.register_block('webui','template', Template)
|
||||
config.register_block('webui','server',Server)
|
||||
|
|
|
@ -133,7 +133,8 @@ template.Template.globals.update({
|
|||
'rev': 'rev.%s' % (REVNO, ),
|
||||
'version': VERSION,
|
||||
'getcookie':getcookie,
|
||||
'get': lambda (var): getattr(web.input(**{var:None}), var) # unreadable :-(
|
||||
'get': lambda (var): getattr(web.input(**{var:None}), var), # unreadable :-(
|
||||
'env':ws.env
|
||||
})
|
||||
#/template-defs
|
||||
|
||||
|
|
|
@ -12,16 +12,21 @@ $else:
|
|||
$_('Off')
|
||||
$:render.part_button('POST', '/refresh/on', _('Enable'), 'tango/view-refresh.png')
|
||||
$#end
|
||||
|
||||
</div>
|
||||
|
||||
<div class="panel" id='stats_panel'>
|
||||
<!--<a href='/config'>-->
|
||||
$if env == '0.6':
|
||||
$:render.part_button('GET', '/config/', _('Settings'), 'tango/preferences-system.png')
|
||||
|
||||
$_('Connections') : $stats.num_connections ($stats.max_num_connections)
|
||||
$_('Connections') : $stats.num_connections ($stats.max_num_connections)
|
||||
|
||||
$_('Down Speed') : $stats.download_rate ($stats.max_download)
|
||||
|
||||
$_('Up Speed') : $stats.upload_rate ($stats.max_upload)
|
||||
|
||||
$_('Down Speed') : $stats.download_rate ($stats.max_download)
|
||||
|
||||
$_('Up Speed') : $stats.upload_rate ($stats.max_upload)
|
||||
|
||||
|
||||
<!--</a>-->
|
||||
|
|
|
@ -165,14 +165,30 @@ body.inner {
|
|||
border:0;
|
||||
position:relative;
|
||||
top:0px;
|
||||
height:20px;
|
||||
height:15px;
|
||||
background-color:#ddd;
|
||||
color:#000;
|
||||
color:#00F;
|
||||
}
|
||||
|
||||
#refresh_panel button:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#stats_panel button {
|
||||
background-color:#304663;
|
||||
color:#FFFFFF;
|
||||
border:0;
|
||||
position:relative;
|
||||
top:0px;
|
||||
height:20px;
|
||||
background-color:#ddd;
|
||||
color:#00F;
|
||||
}
|
||||
#stats_panel button:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
|
||||
#category_panel {
|
||||
margin-bottom:0;
|
||||
padding-bottom:0;
|
||||
|
|
|
@ -2,14 +2,14 @@ $def with (method, url, title, image='')
|
|||
<div class="deluge_button">
|
||||
<form method="$method" action="$url" class="deluge_button">
|
||||
<input type="hidden" name="redir" value="$self_url()">
|
||||
$if (get_config('button_style') == 0):
|
||||
$if (int(get_config('button_style')) == 0):
|
||||
<button type="submit" class="deluge_button" alt="$title">
|
||||
$title
|
||||
$if image:
|
||||
<image src="/static/images/$image" class="button" alt="$title"/>
|
||||
</button>
|
||||
|
||||
$if (get_config('button_style') == 1):
|
||||
$if (int(get_config('button_style')) == 1):
|
||||
$if image:
|
||||
<input type="image" image src="/static/images/$image" class="img_button" alt="$title"/>
|
||||
$else:
|
||||
|
@ -17,7 +17,7 @@ $if (get_config('button_style') == 1):
|
|||
$title
|
||||
</button>
|
||||
|
||||
$if (get_config('button_style') == 2):
|
||||
$if (int(get_config('button_style')) == 2):
|
||||
<button type="submit" class="deluge_button" alt="$title">
|
||||
$title
|
||||
</button>
|
||||
|
|
|
@ -26,9 +26,10 @@ $#end
|
|||
|
||||
<!--</a>-->
|
||||
|
||||
<span id=#about>
|
||||
(<a href='/about'>$_('About')</a>)
|
||||
</span>
|
||||
$if env == '0.6':
|
||||
$:render.part_button('GET', '/config/', _('Settings'), 'tango/preferences-system.png')
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -362,6 +362,7 @@ if True:
|
|||
print key,cfg[key]
|
||||
|
||||
|
||||
|
||||
if False:
|
||||
suiteFew = unittest.TestSuite()
|
||||
|
||||
|
|
Loading…
Reference in New Issue