webui label options
This commit is contained in:
parent
08f2d5b412
commit
207005e355
|
@ -147,13 +147,21 @@ class Core(CorePluginBase):
|
|||
del self.torrent_labels[torrent_id]
|
||||
|
||||
def clean_initial_config(self):
|
||||
"add any new keys in OPTIONS_DEFAULTS"
|
||||
"""
|
||||
*add any new keys in OPTIONS_DEFAULTS
|
||||
*set all None values to default <-fix development config
|
||||
"""
|
||||
log.debug(self.labels.keys())
|
||||
for key in self.labels.keys():
|
||||
options = dict(OPTIONS_DEFAULTS)
|
||||
options.update(self.labels[key])
|
||||
self.labels[key] = options
|
||||
|
||||
for key, value in self.labels[key].iteritems():
|
||||
if value == None:
|
||||
self.labels[key] = OPTIONS_DEFAULTS[key]
|
||||
|
||||
|
||||
def save_config(self):
|
||||
self.clean_config()
|
||||
self.config.save()
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
$def with (label_id, options_form)
|
||||
$def with (label_id, options_form, error=None)
|
||||
$:render.basic_header(_("Label Options"))
|
||||
<h2>$label_id Options.</h2>
|
||||
<div class="panel">
|
||||
<form method="POST" action='$base/label/options/$label_id'>
|
||||
label= $label_id
|
||||
<h3>max</h3>
|
||||
<table>
|
||||
$:(options_form.as_table(["apply_max", "max_download_speed", "max_upload_speed", "max_upload_slots", "max_connections"]))
|
||||
|
|
|
@ -46,12 +46,35 @@ forms = api.forms
|
|||
|
||||
#pages:
|
||||
class options:
|
||||
def page(self, label_id, options , error=None):
|
||||
options_form = OptionsForm(options)
|
||||
options_form.label_id = label_id
|
||||
options_form.full_clean()
|
||||
return api.render.label.options(label_id, options_form)
|
||||
|
||||
@api.deco.deluge_page
|
||||
def GET(self, label_id):
|
||||
return self.page(label_id, sclient.label_get_options(label_id))
|
||||
|
||||
@api.deco.check_session
|
||||
def POST(self, label_id):
|
||||
post_options = api.utils.get_newforms_data(OptionsForm)
|
||||
options = sclient.label_get_options(label_id)
|
||||
|
||||
log.debug(options)
|
||||
options.update(dict(post_options))
|
||||
log.debug(options)
|
||||
options_form = OptionsForm(options)
|
||||
return api.render.label.options(label_id, options_form)
|
||||
options_form.label_id = label_id
|
||||
|
||||
if not options_form.is_valid():
|
||||
return self.page(label_id, options, _("Error setting label options"))
|
||||
else:
|
||||
error = None
|
||||
|
||||
sclient.label_set_options(label_id, options_form.cleaned_data)
|
||||
api.utils.seeother("/config/label")
|
||||
|
||||
|
||||
class add:
|
||||
@api.deco.deluge_page
|
||||
|
@ -99,6 +122,11 @@ class WebUI(WebUIPluginBase):
|
|||
]
|
||||
"""
|
||||
class OptionsForm(forms.Form):
|
||||
|
||||
#load/save:
|
||||
def initial_data(self):
|
||||
return sclient.label_get_options(self.label_id)
|
||||
|
||||
#maximum:
|
||||
apply_max = forms.CheckBox(_("apply_max"))
|
||||
max_download_speed = forms.DelugeInt(_("max_download_speed"))
|
||||
|
@ -110,17 +138,17 @@ class OptionsForm(forms.Form):
|
|||
apply_queue = forms.CheckBox(_("apply_queue"))
|
||||
is_auto_managed = forms.CheckBox(_("is_auto_managed"))
|
||||
stop_at_ratio = forms.CheckBox(_("stop_at_ratio"))
|
||||
stop_ratio = forms.DelugeInt(_("stop_ratio"))
|
||||
stop_ratio = forms.DelugeFloat(_("stop_ratio"), required=False)
|
||||
remove_at_ratio = forms.CheckBox(_("remove_at_ratio"))
|
||||
|
||||
#location:
|
||||
apply_move_completed = forms.CheckBox(_("apply_move_completed"))
|
||||
move_completed = forms.CheckBox(_("move_completed"))
|
||||
move_completed_path = forms.CharField(label=_("move_completed_path"))
|
||||
move_completed_path = forms.CharField(label=_("move_completed_path"), required=False)
|
||||
|
||||
#tracker:
|
||||
auto_add = forms.CheckBox(_("auto_add"))
|
||||
auto_add_trackers = forms.CharField(label=_("auto_add_trackers"), widget=forms.Textarea)
|
||||
auto_add_trackers = forms.StringList(_("auto_add_trackers"))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -171,13 +171,14 @@ def get_newforms_data(form_class):
|
|||
form_data = {}
|
||||
vars = web.input()
|
||||
for field in fields:
|
||||
form_data[field] = vars.get(field)
|
||||
#log.debug("form-field:%s=%s" % (field, form_data[field]))
|
||||
#DIRTY HACK: (for multiple-select)
|
||||
if isinstance(form_class.base_fields[field],
|
||||
forms.MultipleChoiceField):
|
||||
value = vars.get(field)
|
||||
|
||||
if value != None or isinstance(form_class.base_fields[field], forms.BooleanField):
|
||||
form_data[field] = value
|
||||
#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
|
||||
|
|
Loading…
Reference in New Issue