Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/StickyForm.html
Дата изменения: Fri Apr 8 12:46:13 2016
Дата индексирования: Mon Apr 11 00:37:44 2016
Кодировка:

Поисковые слова: m 8
Python: module StickyForm
 
 
StickyForm (version 1.0.1)
index
StickyForm.py

StickyForm -- state maintaining HTML forms
 
Intended to work with HTMLgen.
 
    What is StickyForm?
 
        It is a class which works with HTMLgen to provide state
        maintaining forms. Forms can load and save their state to and
        from files. This persistent state is what makes them 'sticky'.
 
    Why would I want to use it?
 
        The same reason you'd want to use CGI.pm ;) Actually there are
        many CGI tasks which benefit from forms which can remember
        their settings. For example, in a hypothetical CGI program, a
        user could set their preferences with a form, and later return
        to the form to modify or review them.
 
    How do I use it?
 
        Simply create forms the same way you normally would with
        HTMLgen, only use the StickyForm class instead of the Form
        class.
 
    StickyForm works like a Form with the addition of a state
    attribute, a save method and a restore method.
 
        state -- is a FormState instance which holds the default values 
                 for all form elements.
        save -- tells the FormState instance to save itself to a file.
        restore -- tells the FormState instance to restore itself from a file.
 
    So how do I set a form's state?
 
        You can set a form's state when you create it, and you can
        always change the state later by assigning something else to
        the form's state attribute.
 
    There are three ways to indicate a StickyForm's state upon initialization:
 
        filename -- this loads the state of the form from a file
        FieldStorage -- this sets the state of the form from the 
                        information in the FieldStorage
        FormState -- this sets the state to the FormState instance
 
    For each method here are some examples:
 
        form=StickyForm(state="/tmp/form.txt")
 
        cgi_results=cgi.FieldStorage()
        form=StickyForm(state=cgi_results)
 
        fs=FormState()
        form=StickyForm(state=fs)
 
    What is the FormState class?
 
        This is a simple dictionary which StickyForm uses to store its
        state information. A FormState instance can be intitalized
        with a FieldStorage instance, to create a form state which
        reflects the form data in the FieldStorage instance. This just
        means turning a slightly complex FieldStorage into a simple
        dictionary.
 
    How is the form's state saved?
 
        It is pickled to a file.
 
    Does StickyForm work with Bobo or DocumentTemplate?
 
        Yes, see the [StickyForm page].
 
.. [StickyForm page] http://www.aracnet.com/~amos/stickyform/

 
Modules
       
UserDict
UserList
cPickle
copy
os
re
string
time

 
Classes
       
HTMLgen.Form
StickyForm
UserDict.UserDict
FormState

 
class FormState(UserDict.UserDict)
    This is a Dictionary which holds the state of a form.
 
It is like a simplified FieldStorage class.
Each key is the name of a form element.
Each value is either a string or a list of strings which 
define that value.
 
You can create a FormState from a FieldStorage.
You can save and restore FormStates from text files
 
  Methods defined here:
__init__(self, field_storage=None)
restore(self, filename)
save(self, filename)

Methods inherited from UserDict.UserDict:
__cmp__(self, dict)
__contains__(self, key)
__delitem__(self, key)
__getitem__(self, key)
__len__(self)
__repr__(self)
__setitem__(self, key, item)
clear(self)
copy(self)
get(self, key, failobj=None)
has_key(self, key)
items(self)
iteritems(self)
iterkeys(self)
itervalues(self)
keys(self)
pop(self, key, *args)
popitem(self)
setdefault(self, key, failobj=None)
update(self, dict=None, **kwargs)
values(self)

Class methods inherited from UserDict.UserDict:
fromkeys(cls, iterable, value=None) from __builtin__.classobj

Data and other attributes inherited from UserDict.UserDict:
__hash__ = None

 
class StickyForm(HTMLgen.Form)
    Works like a Form with the addition of a state attribute, a
save method and a restore method.  A form's state is a FormState
instance which holds the default values for all form elements.
 
save tells the FormState instance to save itself to a file.
 
restore tells the FormState instance to restore itself from a file.
 
You can initalize the state 3 ways, with a:
 
    filename -- this loads the state of the form from a file
    FieldStorage -- this sets the state of the form from the
                    information in the FieldStorage
    FormState -- this sets the state to the FormState instance
 
For example:
 
   form=StickyForm(state="/tmp/form.txt")
 
   fs=cgi.FieldStorage()
   form=StickyForm(state=fs)
 
   fs=FormState()
   form=StickyForm(state=fs)
 
  Methods defined here:
__init__(self, cgi=None, state=None, **kw)
__str__(self)
restore(self, filename)
save(self, filename)
with_state(self, input)
Here's where the actual work gets done. Each Input, Select
and Textarea object in the form is modified to reflect it's
value as defined in the form's state.

Methods inherited from HTMLgen.Form:
append(self, *items)
Append any number of items to the form container.

 
Functions
       
dump(data, filename)
load(filename)

 
Data
        CONTYPE = 'Content-Type: text/html\n\n'
DOCTYPE = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">\n<HTML>\n'
PRINTECHO = 1
__author__ = 'Amos Latteier, amos@aracnet.com'
__version__ = '1.0.1'

 
Author
        Amos Latteier, amos@aracnet.com