webui label options

This commit is contained in:
Martijn Voncken 2008-11-23 09:30:48 +00:00
parent 08f2d5b412
commit 207005e355
4 changed files with 50 additions and 14 deletions

View File

@ -147,13 +147,21 @@ class Core(CorePluginBase):
del self.torrent_labels[torrent_id] del self.torrent_labels[torrent_id]
def clean_initial_config(self): 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()) log.debug(self.labels.keys())
for key in self.labels.keys(): for key in self.labels.keys():
options = dict(OPTIONS_DEFAULTS) options = dict(OPTIONS_DEFAULTS)
options.update(self.labels[key]) options.update(self.labels[key])
self.labels[key] = options 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): def save_config(self):
self.clean_config() self.clean_config()
self.config.save() self.config.save()

View File

@ -1,9 +1,8 @@
$def with (label_id, options_form) $def with (label_id, options_form, error=None)
$:render.basic_header(_("Label Options")) $:render.basic_header(_("Label Options"))
<h2>$label_id Options.</h2> <h2>$label_id Options.</h2>
<div class="panel"> <div class="panel">
<form method="POST" action='$base/label/options/$label_id'> <form method="POST" action='$base/label/options/$label_id'>
label= $label_id
<h3>max</h3> <h3>max</h3>
<table> <table>
$:(options_form.as_table(["apply_max", "max_download_speed", "max_upload_speed", "max_upload_slots", "max_connections"])) $:(options_form.as_table(["apply_max", "max_download_speed", "max_upload_speed", "max_upload_slots", "max_connections"]))

View File

@ -46,12 +46,35 @@ forms = api.forms
#pages: #pages:
class options: 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 @api.deco.deluge_page
def GET(self, label_id): 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) options = sclient.label_get_options(label_id)
log.debug(options)
options.update(dict(post_options))
log.debug(options)
options_form = OptionsForm(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: class add:
@api.deco.deluge_page @api.deco.deluge_page
@ -99,6 +122,11 @@ class WebUI(WebUIPluginBase):
] ]
""" """
class OptionsForm(forms.Form): class OptionsForm(forms.Form):
#load/save:
def initial_data(self):
return sclient.label_get_options(self.label_id)
#maximum: #maximum:
apply_max = forms.CheckBox(_("apply_max")) apply_max = forms.CheckBox(_("apply_max"))
max_download_speed = forms.DelugeInt(_("max_download_speed")) max_download_speed = forms.DelugeInt(_("max_download_speed"))
@ -110,17 +138,17 @@ class OptionsForm(forms.Form):
apply_queue = forms.CheckBox(_("apply_queue")) apply_queue = forms.CheckBox(_("apply_queue"))
is_auto_managed = forms.CheckBox(_("is_auto_managed")) is_auto_managed = forms.CheckBox(_("is_auto_managed"))
stop_at_ratio = forms.CheckBox(_("stop_at_ratio")) 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")) remove_at_ratio = forms.CheckBox(_("remove_at_ratio"))
#location: #location:
apply_move_completed = forms.CheckBox(_("apply_move_completed")) apply_move_completed = forms.CheckBox(_("apply_move_completed"))
move_completed = forms.CheckBox(_("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: #tracker:
auto_add = forms.CheckBox(_("auto_add")) 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"))

View File

@ -171,13 +171,14 @@ def get_newforms_data(form_class):
form_data = {} form_data = {}
vars = web.input() vars = web.input()
for field in fields: for field in fields:
form_data[field] = vars.get(field) value = vars.get(field)
#log.debug("form-field:%s=%s" % (field, form_data[field]))
#DIRTY HACK: (for multiple-select) if value != None or isinstance(form_class.base_fields[field], forms.BooleanField):
if isinstance(form_class.base_fields[field], form_data[field] = value
forms.MultipleChoiceField): #for multiple-select) :
form_data[field] = web.input(**{field:[]})[field] if isinstance(form_class.base_fields[field], forms.MultipleChoiceField):
#/DIRTY HACK form_data[field] = web.input(**{field:[]})[field]
return form_data return form_data
#/utils #/utils