Changeset 5231


Ignore:
Timestamp:
27/04/09 16:43:47 (10 years ago)
Author:
cbyrom
Message:

Extend ndgcommon code for use with the OAI Info Editor - fix checking
for non-empty ETs - if these only have an attribute set on them, they
won't be evaluated to 'True' in an 'if' statement. Add methods for
getting bools from strings + for setting up select lists.

Location:
ndgCommon/trunk/ndg/common/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/lib/htmlUtilities.py

    r4793 r5231  
    103103    logging.debug("- produced drop down contents: '%s'" %r) 
    104104    return options 
     105 
     106 
     107def setupDropdownList(list, selected=None, defaultVal=None): 
     108    '''  
     109    Gets a dropdown option list suitable for use in the h.select helper 
     110    @param list: list of items to include in the drop down 
     111    @keyword selected: the value currently selected 
     112    @keyword defaultVal: an additional item to add - to represent a default - e.g. 
     113    'all' or 'none' 
     114    ''' 
     115    logging.debug("Setting up drop down list for data") 
     116    if selected: 
     117        logging.debug("(current val:'%s')" %selected) 
     118    r='' 
    105119     
     120    if defaultVal: 
     121        r+='<option value="%s">%s</option>' %(defaultVal, defaultVal) 
     122 
     123    for val in list: 
     124        default='' 
     125        if selected and selected == val: 
     126            default='selected="selected"' 
     127        r+='<option value="%s" %s>%s</option>' %(val, default, val) 
     128     
     129    logging.debug("- produced drop down contents: '%s'" %r) 
     130    return r 
     131     
  • ndgCommon/trunk/ndg/common/src/lib/utilities.py

    r5215 r5231  
    709709        logging.debug("Element not found") 
    710710    return index 
     711 
     712 
     713def getBool(val): 
     714    ''' 
     715    Return the boolean version of the input val 
     716    @param val: string (or bool) to determine the boolean value of 
     717    @return True/False depending on the input val 
     718    ''' 
     719    logging.debug("Determining boolean value of '%s'" %val) 
     720    if val is True or val is False: 
     721        return val 
     722     
     723    val = str(val).strip().lower() 
     724    return not val in ['false','f','n','0','']     
     725     
  • ndgCommon/trunk/ndg/common/src/models/abstractrecord.py

    r5169 r5231  
    3434        logging.debug("Fields initialised") 
    3535 
    36         if et: 
     36        if et != None: 
    3737            self.fromET(et) 
    3838 
Note: See TracChangeset for help on using the changeset viewer.