minor css fix+pwd-cfg
This commit is contained in:
parent
89af88e370
commit
b73dd60e6b
|
@ -38,6 +38,7 @@ from webserver_common import ws
|
||||||
from render import render
|
from render import render
|
||||||
from lib.webpy022.http import seeother
|
from lib.webpy022.http import seeother
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
groups = []
|
groups = []
|
||||||
blocks = forms.utils.datastructures.SortedDict()
|
blocks = forms.utils.datastructures.SortedDict()
|
||||||
|
@ -52,11 +53,13 @@ class Form(forms.Form):
|
||||||
|
|
||||||
def initial_data(self):
|
def initial_data(self):
|
||||||
"override in subclass"
|
"override in subclass"
|
||||||
raise NotImplementedError()
|
return None
|
||||||
|
|
||||||
def start_save(self):
|
def start_save(self):
|
||||||
"called by config_page"
|
"called by config_page"
|
||||||
self.save(web.Storage(self.clean_data))
|
data = web.Storage(self.clean_data)
|
||||||
|
self.validate(data)
|
||||||
|
self.save(data)
|
||||||
self.post_save()
|
self.post_save()
|
||||||
|
|
||||||
def save(self, vars):
|
def save(self, vars):
|
||||||
|
@ -64,7 +67,9 @@ class Form(forms.Form):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def post_save(self):
|
def post_save(self):
|
||||||
"override in subclass"
|
pass
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,10 +81,6 @@ class WebCfgForm(Form):
|
||||||
def save(self, data):
|
def save(self, data):
|
||||||
ws.config.update(data)
|
ws.config.update(data)
|
||||||
ws.save_config()
|
ws.save_config()
|
||||||
self.post_save()
|
|
||||||
|
|
||||||
def post_save(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class CookieCfgForm(Form):
|
class CookieCfgForm(Form):
|
||||||
"config base for webui"
|
"config base for webui"
|
||||||
|
@ -89,11 +90,6 @@ class CookieCfgForm(Form):
|
||||||
def save(self, data):
|
def save(self, data):
|
||||||
ws.config.update(data)
|
ws.config.update(data)
|
||||||
ws.save_config()
|
ws.save_config()
|
||||||
self.post_save()
|
|
||||||
|
|
||||||
def post_save(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CfgForm(Form):
|
class CfgForm(Form):
|
||||||
|
@ -129,8 +125,8 @@ class IntCombo(forms.ChoiceField):
|
||||||
returns int for the chosen display-value.
|
returns int for the chosen display-value.
|
||||||
"""
|
"""
|
||||||
def __init__(self, label, choices, **kwargs):
|
def __init__(self, label, choices, **kwargs):
|
||||||
forms.ChoiceField.__init__(self, label=label, choices=enumerate(choices)
|
forms.ChoiceField.__init__(self, label=label,
|
||||||
, **kwargs)
|
choices=enumerate(choices), **kwargs)
|
||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
return int(forms.ChoiceField.clean(self, value))
|
return int(forms.ChoiceField.clean(self, value))
|
||||||
|
@ -155,6 +151,23 @@ class MultipleChoice(forms.MultipleChoiceField):
|
||||||
forms.MultipleChoiceField.__init__(self, label=label, choices=choices,
|
forms.MultipleChoiceField.__init__(self, label=label, choices=choices,
|
||||||
widget=forms.CheckboxSelectMultiple, required=False)
|
widget=forms.CheckboxSelectMultiple, required=False)
|
||||||
|
|
||||||
|
class ServerFolder(forms.CharField):
|
||||||
|
def __init__(self, label, **kwargs):
|
||||||
|
forms.CharField.__init__(self, label=label,**kwargs)
|
||||||
|
|
||||||
|
def clean(self, value):
|
||||||
|
value = value.rstrip('/').rstrip('\\')
|
||||||
|
self.validate(value)
|
||||||
|
return forms.CharField.clean(self, value)
|
||||||
|
|
||||||
|
def validate(self, value):
|
||||||
|
if (value and not os.path.isdir(value)):
|
||||||
|
raise forms.ValidationError(_("This folder does not exist."))
|
||||||
|
|
||||||
|
class Password(forms.CharField):
|
||||||
|
def __init__(self, label, **kwargs):
|
||||||
|
forms.CharField.__init__(self, label=label, widget=forms.PasswordInput,
|
||||||
|
**kwargs)
|
||||||
|
|
||||||
#/fields
|
#/fields
|
||||||
|
|
||||||
|
@ -203,7 +216,8 @@ 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= _('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)
|
||||||
|
@ -214,5 +228,10 @@ def register_block(group, name, form):
|
||||||
form.group = group
|
form.group = group
|
||||||
blocks[name] = form
|
blocks[name] = form
|
||||||
|
|
||||||
|
def unregister_block(name):
|
||||||
|
del blocks[name]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,6 @@ import utils
|
||||||
from webserver_common import ws
|
from webserver_common import ws
|
||||||
|
|
||||||
|
|
||||||
class ServerFolderField(forms.CharField):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NetworkPorts(config.CfgForm ):
|
class NetworkPorts(config.CfgForm ):
|
||||||
title = _("Ports")
|
title = _("Ports")
|
||||||
info = _("Restart daemon after changing these values.")
|
info = _("Restart daemon after changing these values.")
|
||||||
|
@ -54,13 +50,15 @@ class NetworkPorts(config.CfgForm ):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def save(self,data):
|
def save(self,data):
|
||||||
if (data['_port_to'] < data['_port_from']):
|
|
||||||
raise ValidationError('"Port from" must be greater than "Port to"')
|
|
||||||
data['listen_ports'] = [data['_port_from'] , data['_port_to'] ]
|
data['listen_ports'] = [data['_port_from'] , data['_port_to'] ]
|
||||||
del(data['_port_from'])
|
del(data['_port_from'])
|
||||||
del(data['_port_to'])
|
del(data['_port_to'])
|
||||||
config.CfgForm.save(self, data)
|
config.CfgForm.save(self, data)
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
if (data['_port_to'] < data['_port_from']):
|
||||||
|
raise ValidationError('"Port from" must be greater than "Port to"')
|
||||||
|
|
||||||
config.register_block('network','ports', NetworkPorts)
|
config.register_block('network','ports', NetworkPorts)
|
||||||
|
|
||||||
class NetworkExtra(config.CfgForm ):
|
class NetworkExtra(config.CfgForm ):
|
||||||
|
@ -108,11 +106,12 @@ config.register_block('bandwidth','torrent', BandwithTorrent)
|
||||||
|
|
||||||
class Download(config.CfgForm):
|
class Download(config.CfgForm):
|
||||||
title = _("Download")
|
title = _("Download")
|
||||||
download_location = ServerFolderField(_("Store all downoads in"))
|
download_location = config.ServerFolder(_("Store all downoads in"))
|
||||||
torrentfiles_location = ServerFolderField(_("Save .torrent files to"))
|
torrentfiles_location = config.ServerFolder(_("Save .torrent files to"))
|
||||||
autoadd_location = ServerFolderField(_("Auto Add folder") , required=False)
|
autoadd_location = config.ServerFolder(_("Auto Add folder"), required=False)
|
||||||
compact_allocation = config.CheckBox(_('Use Compact Allocation'))
|
compact_allocation = config.CheckBox(_('Use Compact Allocation'))
|
||||||
prioritize_first_last_pieces = config.CheckBox(_('Prioritize first and last pieces'))
|
prioritize_first_last_pieces = config.CheckBox(
|
||||||
|
_('Prioritize first and last pieces'))
|
||||||
|
|
||||||
config.register_block('deluge','download', Download)
|
config.register_block('deluge','download', Download)
|
||||||
|
|
||||||
|
@ -132,8 +131,6 @@ class Plugins(config.Form):
|
||||||
return {'enabled_plugins':ws.proxy.get_enabled_plugins()}
|
return {'enabled_plugins':ws.proxy.get_enabled_plugins()}
|
||||||
|
|
||||||
def save(self, value):
|
def save(self, value):
|
||||||
raise NotImplementedError("TODO")
|
raise forms.ValidationError("SAVE:TODO")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
config.register_block('deluge','plugins', Plugins)
|
config.register_block('deluge','plugins', Plugins)
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
import lib.newforms as forms
|
import lib.newforms as forms
|
||||||
import config
|
import config
|
||||||
import utils
|
import utils
|
||||||
from render import render
|
|
||||||
from webserver_common import ws
|
from webserver_common import ws
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +48,7 @@ class Template(config.WebCfgForm):
|
||||||
cache_templates = config.CheckBox(_("Cache templates"))
|
cache_templates = config.CheckBox(_("Cache templates"))
|
||||||
|
|
||||||
def post_save(self):
|
def post_save(self):
|
||||||
|
from render import render
|
||||||
render.apply_cfg()
|
render.apply_cfg()
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,31 +60,26 @@ class Server(config.WebCfgForm):
|
||||||
|
|
||||||
def post_save(self):
|
def post_save(self):
|
||||||
pass
|
pass
|
||||||
#raise forms.ValidationError(_("Manually restart server to apply these changes."))
|
#raise forms.ValidationError(
|
||||||
|
# _("Manually restart server to apply these changes."))
|
||||||
|
|
||||||
class Password(config.Form):
|
class Password(config.Form):
|
||||||
title = _("Password")
|
title = _("Password")
|
||||||
old_pwd = forms.CharField(widget = forms.PasswordInput
|
|
||||||
,label = _("Current Password"))
|
|
||||||
|
|
||||||
new1 = forms.CharField(widget = forms.PasswordInput
|
old_pwd = config.Password(_("Current Password"))
|
||||||
,label = _("New Password"))
|
new1 = config.Password(_("New Password"))
|
||||||
|
new2 = config.Password(_("New Password (Confirm)"))
|
||||||
new2 = forms.CharField(widget = forms.PasswordInput
|
|
||||||
,label = _("New Password (Confirm)"))
|
|
||||||
|
|
||||||
def initial_data(self):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def save(self,data):
|
def save(self,data):
|
||||||
if not ws.check_pwd(data.old_pwd):
|
|
||||||
raise forms.ValidationError(_("Old password is invalid"))
|
|
||||||
if data.new1 <> data.new2:
|
|
||||||
raise forms.ValidationError(_("New Password is not equal to New Password(confirm)"))
|
|
||||||
|
|
||||||
ws.update_pwd(data.new1)
|
ws.update_pwd(data.new1)
|
||||||
ws.save_config()
|
ws.save_config()
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
if not ws.check_pwd(data.old_pwd):
|
||||||
|
raise forms.ValidationError(_("Old password is invalid"))
|
||||||
|
if data.new1 <> data.new2:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
_("New Password is not equal to New Password(confirm)"))
|
||||||
|
|
||||||
def post_save(self):
|
def post_save(self):
|
||||||
utils.end_session()
|
utils.end_session()
|
||||||
|
|
|
@ -164,7 +164,7 @@ body.inner {
|
||||||
color:#FFFFFF;
|
color:#FFFFFF;
|
||||||
border:0;
|
border:0;
|
||||||
position:relative;
|
position:relative;
|
||||||
top:0px;
|
top:-2px;
|
||||||
height:15px;
|
height:15px;
|
||||||
background-color:#ddd;
|
background-color:#ddd;
|
||||||
color:#00F;
|
color:#00F;
|
||||||
|
@ -179,8 +179,8 @@ body.inner {
|
||||||
color:#FFFFFF;
|
color:#FFFFFF;
|
||||||
border:0;
|
border:0;
|
||||||
position:relative;
|
position:relative;
|
||||||
top:0px;
|
top:-2px;
|
||||||
height:20px;
|
height:15px;
|
||||||
background-color:#ddd;
|
background-color:#ddd;
|
||||||
color:#00F;
|
color:#00F;
|
||||||
}
|
}
|
||||||
|
@ -269,6 +269,7 @@ form { /*all forms!*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#config_chooser {
|
#config_chooser {
|
||||||
|
margin-left:20px;
|
||||||
float: left;
|
float: left;
|
||||||
width:150px;
|
width:150px;
|
||||||
text-align:left;
|
text-align:left;
|
||||||
|
@ -279,6 +280,7 @@ form { /*all forms!*/
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#config_chooser li:hover {
|
#config_chooser li:hover {
|
||||||
background-color:#68a;
|
background-color:#68a;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue