本文整理汇总了Python中forms.Form.html方法的典型用法代码示例。如果您正苦于以下问题:Python Form.html方法的具体用法?Python Form.html怎么用?Python Form.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.Form
的用法示例。
在下文中一共展示了Form.html方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def main(self, message='', **kwargs):
store = filedict_con(cfg.store_file, 'sys')
defaults = {'wan_admin': "''",
'wan_ssh': "''",
'lan_ssh': "''",
}
for k,c in defaults.items():
if not k in kwargs:
try:
kwargs[k] = store[k]
except KeyError:
exec("if not '%(k)s' in kwargs: store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {'k':k, 'c':c})
form = Form(title=_("Accessing the %s" % cfg.box_name),
action="/sys/config/wan",
name="admin_wan_form",
message=message )
form.html(self.help())
if cfg.users.expert():
form.checkbox(_("Allow access to Plinth from WAN"), name="wan_admin", checked=kwargs['wan_admin'])
form.checkbox(_("Allow SSH access from LAN"), name="lan_ssh", checked=kwargs['lan_ssh'])
form.checkbox(_("Allow SSH access from WAN"), name="wan_ssh", checked=kwargs['wan_ssh'])
form.submit(_("Submit"))
return form.render()
示例2: main
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def main(self, msg=''):
users = cfg.users.keys()
add_form = Form(title=_("Edit or Delete User"), action="/sys/users/edit", message=msg)
add_form.html('<span class="indent"><strong>Delete</strong><br /></span>')
for uname in sorted(users.keys()):
add_form.html('<span class="indent"> %s ' %
add_form.get_checkbox(name=uname) +
'<a href="/sys/users/edit?username=%s">%s (%s)</a><br /></span>' %
(uname, users[uname]['name'], uname))
add_form.submit(label=_("Delete User"), name="delete")
return add_form.render()
示例3: main
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def main(self, msg=''):
users = cfg.users.get_all()
add_form = Form(title=_("Edit or Delete User"), action=cfg.server_dir + "/sys/users/edit", message=msg)
add_form.html('<span class="indent"><strong>Delete</strong><br /></span>')
for uname in users:
user = User(uname[1])
add_form.html('<span class="indent"> %s ' %
add_form.get_checkbox(name=user['username']) +
'<a href="'+cfg.server_dir+'/sys/users/edit?username=%s">%s (%s)</a><br /></span>' %
(user['username'], user['name'], user['username']))
add_form.submit(label=_("Delete User"), name="delete")
return add_form.render()
示例4: main
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def main(self, message='', **kwargs):
if not cfg.users.expert():
return '<p>' + _('Only members of the expert group are allowed to see and modify the system setup.') + '</p>'
sys_store = filedict_con(cfg.store_file, 'sys')
hostname = get_hostname()
# this layer of persisting configuration in sys_store could/should be
# removed -BLN
defaults = {'time_zone': "slurp('/etc/timezone').rstrip()",
'hostname': "hostname",
}
for k,c in defaults.items():
if not k in kwargs:
try:
kwargs[k] = sys_store[k]
except KeyError:
exec("if not '%(k)s' in kwargs: sys_store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {'k':k, 'c':c})
# over-ride the sys_store cached value
kwargs['hostname'] = hostname
## Get the list of supported timezones and the index in that list of the current one
module_file = __file__
if module_file.endswith(".pyc"):
module_file = module_file[:-1]
time_zones = json.loads(slurp(os.path.join(os.path.dirname(os.path.realpath(module_file)), "time_zones")))
for i in range(len(time_zones)):
if kwargs['time_zone'] == time_zones[i]:
time_zone_id = i
break
## A little sanity checking. Make sure the current timezone is in the list.
try:
cfg.log('kwargs tz: %s, from_table: %s' % (kwargs['time_zone'], time_zones[time_zone_id]))
except NameError:
cfg.log.critical("Unknown Time Zone: %s" % kwargs['time_zone'])
raise cherrypy.HTTPError(500, "Unknown Time Zone: %s" % kwargs['time_zone'])
## And now, the form.
form = Form(title=_("General Config"),
action="/sys/config/general/index",
name="config_general_form",
message=message )
form.html(self.help())
form.dropdown(_("Time Zone"), name="time_zone", vals=time_zones, select=time_zone_id)
form.html("<p>Your hostname is the local name by which other machines on your LAN can reach you.</p>")
form.text_input('Hostname', name='hostname', value=kwargs['hostname'])
form.submit(_("Submit"))
return form.render()
示例5: main
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def main(self, expert=None, message='', **kwargs):
"""Note that kwargs contains '':"submit" if this is coming
from a submitted form. If kwargs is empty, it's a fresh form
with no user input, which means it should just reflect the
state of the stored data."""
if not kwargs and expert == None:
expert = cfg.users.expert()
cfg.log("Expert mode is %s" % expert)
form = Form(title=_("Expert Mode"),
action="/sys/config/experts",
name="expert_mode_form",
message=message )
form.html(self.help())
form.checkbox(_("Expert Mode"), name="expert", checked=expert)
form.submit(_("Submit"))
return form.render()
示例6: main
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def main(self, xmpp_inband_enable=False, message=None, *args, **kwargs):
output, error = actions.superuser_run("xmpp-setup", 'status')
if error:
raise Exception("something is wrong: " + error)
if "inband_enable" in output.split():
xmpp_inband_enable = True
form = Form(title="Configure XMPP Server",
action=cfg.server_dir + "/services/xmpp/configure/index",
name="configure_xmpp_form",
message=message)
form.checkbox(_("Allow In-Band Registration"), name="xmpp_inband_enable",
id="xmpp_inband_enable", checked=xmpp_inband_enable)
# hidden field is needed because checkbox doesn't post if not checked
form.hidden(name="submitted", value="True")
form.html(_("<p>When enabled, anyone who can reach this server will be allowed to register an account through an XMPP client.</p>"))
form.submit(_("Update setup"))
return form.render()
示例7: main
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def main(self, message="", **kwargs):
sys_store = filedict_con(cfg.store_file, "sys")
defaults = {"time_zone": "slurp('/etc/timezone').rstrip()", "hostname": "gethostname()"}
for k, c in defaults.items():
if not k in kwargs:
try:
kwargs[k] = sys_store[k]
except KeyError:
exec("if not '%(k)s' in kwargs: sys_store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {"k": k, "c": c})
## Get the list of supported timezones and the index in that list of the current one
module_file = __file__
if module_file.endswith(".pyc"):
module_file = module_file[:-1]
time_zones = json.loads(slurp(os.path.join(os.path.dirname(os.path.realpath(module_file)), "time_zones")))
for i in range(len(time_zones)):
if kwargs["time_zone"] == time_zones[i]:
time_zone_id = i
break
## A little sanity checking. Make sure the current timezone is in the list.
try:
cfg.log("kwargs tz: %s, from_table: %s" % (kwargs["time_zone"], time_zones[time_zone_id]))
except NameError:
cfg.log.critical("Unknown Time Zone: %s" % kwargs["time_zone"])
raise cherrypy.HTTPError(500, "Unknown Time Zone: %s" % kwargs["time_zone"])
## And now, the form.
form = Form(
title=_("General Config"), action="/sys/config/general/index", name="config_general_form", message=message
)
form.html(self.help())
form.dropdown(_("Time Zone"), name="time_zone", vals=time_zones, select=time_zone_id)
form.html("<p>Your hostname is the local name by which other machines on your LAN can reach you.</p>")
form.text_input("Hostname", name="hostname", value=kwargs["hostname"])
form.submit(_("Submit"))
return form.render()
示例8: main
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def main(self, wan_ip0=0, wan_ip1=0, wan_ip2=0, wan_ip3=0,
subnet0=0, subnet1=0, subnet2=0, subnet3=0,
gateway0=0, gateway1=0, gateway2=0, gateway3=0,
dns10=0, dns11=0, dns12=0, dns13=0,
dns20=0, dns21=0, dns22=0, dns23=0,
dns30=0, dns31=0, dns32=0, dns33=0,
message=None, **kwargs):
if not cfg.users.expert():
return ''
store = filedict_con(cfg.store_file, 'router')
defaults = {'connect_type': "'DHCP'",
}
for k,c in defaults.items():
if not k in kwargs:
try:
kwargs[k] = store[k]
except KeyError:
exec("if not '%(k)s' in kwargs: store['%(k)s'] = kwargs['%(k)s'] = %(c)s" % {'k':k, 'c':c})
form = Form(title="WAN Connection",
action="/router/setup/wan/index",
name="wan_connection_form",
message=message)
form.dropdown('Connection Type', vals=["DHCP", "Static IP"], id="connect_type", onchange="hideshow_static()")
form.html('<div id="static_ip_form">')
form.dotted_quad("WAN IP Address", name="wan_ip", quad=[wan_ip0, wan_ip1, wan_ip2, wan_ip3])
form.dotted_quad("Subnet Mask", name="subnet", quad=[subnet0, subnet1, subnet2, subnet3])
form.dotted_quad("Gateway", name="gateway", quad=[gateway0, gateway1, gateway2, gateway3])
form.dotted_quad("Static DNS 1", name="dns1", quad=[dns10, dns11, dns12, dns13])
form.dotted_quad("Static DNS 2", name="dns2", quad=[dns20, dns21, dns22, dns23])
form.dotted_quad("Static DNS 3", name="dns3", quad=[dns30, dns31, dns32, dns33])
form.html('</div>')
form.html(""" <script LANGUAGE="JavaScript">
<!--
hideshow_static();
// -->
</script>""")
form.submit("Set Wan")
return form.render()
示例9: state0
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def state0(self, message="", hostname="", box_key="", submitted=False, username="", password="", **kwargs):
"""
In this state, we do time config over HTTP, name the box and
server key selection.
All the parameters are form inputs. They get passed in when
the form is submitted. This method checks the inputs and if
they validate, uses them to take action. If they do not
validate, it displays the form to give the user a chance to
input correct values. It might display an error message (in
the message parameter).
message is an optional string that we can display to the
user. It's a good place to put error messages.
"""
# FIXME: reject connection attempt if db["state"] >= 5.
## Until LDAP is in place, we'll put the box name and key in the cfg.store_file
## Must resist the sick temptation to write an LDAP interface to the sqlite file
with sqlite_db(cfg.store_file, table="thisbox", autocommit=True) as db:
db['about'] = "This table is for information about this FreedomBox"
if hostname:
if '' == config.valid_hostname(hostname):
config.set_hostname(hostname)
else:
message += _("Invalid box name: %s") % config.valid_hostname(hostname)
else:
hostname = config.get_hostname()
if box_key:
if self.valid_box_key_p(box_key):
db['box_key'] = box_key
else:
message += _("Invalid key!")
elif 'box_key' in db and db['box_key']:
box_key = _("We already have a key for this box on file.") # TODO: Think this through and handle more gracefully. Seriously.
elif submitted and not box_key:
box_key = self.generate_box_key()
db['box_key'] = box_key
if username and password:
error = add_user(username, password, 'First user - please change', '', True)
if error:
message += _("User account creation failed: %s") % error
validuser = False
else:
validuser = True
else:
validuser = False
if hostname and box_key and '' == config.valid_hostname(hostname) and self.valid_box_key_p(box_key) and validuser:
## Update state to 1 and head there
with sqlite_db(cfg.store_file, table="firstboot", autocommit=True) as db:
db['state']=1
raise cherrypy.InternalRedirect('state1')
main = "<p>Welcome. It looks like this FreedomBox isn't set up yet. We'll need to ask you a just few questions to get started.</p>"
form = Form(title="Welcome to Your FreedomBox!",
action="", # stay at firstboot
name="whats_my_name",
message=message)
form.html("<p>For convenience, your FreedomBox needs a name. It should be something short that doesn't contain spaces or punctuation. 'Willard' would be a good name. 'Freestyle McFreedomBox!!!' would not.</p>")
form.text_input('Name your FreedomBox', id="hostname", value=hostname)
form.html("<p><strong>Initial user and password.</strong> Access to this web interface is protected by knowing a username and password. Provide one here to register the initial privileged user. The password can be changed and other users added later.</p>")
form.text_input('Username:', id="username", value=username)
form.text_input('Password:', id="password", type='password')
form.html("<p>%(box_name)s uses cryptographic keys so it can prove its identity when talking to you. %(box_name)s can make a key for itself, but if one already exists (from a prior FreedomBox, for example), you can paste it below. This key should not be the same as your key because you are not your FreedomBox!</p>" % {'box_name':cfg.box_name})
form.text_box("If you want, paste your box's key here.", id="box_key", value=box_key)
form.hidden(name="submitted", value="True")
form.submit("Box it up!")
main += form.render()
return self.fill_template(
template="base",
title=_("First Boot!"),
main=main,
sidebar_right=sidebar_right)
示例10: state0
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import html [as 别名]
def state0(self, message="", box_name="", box_key="", submitted=False):
"""
In this state, we do time config over HTTP, name the box and
server key selection.
All the parameters are form inputs. They get passed in when
the form is submitted. This method checks the inputs and if
they validate, uses them to take action. If they do not
validate, it displays the form to give the user a chance to
input correct values. It might display an error message (in
the message parameter).
message is an optional string that we can display to the
user. It's a good place to put error messages.
"""
## Until LDAP is in place, we'll put the box name and key in the cfg.store_file
## Must resist the sick temptation to write an LDAP interface to the sqlite file
with sqlite_db(cfg.store_file, table="thisbox", autocommit=True) as db:
db['about'] = "This table is for information about this FreedomBox"
if box_name:
if self.valid_box_name_p(box_name):
db['box_name'] = box_name
else:
message += _("Invalid box name.")
elif 'box_name' in db and db['box_name']:
box_name = db['box_name']
#TODO: set /etc/hostname to box name via ex machina
if box_key:
if self.valid_box_key_p(box_key):
db['box_key'] = box_key
else:
message += _("Invalid key!")
elif 'box_key' in db and db['box_key']:
box_key = _("We already have a key for this box on file.") #TODO: Think this through and handle more gracefully
elif submitted and not box_key:
box_key = self.generate_box_key()
db['box_key'] = box_key
if box_name and box_key and self.valid_box_name_p(box_name) and self.valid_box_key_p(box_key):
## Update state to 1 and head there
with sqlite_db(cfg.store_file, table="firstboot", autocommit=True) as db:
db['state']=1
raise cherrypy.InternalRedirect('/firstboot/state1')
main = "<p>Welcome. It looks like this FreedomBox isn't set up yet. We'll need to ask you a just few questions to get started.</p>"
form = Form(title="Welcome to Your FreedomBox!",
action="/firstboot",
name="whats_my_name",
message=message)
if not box_name:
box_name = cfg.box_name
form.html("<p>For convenience, your FreedomBox needs a name. It should be something short that doesn't contain spaces or punctuation. 'Willard' would be a good name. 'Freestyle McFreedomBox!!!' would not.</p>")
form.text_input('Name your FreedomBox', id="box_name", value=box_name)
form.html("<p>%(box_name)s uses cryptographic keys so it can prove its identity when talking to you. %(box_name)s can make a key for itself, but if one already exists (from a prior FreedomBox, for example), you can paste it below. This key should not be the same as your key because you are not your FreedomBox!</p>" % {'box_name':cfg.box_name})
form.text_box("If you want, paste your box's key here.", id="box_key", value=box_key)
form.hidden(name="submitted", value="True")
form.submit("Box it up!")
main += form.render()
return self.fill_template(template="base", title=_("First Boot!"), main=main,
sidebar_right=_("""<strong>Getting Help</strong><p>We've done our best to make your FreedomBox easy to use. If you have questions during setup, there are a few places to turn for help. TODO: add links to such help.</p>"""))