Back to index

python-weblib  1.3.9
Public Member Functions | Public Attributes | Private Member Functions
pyweblib.forms.Radio Class Reference
Inheritance diagram for pyweblib.forms.Radio:
Inheritance graph
[legend]
Collaboration diagram for pyweblib.forms.Radio:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def setOptions
def inputHTML
def setDefault
def idAttrStr
def labelHTML
def getValue
def setRegex
def setValue
def setCharset
def titleHTML
def valueHTML

Public Attributes

 optionValues
 maxLen
 options
 default
 value
 name
 text
 maxValues
 required
 accessKey
 inputHTMLTemplate
 valueHTMLTemplate
 charset

Private Member Functions

def _validateFormat

Detailed Description

Radio buttons:
<INPUT TYPE=RADIO>

Definition at line 405 of file forms.py.


Constructor & Destructor Documentation

def pyweblib.forms.Radio.__init__ (   self,
  name,
  text,
  maxValues = 1,
  required = 0,
  default = None,
  accessKey = '',
  options = None 
)
pattern and maxLen are determined from __init__ params
Additional parameters:
options=[]
  List of options. Either just a list of strings
  ['value1','value2',..] for simple options
  or a list of tuples of string pairs
  [('value1','description1),('value2','description2),..]
  for options with different option value and description.

Definition at line 414 of file forms.py.

00414 
00415   ):
00416     """
00417     pattern and maxLen are determined from __init__ params
00418     Additional parameters:
00419     options=[]
00420       List of options. Either just a list of strings
00421       ['value1','value2',..] for simple options
00422       or a list of tuples of string pairs
00423       [('value1','description1),('value2','description2),..]
00424       for options with different option value and description.
00425     """
00426     self.setOptions(options)
00427     self.setDefault(default)
00428     Field.__init__(
00429       self,name,text,self.maxLen,maxValues,'',required,default,accessKey
00430     )

Here is the call graph for this function:


Member Function Documentation

def pyweblib.forms.Radio._validateFormat (   self,
  value 
) [private]
Check format of the user's value for this field.

Empty input (zero-length string) are valid in any case.
You might override this method to change this behaviour.

Reimplemented from pyweblib.forms.Field.

Definition at line 431 of file forms.py.

00431 
00432   def _validateFormat(self,value):
00433     """
00434     Check format of the user's value for this field.
00435 
00436     Empty input (zero-length string) are valid in any case.
00437     You might override this method to change this behaviour.
00438     """
00439     if value and (not value in self.optionValues):
00440       raise InvalidValueFormat(
00441         self.name,
00442         self.text.encode(self.charset),
00443         value.encode(self.charset)
00444       )

def pyweblib.forms.Field.getValue (   self) [inherited]
Returns self.value in case of multi-valued input or
self.value[0] if only one value is allowed.

Definition at line 103 of file forms.py.

00103 
00104   def getValue(self):
00105     """
00106     Returns self.value in case of multi-valued input or
00107     self.value[0] if only one value is allowed.
00108     """
00109     if self.maxValues>1:
00110       return self.value
00111     else:
00112       return self.value[0]

def pyweblib.forms.Field.idAttrStr (   self,
  id_value 
) [inherited]

Definition at line 93 of file forms.py.

00093 
00094   def idAttrStr(self,id_value):
00095     if id_value is None:
00096       return ''
00097     else:
00098       return 'id="%s" ' % (id_value)

Here is the caller graph for this function:

def pyweblib.forms.Radio.inputHTML (   self,
  default = None,
  id_value = None,
  title = None 
)

Reimplemented in pyweblib.forms.Select.

Definition at line 459 of file forms.py.

00459 
00460   def inputHTML(self,default=None,id_value=None,title=None):
00461     s = []
00462     default_value = self._defaultValue(default)
00463     for i in self.options:
00464       if type(i) is types.TupleType:
00465         optionValue,optionText = i
00466       else:
00467         optionValue = optionText = i
00468       s.append("""
00469         <input
00470           type="radio"
00471           %s
00472           title="%s"
00473           name="%s"
00474           %s
00475           value="%s"
00476           %s
00477         >%s<br>
00478         """ % (
00479           self.idAttrStr(id_value),
00480           self.titleHTML(title),
00481           self.name.encode(self.charset),
00482           self._accessKeyAttr(),
00483           optionValue,
00484           ' checked'*(optionValue==default_value),
00485           optionText
00486         )
00487       )
00488     return self.inputHTMLTemplate % '\n'.join(s)

Here is the call graph for this function:

def pyweblib.forms.Field.labelHTML (   self,
  labelText = None,
  for_value = None 
) [inherited]

Definition at line 99 of file forms.py.

00099 
00100   def labelHTML(self,labelText=None,for_value=None):
00101     labelText = (labelText or self.text).encode(self.charset)
00102     return '<label for="%s">%s</label>' % (for_value or self.name,labelText)

def pyweblib.forms.Field.setCharset (   self,
  charset 
) [inherited]
Define the character set of the user's input.

Definition at line 212 of file forms.py.

00212 
00213   def setCharset(self,charset):
00214     """Define the character set of the user's input."""
00215     self.charset = charset

def pyweblib.forms.Radio.setDefault (   self,
  default 
)
Set the default of a default field.

Mainly this is used if self.default shall be changed after
initializing the field object.

Reimplemented from pyweblib.forms.Field.

Definition at line 489 of file forms.py.

00489 
00490   def setDefault(self,default):
00491     """
00492     Set the default of a default field.
00493 
00494     Mainly this is used if self.default shall be changed after
00495     initializing the field object.
00496     """
00497     optionValues = []
00498     for i in self.options:
00499       if type(i) is types.TupleType:
00500         optionValues.append(i[0])
00501       else:
00502         optionValues.append(i)
00503     if type(default)==types.StringType and not default in optionValues:
00504       # Append option to list of options if singleton
00505       self.options.append(default)
00506     elif type(default)==types.ListType:
00507       # Extend list of options with items in default which are not in options
00508       self.options.extend(filter(lambda x,o=optionValues:not x in o,default))
00509     self.default = default
00510 

def pyweblib.forms.Radio.setOptions (   self,
  options 
)

Definition at line 445 of file forms.py.

00445 
00446   def setOptions(self,options):
00447     self.optionValues = {}
00448     self.maxLen = 0
00449     if options:
00450       optionValues = []
00451       for i in options:
00452         if type(i) is types.TupleType:
00453           optionValue = i[0]
00454         else:
00455           optionValue = i
00456         self.optionValues[optionValue] = None
00457       self.maxLen = max(map(len,self.optionValues.keys()))
00458     self.options  = options

Here is the caller graph for this function:

def pyweblib.forms.Field.setRegex (   self,
  pattern 
) [inherited]
Set the regex pattern for validating this field.

Mainly this is used if self._re shall be changed after
the field object was initialized.

pattern
Either a string containing a regex pattern,
a tuple (pattern string, pattern options) or None.
If None regex checking in _validateFormat is switched off
(not recommended).

Reimplemented in pyweblib.forms.Textarea.

Definition at line 138 of file forms.py.

00138 
00139   def setRegex(self,pattern):
00140     """
00141     Set the regex pattern for validating this field.
00142 
00143     Mainly this is used if self._re shall be changed after
00144     the field object was initialized.
00145 
00146     pattern
00147         Either a string containing a regex pattern,
00148         a tuple (pattern string, pattern options) or None.
00149         If None regex checking in _validateFormat is switched off
00150         (not recommended).
00151     """
00152     patternstring,patternoptions = self._patternAndOptions(pattern)
00153     if patternstring is None:
00154       # Regex checking is completely switched off
00155       self._re = None
00156     else:
00157       # This is a Unicode input field
00158       patternoptions = patternoptions | re.U
00159       self._re = re.compile('%s$' % patternstring,patternoptions)

Here is the call graph for this function:

def pyweblib.forms.Field.setValue (   self,
  value 
) [inherited]
Store the user's value into the field object.

This method can be used to modify the user's value
before storing it into self.value.

Definition at line 196 of file forms.py.

00196 
00197   def setValue(self,value):
00198     """
00199     Store the user's value into the field object.
00200 
00201     This method can be used to modify the user's value
00202     before storing it into self.value.
00203     """
00204     value = self._encodeValue(value)
00205     # Check if input is valid
00206     # Length valid?
00207     self._validateLen(value)
00208     # Format valid?
00209     self._validateFormat(value)
00210     self._validateMaxValue()
00211     self.value.append(value)

Here is the call graph for this function:

def pyweblib.forms.Field.titleHTML (   self,
  title 
) [inherited]
HTML output of default.

Definition at line 220 of file forms.py.

00220 
00221   def titleHTML(self,title):
00222     """HTML output of default."""
00223     return escapeHTML(title or self.text).encode(self.charset)

Here is the call graph for this function:

Here is the caller graph for this function:

def pyweblib.forms.Field.valueHTML (   self) [inherited]
HTML output of self.value using the HTML template string
in self.valueHTMLTemplate.

Reimplemented in pyweblib.forms.Keygen, pyweblib.forms.Password, and pyweblib.forms.Textarea.

Definition at line 228 of file forms.py.

00228 
00229   def valueHTML(self):
00230     """
00231     HTML output of self.value using the HTML template string
00232     in self.valueHTMLTemplate.
00233     """
00234     return [
00235       self.valueHTMLTemplate % v
00236       for v in self.value
00237     ]
00238 


Member Data Documentation

Definition at line 78 of file forms.py.

Definition at line 83 of file forms.py.

Reimplemented from pyweblib.forms.Field.

Definition at line 508 of file forms.py.

Definition at line 79 of file forms.py.

Reimplemented from pyweblib.forms.Field.

Definition at line 447 of file forms.py.

Definition at line 76 of file forms.py.

Definition at line 73 of file forms.py.

Definition at line 457 of file forms.py.

Definition at line 446 of file forms.py.

Definition at line 77 of file forms.py.

Definition at line 74 of file forms.py.

Definition at line 72 of file forms.py.

Definition at line 80 of file forms.py.


The documentation for this class was generated from the following file: