Changeset 3881

Show
Ignore:
Timestamp:
01/17/08 13:48:04 (7 months ago)
Author:
paul
Message:

Moved the setlocale() call to dApp.init, to give a developer a
chance to:

import dabo
dabo.settings.loadUserLocale = False

Followed through, adding datetime support.


Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/paul/dabo/__init__.py

    r3879 r3881  
    103103import os 
    104104import sys 
    105 import locale 
    106105try: 
    107106    import pysqlite2 
     
    152151from settings import * 
    153152 
    154 if settings.loadUserLocale: 
    155     locale.setlocale(locale.LC_ALL, '') 
    156  
    157153from __version__ import version 
    158154import dColors 
  • branches/paul/dabo/dApp.py

    r3810 r3881  
    158158     
    159159    def __init__(self, selfStart=False, properties=None, *args, **kwargs): 
     160        if dabo.settings.loadUserLocale: 
     161            locale.setlocale(locale.LC_ALL, '') 
     162 
    160163        self._uiAlreadySet = False 
    161164        dabo.dAppRef = self 
  • branches/paul/dabo/lib/dates.py

    r3879 r3881  
    151151 
    152152 
     153def getStringFromDateTime(dateTimeVal): 
     154    """Given a datetime.datetime, convert to string in dabo.settings.dateTimeFormat style.""" 
     155    dateTimeFormat = dabo.settings.dateTimeFormat 
     156    if dateTimeFormat is None: 
     157        # Delegate formatting to the time module, which will take the 
     158        # user's locale into account. 
     159        dateTimeFormat = "%x %X" 
     160    return dateTimeVal.strftime(dateTimeFormat) 
     161 
     162 
    153163def getDateTimeFromString(strVal, formats=None): 
    154164    """Given a string in a defined format, return a datetime object or None.""" 
    155165    global _dtregex 
    156166 
     167    dtFormat = dabo.settings.dateTimeFormat 
    157168    ret = None 
     169 
    158170    if formats is None: 
    159171        formats = ["ISO8601"] 
     172 
     173    if dtFormat is not None: 
     174        formats.append(dtFormat) 
    160175     
    161176    for format in formats: 
     
    195210                pass 
    196211        if ret is not None: 
    197             break    
     212            break 
     213    if ret is None: 
     214        if dtFormat is None: 
     215            # Fall back to the current locale setting in user's os account: 
     216            try: 
     217                ret = datetime.datetime(*time.strptime(strVal, "%x %X")) 
     218            except: 
     219                pass 
    198220    return ret 
    199221 
  • branches/paul/dabo/ui/uiwx/dGrid.py

    r3879 r3881  
    349349    def getStringValue(self, val): 
    350350        """Get the string value to display in the grid.""" 
    351         if isinstance(val, datetime.date): 
     351        if isinstance(val, datetime.datetime): 
     352            return dabo.lib.dates.getStringFromDateTime(val) 
     353        elif isinstance(val, datetime.date): 
    352354            return dabo.lib.dates.getStringFromDate(val) 
    353355        return val 
  • branches/paul/dabo/ui/uiwx/dTextBoxMixin.py

    r3879 r3881  
    510510            strVal = value 
    511511        elif isinstance(value, datetime.datetime): 
    512             # Use the ISO 8601 datetime string format (with a " " separator 
    513             # instead of "T")  
    514             strVal = value.isoformat(" ") 
     512            strVal = dabo.lib.dates.getStringFromDateTime(value) 
    515513        elif isinstance(value, datetime.date): 
    516514            strVal = dabo.lib.dates.getStringFromDate(value)