ATLAS Offline Software
Loading...
Searching...
No Matches
WebPage Namespace Reference

Classes

class  GlobalConfiguration
class  HelloWorld
class  htmlTable
class  WebPage
class  WebPageConfigurationError

Functions

 sep (s)
 htmlDiv (id, contents='', attr='', keepEmptyDiv=True)
 htmlText (text, attr='', escapeText=False)
 htmlPre (text, attr='', escapeText=False)
 htmlPara (text='', attr='', escapeText=False)
 htmlLink (text, link, attr='', escapeText=False)
 htmlList (contents, attr='', listType='ul')
 htmlLI (text, attr='', escapeText=False)
 htmlFoldingSection (header, content, isClosed=True, headerClass='section-header', contentClass='section-content')
 htmlForm (contents, action='', method='post', attr='')
 htmlLabel (labelText, parName, attr='')
 htmlSelect (labelText, parName, args, choiceList, hint=None, descriptionSeparator='::', labelAttr='', attr='')
 htmlCheckbox (labelText, parName, args, labelAttr='', attr='')
 htmlTextInput (labelText, parName, args, size=None, maxLength=None, labelAttr='', attr='')
 htmlSubmit (text, parName, attr='', onlyOnce=False)

Variables

str __author__ = 'Juerg Beringer'
str __version__ = 'WebPage.py atlas/athena'
str startPage
str endPage

Detailed Description

This module provides a simple framework for generating CSS-based dynamic web
pages with a typical layout consisting of a header, navigation bar, content area
and a footer. It is compatible with different web servers using e.g. CGI, mod_python,
or CherryPy.

Function Documentation

◆ htmlCheckbox()

WebPage.htmlCheckbox ( labelText,
parName,
args,
labelAttr = '',
attr = '' )
Make a checkbox (including label with text).

Definition at line 206 of file WebPage.py.

206def htmlCheckbox(labelText, parName, args, labelAttr='', attr=''):
207 """Make a checkbox (including label with text)."""
208 snippet = htmlLabel(labelText,parName,labelAttr)
209 checked = 'checked="checked"' if parName in args else ''
210 snippet += '<input type="checkbox" name="%s"%s%s/>\n' % (parName,sep(checked),sep(attr))
211 return snippet
212

◆ htmlDiv()

WebPage.htmlDiv ( id,
contents = '',
attr = '',
keepEmptyDiv = True )
Make a named div element containing contents. If
   contents is empty, an empty string is returned,
   unless keepEmtpyDiv is set True.

Definition at line 46 of file WebPage.py.

46def htmlDiv(id, contents='', attr='', keepEmptyDiv=True):
47 """Make a named div element containing contents. If
48 contents is empty, an empty string is returned,
49 unless keepEmtpyDiv is set True."""
50 if contents or keepEmptyDiv:
51 if id:
52 return '<div id="%s"%s>\n%s</div>\n' % (id,sep(attr),contents)
53 else:
54 return '<div%s>\n%s</div>\n' % (sep(attr),contents)
55 else:
56 return ''
57

◆ htmlFoldingSection()

WebPage.htmlFoldingSection ( header,
content,
isClosed = True,
headerClass = 'section-header',
contentClass = 'section-content' )
Generate the html for a folding section using the toggleSection JavaScript utility
   from WebPageUtils.js and CSS classes section-closed, section-open, and hidden.

Definition at line 154 of file WebPage.py.

156 contentClass='section-content'):
157 """Generate the html for a folding section using the toggleSection JavaScript utility
158 from WebPageUtils.js and CSS classes section-closed, section-open, and hidden."""
159 if isClosed:
160 s = '<div class="section-closed" onclick="toggleSection(this);">'
161 else:
162 s = '<div class="section-open" onclick="toggleSection(this);">'
163 s += '<span class="%s">%s</span></div>\n' % (headerClass,header)
164 h = ' hidden' if isClosed else ''
165 s += '<div class="%s%s">\n%s</div>\n' % (contentClass,h,content)
166 return s
167

◆ htmlForm()

WebPage.htmlForm ( contents,
action = '',
method = 'post',
attr = '' )

Definition at line 168 of file WebPage.py.

168def htmlForm(contents, action='', method='post', attr=''):
169 snippet = '<form action="%s" method="%s"%s>\n' % (action,method,sep(attr))
170 snippet += '<fieldset>\n'
171 snippet += contents
172 snippet += '</fieldset>\n</form>\n'
173 return snippet
174

◆ htmlLabel()

WebPage.htmlLabel ( labelText,
parName,
attr = '' )
Make a label for parName. If labelText is None,
   an empty string is returned.

Definition at line 175 of file WebPage.py.

175def htmlLabel(labelText, parName, attr=''):
176 """Make a label for parName. If labelText is None,
177 an empty string is returned."""
178 if labelText!=None:
179 return '<label for="%s"%s>%s</label>' % (parName,sep(attr),labelText)
180 else:
181 return ''
182

◆ htmlLI()

WebPage.htmlLI ( text,
attr = '',
escapeText = False )
Make a list item.  Special HTML characters
   in the text are properly replaced (using escape from cgi) if
   escapeText is set True.

Definition at line 85 of file WebPage.py.

85def htmlLI(text, attr='', escapeText=False):
86 """Make a list item. Special HTML characters
87 in the text are properly replaced (using escape from cgi) if
88 escapeText is set True."""
89 return '<li%s>%s</li>\n' % (sep(attr), escape(text) if escapeText else text)
90

◆ htmlLink()

WebPage.htmlLink ( text,
link,
attr = '',
escapeText = False )

Definition at line 77 of file WebPage.py.

77def htmlLink(text, link, attr='', escapeText=False):
78 return '<a href="%s"%s>%s</a>' % (link,sep(attr),escape(text) if escapeText else text)
79

◆ htmlList()

WebPage.htmlList ( contents,
attr = '',
listType = 'ul' )
Enclose list contents (a string with one or more list items) with
   the proper list tag. The type of the list is given by listType.

Definition at line 80 of file WebPage.py.

80def htmlList(contents, attr='', listType='ul'):
81 """Enclose list contents (a string with one or more list items) with
82 the proper list tag. The type of the list is given by listType."""
83 return '<%s%s>\n%s</%s>\n' % (listType,sep(attr),contents,listType)
84

◆ htmlPara()

WebPage.htmlPara ( text = '',
attr = '',
escapeText = False )
Make a paragraph.

Definition at line 70 of file WebPage.py.

70def htmlPara(text='', attr='', escapeText=False):
71 """Make a paragraph."""
72 if text or attr:
73 return '<p%s>%s</p>\n' % (sep(attr), escape(text) if escapeText else text)
74 else:
75 return '<p>\n'
76

◆ htmlPre()

WebPage.htmlPre ( text,
attr = '',
escapeText = False )
Make a preformatted text section. Special HTML characters
   in the text are properly replaced (using escape from cgi) if
   escapeText is set True.

Definition at line 64 of file WebPage.py.

64def htmlPre(text, attr='', escapeText=False):
65 """Make a preformatted text section. Special HTML characters
66 in the text are properly replaced (using escape from cgi) if
67 escapeText is set True."""
68 return '<pre%s>\n%s\n</pre>\n' % (sep(attr),escape(text) if escapeText else text)
69

◆ htmlSelect()

WebPage.htmlSelect ( labelText,
parName,
args,
choiceList,
hint = None,
descriptionSeparator = '::',
labelAttr = '',
attr = '' )
Make a select statement (including label with text).

Definition at line 183 of file WebPage.py.

184 labelAttr='', attr=''):
185 """Make a select statement (including label with text)."""
186 snippet = htmlLabel(labelText,parName,labelAttr)
187 default = args[parName] if parName in args else ''
188 if not isinstance(default,list):
189 default = [default]
190 snippet += '<select name="%s"%s>\n' % (parName,sep(attr))
191 if hint:
192 snippet += '<option value="">%s</option>\n' % hint
193 for c in choiceList:
194 p = c.split(descriptionSeparator)
195 if len(p)==2:
196 (desc,val) = p
197 else:
198 (desc,val) = (c,c)
199 if val in default:
200 snippet += '<option selected="yes" value="%s">%s</option>\n' % (val,desc)
201 else:
202 snippet += '<option value="%s">%s</option>\n' % (val,desc)
203 snippet += '</select>\n'
204 return snippet
205

◆ htmlSubmit()

WebPage.htmlSubmit ( text,
parName,
attr = '',
onlyOnce = False )
Make a submit button. If onlyOnce is true, the button can only
   be clicked once in order to prevent multiple clicking of the
   submit button.

Definition at line 227 of file WebPage.py.

227def htmlSubmit(text, parName, attr='', onlyOnce=False):
228 """Make a submit button. If onlyOnce is true, the button can only
229 be clicked once in order to prevent multiple clicking of the
230 submit button."""
231 if onlyOnce:
232 # FIXME: this doesn't work yet - it disables submission
233 s = '<input type="button" name="%s" value="%s"' % (parName,text)
234 s += ' onclick="this.form.submit()"'
235 s += '%s />\n' % sep(attr)
236 return s
237 else:
238 return '<input type="submit" name="%s" value="%s"%s />\n' % (parName,text,sep(attr))
239
240
241#
242# Utility classes
243#

◆ htmlText()

WebPage.htmlText ( text,
attr = '',
escapeText = False )
Make a text consisting of an unnamed div. Special HTML characters
   in the text are properly replaced (using escape from cgi) if
   escapeText is set True.

Definition at line 58 of file WebPage.py.

58def htmlText(text, attr='', escapeText=False):
59 """Make a text consisting of an unnamed div. Special HTML characters
60 in the text are properly replaced (using escape from cgi) if
61 escapeText is set True."""
62 return '<div%s>%s</div>\n' % (sep(attr),escape(text) if escapeText else text)
63

◆ htmlTextInput()

WebPage.htmlTextInput ( labelText,
parName,
args,
size = None,
maxLength = None,
labelAttr = '',
attr = '' )
Make a text input area (including label with text). Special HTML
   characters in any default text are properly replaced.

Definition at line 213 of file WebPage.py.

213def htmlTextInput(labelText, parName, args, size=None, maxLength = None, labelAttr='', attr=''):
214 """Make a text input area (including label with text). Special HTML
215 characters in any default text are properly replaced."""
216 snippet = htmlLabel(labelText,parName,labelAttr)
217 snippet += '<input type="text" name="%s"' % parName
218 if parName in args:
219 snippet += ' value="%s"' % escape(args[parName],True)
220 if size!=None:
221 snippet += ' size="%s"' % size
222 if maxLength!=None:
223 snippet += ' maxlength="%s"' % maxLength
224 snippet += '%s/>\n' % sep(attr)
225 return snippet
226

◆ sep()

WebPage.sep ( s)
Add separator to string s unless s is empty.

Definition at line 42 of file WebPage.py.

42def sep(s):
43 """Add separator to string s unless s is empty."""
44 return ' '+s if s else s
45

Variable Documentation

◆ __author__

str WebPage.__author__ = 'Juerg Beringer'
private

Definition at line 9 of file WebPage.py.

◆ __version__

str WebPage.__version__ = 'WebPage.py atlas/athena'
private

Definition at line 10 of file WebPage.py.

◆ endPage

str WebPage.endPage
Initial value:
1= """\
2</body>
3</html>\
4"""

Definition at line 33 of file WebPage.py.

◆ startPage

str WebPage.startPage
Initial value:
1= """\
2%(contentType)s<?xml version="1.0" encoding="UTF-8"?>
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4<html xmlns="http://www.w3.org/1999/xhtml">
5<head>
6<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7<title>%(pageTitle)s</title>
8<link href="%(cssName)s" rel="stylesheet" type="text/css" />
9%(pageHeaderSnippets)s\
10</head>
11<body>
12"""

Definition at line 20 of file WebPage.py.