Package gluon :: Module html
[hide private]
[frames] | no frames]

Module html

source code

This file is part of web2py Web Framework (Copyrighted, 2007) Developed by Massimo Di Pierro <mdipierro@cs.depaul.edu> License: GPL v2

Classes [hide private]
  XML
example:
  DIV
example:
  HTML
  HEAD
  TITLE
  META
  LINK
  SCRIPT
  STYLE
  IMG
  SPAN
  BODY
  H1
  H2
  H3
  H4
  H5
  H6
  P
  B
  BR
  HR
  A
  EM
  EMBED
  TT
  PRE
  CENTER
  CODE
displays code in HTML with syntax highlighting.
  LABEL
  LI
  UL
  OL
  TD
  TH
  TR
  TABLE
  IFRAME
  INPUT
examples:
  TEXTAREA
TEXTAREA(_name='sometext',value='bla '*100,requires=IS_NOT_EMPTY()) 'bla bla bla ...' will be the content of the textarea field.
  OPTION
  OBJECT
  SELECT
example:
  FIELDSET
  FORM
example:
  BEAUTIFY
example:
Functions [hide private]
 
xmlescape(data, quote=False) source code
 
URL(a=None, c=None, f=None, r=None, args=[], vars={})
example:
source code
 
embed64(filename=None, file=None, data=None, extension='image/gif') source code
 
test()
Example:
source code
Variables [hide private]
  ON = None
Function Details [hide private]

URL(a=None, c=None, f=None, r=None, args=[], vars={})

source code 

example:

>>> URL(a='a',c='c',f='f',args=['x','y','z'],vars={'p':1, 'q':2})
'/a/c/f/x/y/z?q=2&p=1'

generates a url "/a/c/f" corresponding to application a, controller c and function f. If r=request is passed, a,c,f are set, respectively, to r.applicaiton, r.controller, r.function.

The more typical usage is:

URL(r=request,f='index') that generates a url for the index function within the present application and controller.

test()

source code 

Example:

>>> from validators import *
>>> print DIV(A('click me',_href=URL(a='a',c='b',f='c')),BR(),HR(),DIV(SPAN("World"),_class='unkown')).xml()
<div><a href="/a/b/c">click me</a><br/><hr/><div class="unkown"><span>World</span></div></div>
>>> print DIV(UL("doc","cat","mouse")).xml()
<div><lu><li>doc</li><li>cat</li><li>mouse</li></lu></div>
>>> print DIV(UL("doc",LI("cat", _class='felin'),18)).xml()
<div><lu><li>doc</li><li class="felin">cat</li><li>18</li></lu></div>
>>> print TABLE(['a','b','c'],TR('d','e','f'),TR(TD(1),TD(2),TD(3))).xml()
<table><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>d</td><td>e</td><td>f</td></tr><tr><td>1</td><td>2</td><td>3</td></tr></table>
>>> form=FORM(INPUT(_type='text',_name='myvar',requires=IS_EXPR('int(value)<10')))
>>> print form.xml()
<form enctype="multipart/form-data" method="post"><input type="text" name="myvar"/></form>
>>> print form.accepts({'myvar':'34'},formname=None)
False
>>> print form.xml()
<form enctype="multipart/form-data" method="post"><input value="34" type="text" name="myvar"/><div class="error">invalid expression!</div></form>
>>> print form.accepts({'myvar':'4'},formname=None,keepvalues=True)
True
>>> print form.xml()
<form enctype="multipart/form-data" method="post"><input value="4" type="text" name="myvar"/></form>
>>> form=FORM(SELECT('cat','dog',_name='myvar'))
>>> print form.accepts({'myvar':'dog'},formname=None)
True
>>> print form.xml()
<form enctype="multipart/form-data" method="post"><select name="myvar"><option value="cat">cat</option><option selected value="dog">dog</option></select></form>
>>> form=FORM(INPUT(_type='text',_name='myvar',requires=IS_MATCH('^\w+$','only alphanumeric!')))
>>> print form.accepts({'myvar':'as df'},formname=None)
False
>>> print form.xml()
<form enctype="multipart/form-data" method="post"><input value="as df" type="text" name="myvar"/><div class="error">only alphanumeric!</div></form>
>>> session={}
>>> form=FORM(INPUT(value="Hello World",_name="var",requires=IS_MATCH('^\w+$')))
>>> if form.accepts({},session,formname=None): print 'passed'
>>> tmp=form.xml() # form has to be generated or _form_key is not stored
>>> if form.accepts({'var':'test ','_form_key':session['_form_key[None]']},session,formname=None): print 'passed'