johnf wrote:
> On Tuesday 19 August 2008 11:10:56 am Uwe Grauer wrote:
> 
>> It's too easy to create a specialized class for that purpose.
>> So no, i don't think that a generalized dropdownlist fits into the
>> framework (Dabo). Of cause if i would need it too often i would already
>> have such a dropdownlist class. Instead i put effort into were the
>> display data comes from.
>>
>> There are too many ways to manage the list data.
>> To fill the data i'm using a 2-liner:
>> choices, keys = self.Form.enumBiz.getEnumsByToken('e_sex')
>> sexbox = dabo.ui.dComboBox(self, DataSource="JNP", DataField="e_sex",
>>
>>                            Choices=choices, Keys=keys, ValueMode='Key')
>>
>> The real work went into getEnumsByToken() and the underlying data
>> structure.
>>
>> Uwe
> 
> How about showing "getEnumsByToken"?  
> 
> I ask because I bet you are just getting a dataset and then doing the massage 
> to return choices and keys.  And I bet this happens all the time.  Why not a 
> simple way to use dataset directly.  

getEnumsByToken is used for static lists such as salutation, gender or
family status. There are numerous other use cases for list controls.
Static listcontrols only get filled once in the lifetime of a form
whereas other use case need different handling.
Because of all the different use cases, i see no big improvement for a
databound listcontrol.
But all my static lists use getEnumsByToken.

To manage the underlying data i use a form to search, browse and edit
the data.
If you like it, feel free to use it.
All static data comes from a 2-table structure:

CREATE TABLE ETYP
(
  IID Numeric(18,0) NOT NULL,
  CRESTAMP Timestamp,
  CREUSER Varchar(100),
  UPDSTAMP Timestamp,
  UPDUSER Varchar(100),
  E_TOK Varchar(100) NOT NULL,
  E_VAL Varchar(200) NOT NULL,
  PRIMARY KEY (IID),
  UNIQUE (E_TOK)
);

CREATE TABLE ENUM
(
  IID Numeric(18,0) NOT NULL,
  CRESTAMP Timestamp,
  CREUSER Varchar(100),
  UPDSTAMP Timestamp,
  UPDUSER Varchar(100),
  E_TOK Varchar(100) NOT NULL,
  E_VAL Varchar(200) NOT NULL,
  E_STR1 Varchar(200),
  E_STR2 Varchar(200),
  E_STR3 Varchar(200),
  SORT_ORDER Integer,
  ETYP_IID Numeric(18,0) NOT NULL,
  PRIMARY KEY (IID)
);

ALTER TABLE ENUM ADD
  FOREIGN KEY (ETYP_IID) REFERENCES ETYP (IID);
CREATE UNIQUE INDEX ENUM_UIDX1 ON ENUM (ETYP_IID,E_TOK);

class EnumBizobj(dabo.biz.dBizobj):
    ...
    def getEnumsByToken(self, e_typ_tok):
        """Return a 2-tuple of lists of the types and their keys."""
        crs = self.getTempCursor()
        crs.execute("""select en.iid, en.e_val
        from etyp et join enum en
        on et.iid = en.etyp_iid
        where et.e_tok = ?
        order by sort_order""", (e_typ_tok.upper(),))
        ds = crs.getDataSet()
        # Create the lists
        names = [rec["e_val"] for rec in ds]
        names.insert(0, "-/-")
        keys = [rec["iid"] for rec in ds]
        keys.insert(0, Decimal(0))
        #print (names, keys)
        return (names, keys)
                
Uwe



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to