Re: [FE-discuss] Multiple HTML fields to one Python value, …

Top Page
Author: Mike Orr
Date:  
To: formencode-discuss
Subject: Re: [FE-discuss] Multiple HTML fields to one Python value, and vice-versa
I got my LatitudeLongitude widget to work by making the value a dict
containing both the HTML values and Python values. The code is too
long to post, but here's the docstring.

The html fields are name='lat_lon.input_style' etc. The error name is
'lat_lon'.

class LatitudeLongitude(v.FancyValidator):
    """A composite widget for a latitude/longitude pair.

       The value is a dict with the following keys:

           lat: a float acceptable to the Latitude converter, or None.
           lon: a float acceptable to the Longitude converter, or None.

           [RADIO BUTTONS]
           input_style: the input style chosen by the user.
               "d" means degrees. (default)
               "dm" means degrees/minutes.
               "dms" means degrees/minutes/seconds.

          [JAVASCRIPT SHOWS THE FIELDS FOR THE INPUT STYLE CHOSEN.
NON-JAVASCRIPT USERS SEE ALL FIELDS.]

           [TEXT FIELDS AND A SELECT]
           lat_d_deg: latitude degrees for style 'd'.  (float)
           lat_d_dir: latitude direction for style 'd'. "North" or "South".
           lon_d_deg: longitude degrees for style 'd'. (float)
           lon_d_dir: longitude direction for style 'd'. "West" or "East".

           lat_dm_deg: latitude degrees for style 'dm'. (int)
           lat_dm_min: latitude minutes for style 'dm'. (float)
           lat_dm_dir: latitude direction for style 'dm'.
           lon_dm_deg: longitude degrees for style 'dm'. (int)
           lon_dm_min: longitude minutes for style 'dm'. (float)
           lon_dm_dir: longitiude direction for style 'dm'.

           lat_dms_deg: latitude degrees for style 'dms'. (int)
           lat_dms_min: latitude minutes for style 'dms'. (int)
           lat_dms_sec: latitude seconds for style 'dms'. (float)converter_
           lat_dms_dir: latitude direction for style 'dms'.
           lon_dms_deg: longitude degrees for style 'dms'. (int)
           lon_dms_min: longitude minutes for style 'dms'. (int)
           lon_dms_sec: longitude seconds for style 'dms'. (float)
           lon_dms_dir: longitude direction for style 'dms'.

       .from_python() expands 'lat' and 'lon' into the other keys. Illegal
       values are treated like None, so never raise Invalid.

       .to_python() parses the other keys into 'lat' and 'lon', possibly
       raising Invalid.

       .get_html_values(lat, lon) builds a compatible dict from scratch.
       Controllers can call this to get the initial HTML values to populate
       a form.  For "new" forms, call self.get_html_values(None, None).
    """

-- 
Mike Orr <sluggoster@???>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
FormEncode-discuss mailing list
FormEncode-discuss@???
https://lists.sourceforge.net/lists/listinfo/formencode-discuss