The tag determines the generated name (5.2.2.5) from the name related attributes.
To determine the generated value (5.2.2.11) attribute the tag first looks for an expr (5.2.2.3) attribute, then a value attribute, and then if that fails it looks up the generated name in the execution context.
If the generated name contains a non-empty value it will be
written as the name attribute. If the generated
value is not None
it will be escaped and written as
the value attribute. Escaping values makes all &,
<, >, and " characters safe.
For example:
>>> import albatross >>> class Ctx(albatross.SimpleContext): ... def input_add(self, *args): ... print args ... >>> ctx = Ctx('.') >>> ctx.locals.zero = 0 >>> ctx.locals.zerostr = '0' >>> ctx.locals.width = 5 >>> ctx.locals.height = 7 >>> ctx.locals.secret = 42 >>> ctx.locals.other_secret = '<"&' >>> albatross.Template(ctx, '<magic>', ''' ... <al-input name="zero" whitespace> ... <al-input name="zerostr" whitespace> ... <al-input name="width" whitespace> ... <al-input name="area" expr="width * height" whitespace> ... <al-input type="password" name="passwd" whitespace> ... <al-input type="submit" name="login" value="Login" whitespace> ... <al-input type="hidden" name="secret" whitespace> ... <al-input type="hidden" name="other_secret" whitespace> ... ''').to_html(ctx) ('text', 'zero', 0, 0) ('text', 'zerostr', '0', 0) ('text', 'width', 5, 0) ('text', 'area', 35, 0) ('password', 'passwd', None, 0) ('submit', 'login', 'Login', 0) ('hidden', 'secret', 42, 0) ('hidden', 'other_secret', '<"&', 0) >>> ctx.flush_content() <input name="zero" value="0"> <input name="zerostr" value="0"> <input name="width" value="5"> <input name="area" value="35"> <input type="password" name="passwd"> <input type="submit" name="login" value="Login"> <input type="hidden" name="secret" value="42"> <input type="hidden" name="other_secret" value="<"&">
After writing all tag attributes the execution context
input_add() method is called with the following arguments;
input field type ('text'
, 'password
, 'submit
,
'reset
, 'hidden
, or 'button'
), the generated
name, the generated value, and a flag indicating
whether or not the list (5.2.2.4) attribute was
present.
Application code handling browser requests typically determines the submit input pressed by the user via the execution context req_equals() method. The req_equals() method simply tests that the named input is present in the browser request and contains a non-empty value.
For example:
def page_process(ctx): if ctx.req_equals('login'): user = process_login(ctx.locals.username, ctx.locals.passwd) if user: ctx.locals._user = user ctx.add_session_vars('_user') ctx.set_page('home')