Changeset 4543

Show
Ignore:
Timestamp:
04/29/08 06:37:17 (3 months ago)
Author:
alberto
Message:

stolen Chris P's tutorial from docs.turbogears.org

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/ToscaWidgetsForms/trunk/docs/tutorials/pylons_two.rst

    r4540 r4543  
     1.. _pylons_tutorial_two: 
     2 
    13Using tw.forms with Pylons. Part 2 
    24================================== 
     5 
     6.. currentmodule:: tw.forms.fields 
    37 
    48Using fancy fields 
     
    1923It has two mechanisms to "inject" these resources: 
    2024 
    21 * The "official" one which is copied from the way TurboGears' widgets injects 
    22   them. This method involves a "master" or "base" template which is inherited 
     25* The "soon-to-be-deprecated" one which is copied from the way 
     26  TurboGears' widgets injects them. 
     27  This method involves a "master" or "base" template which is inherited 
    2328  by every template you want to display widgets on, a special container in 
    2429  which you pass widgets to the template from the controller and a wrapper 
    25   around the (deprecated I believe) ``render_response`` Pylons' function. 
     30  around the ``render_response`` Pylons' function. This method is a **pain** to 
     31  set up and forces widgets to be passed from the controller to the template 
     32  blurring the separation beteween the view and controller layers. 
    2633 
    27 * The (now not so much) "experimental" one which is based on an idea that 
    28   Ian Bicking expressed in his `blog <http://blog.ianbicking.org/lxml-transformations.html>`_. 
     34* The "soon-to-become-official" one which is based on an idea that 
     35  Ian Bicking expressed in his `blog`_. 
    2936  This method is the recommended approach for two important reasons: 
    3037 
     
    3441     between the MVC layers. 
    3542 
    36   **Note**
     43  .. note:
    3744      
    38      This method used to use lxml to inject the tags into the html but it now 
    39      uses regular expressions. This removes the lxml dependency completely. 
     45     This method used to use `lxml`_ to inject the tags into the html but it now 
     46     uses regular expressions. These removes this troublesome `C`_ dependency 
     47     completely. 
    4048 
    4149In this tutorial I will only cover the second mechanism. 
     
    5462        'toscawidgets.middleware.inject_resources' : True, 
    5563        }) 
     64 
     65.. warning:: 
     66 
     67   Configuring the middleware like this to inject resources does not play well 
     68   with cacheing done at Pylons' :func:`render` function. 
     69   In this scenario it is best to inject resources manually by calling 
     70   :func:`tw.api.inject_resources` on the HTML string before cacheing it. 
     71 
    5672 
    5773Add your fancy fields to the form 
     
    93109   * fielderror 
    94110        This class is applied to the divs that display form errors. For example 
    95         to make errors red colored and bold you would add to your page's CSS:: 
     111        to make errors red colored and bold you would add to your page's CSS: 
     112 
     113        .. code-block:: css 
    96114             
    97115            .fielderror { 
     
    101119 
    102120   * fieldhelp 
    103         This class is applied to the divs that display the fields' `help_text` 
    104         attribute. For example, to make the fields' help messages smaller in 
    105         size and lighter in coloryou would add to your page's CSS:: 
     121        This class is applied to the divs that display the fields' 
     122        :attr:`FormField.help_text` attribute. 
     123        For example, to make the fields' help messages smaller in 
     124        size and lighter in coloryou would add to your page's CSS: 
    106125             
     126        .. code-block:: css 
     127 
    107128            .fieldhelp { 
    108129                color: #aaa; 
     
    112133   * has_error 
    113134        This class is applied to the outermost HTML elements of every 
    114         :class:`tw.forms.fields.FormField` that has produced an error when 
     135        :class:`FormField` that has produced an error when 
    115136        validating. 
    116137        For example, to make the fields that have an error have a red 
    117         background you would add to your page's CSS:: 
     138        background you would add to your page's CSS: 
    118139             
     140        .. code-block:: css 
     141 
    119142            input.has_error, 
    120143            select.has_error, 
     
    123146            } 
    124147 
    125 Some other classes are produced by specialized :class:`tw.forms.fields.FormField`\ s. The best 
    126 way to find out all available CSS classes is to use a tool like 
     148   * required 
     149        This class is applied to both the input field and its label when the 
     150        field is a required field. Required fields are found automatically 
     151        by simulating validation with an empty value. 
     152        For example, to make required fields' labels be bolder you would add 
     153        to your page's CSS: 
     154             
     155        .. code-block:: css 
     156 
     157            label.required { 
     158                font-weight: bold; 
     159            } 
     160 
     161Some other classes are produced by specialized :class:`FormField` subclasses. 
     162The best way to find out all available CSS classes is to use a tool like 
    127163`Firebug <http://getfirebug.com/>`_ to query each DOM element. 
    128164 
     
    131167 
    132168XXX: Write me 
     169 
     170 
     171.. _lxml: http://codespeak.net/lxml/ 
     172.. _blog: http://blog.ianbicking.org/lxml-transformations.html 
     173.. _C: http://en.wikipedia.org/wiki/C_(programming_language) 
  • projects/ToscaWidgetsForms/trunk/docs/tutorials/tutorial_index.rst

    r4540 r4543  
    55 
    66.. toctree:: 
    7    :maxdepth: 1 
     7   :maxdepth: 2 
    88 
    99   sample_form 
     10   tg2 
    1011   pylons_one 
    1112   pylons_two