コード例 #1
0
def format_datetime(dt,
                    format='medium',
                    locale=None,
                    timezone=None,
                    server_tz=False,
                    keep_tz=False):
    """
    Basically a wrapper around Babel's own format_datetime
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if keep_tz:
        assert timezone is None
        timezone = dt.tzinfo
    elif not timezone and dt.tzinfo:
        timezone = DisplayTZ().getDisplayTZ()
    elif server_tz:
        timezone = Config.getInstance().getDefaultTimezone()

    rv = _format_datetime(dt, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(
        rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #2
0
def format_datetime(dt,
                    format='medium',
                    locale=None,
                    timezone=None,
                    server_tz=False,
                    keep_tz=False):
    """
    Basically a wrapper around Babel's own format_datetime
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if keep_tz:
        assert timezone is None
        timezone = dt.tzinfo
    elif not timezone and dt.tzinfo:
        timezone = session.tzinfo
    elif server_tz:
        timezone = config.DEFAULT_TIMEZONE

    rv = _format_datetime(dt, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(
        rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #3
0
ファイル: date_time.py プロジェクト: uxmaster/indico
def format_time(t,
                format='short',
                locale=None,
                timezone=None,
                server_tz=False,
                as_unicode=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    inject_unicode = True
    if format == 'code':
        format = 'HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = session.tzinfo
    elif server_tz:
        timezone = config.DEFAULT_TIMEZONE
    if isinstance(timezone, basestring):
        timezone = get_timezone(timezone)
    rv = _format_time(t, format=format, locale=locale, tzinfo=timezone)
    if as_unicode:
        return rv
    return inject_unicode_debug(
        rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #4
0
def format_timedelta(td, format='short', threshold=0.85, locale=None):
    """
    Basically a wrapper around Babel's own format_timedelta
    """
    if not locale:
        locale = get_current_locale()

    rv = _format_timedelta(td, format=format, locale=locale, threshold=threshold)
    return inject_unicode_debug(rv, 2).encode('utf-8')
コード例 #5
0
ファイル: date_time.py プロジェクト: indico/indico
def format_timedelta(td, format='short', threshold=0.85, locale=None):
    """
    Basically a wrapper around Babel's own format_timedelta
    """
    if not locale:
        locale = get_current_locale()

    rv = _format_timedelta(td, format=format, locale=locale, threshold=threshold)
    return inject_unicode_debug(rv, 2).encode('utf-8')
コード例 #6
0
ファイル: date_time.py プロジェクト: indico/indico
def format_datetime(dt, format='medium', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_datetime
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and dt.tzinfo:
        timezone = session.tzinfo

    rv = _format_datetime(dt, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #7
0
def format_date(d, format='medium', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_date
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if timezone and isinstance(d, datetime) and d.tzinfo:
        d = d.astimezone(pytz.timezone(timezone) if isinstance(timezone, basestring) else timezone)

    rv = _format_date(d, format=format, locale=locale)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #8
0
ファイル: date_time.py プロジェクト: indico/indico
def format_date(d, format='medium', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_date
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if timezone and isinstance(d, datetime) and d.tzinfo:
        d = d.astimezone(pytz.timezone(timezone) if isinstance(timezone, basestring) else timezone)

    rv = _format_date(d, format=format, locale=locale)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #9
0
ファイル: date_time.py プロジェクト: maniacs-oss/indico
def format_datetime(dt, format='medium', locale=None, timezone=None):
    """
    Basically a wrapper around Babel's own format_datetime
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and dt.tzinfo:
        timezone = session.tzinfo

    rv = _format_datetime(dt, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(
        rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #10
0
def gettext_unicode(*args, **kwargs):
    from indico.util.string import inject_unicode_debug
    func_name = kwargs.pop('func_name', 'ugettext')
    plugin_name = kwargs.pop('plugin_name', None)
    force_unicode = kwargs.pop('force_unicode', False)

    if not isinstance(args[0], unicode):
        args = [(text.decode('utf-8') if isinstance(text, str) else text) for text in args]
        using_unicode = force_unicode
    else:
        using_unicode = True

    translations = get_translation_domain(plugin_name).get_translations()
    res = getattr(translations, func_name)(*args, **kwargs)
    res = inject_unicode_debug(res)
    if not using_unicode:
        res = res.encode('utf-8')
    return res
コード例 #11
0
ファイル: date_time.py プロジェクト: indico/indico
def format_time(t, format='short', locale=None, timezone=None, server_tz=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    inject_unicode = True
    if format == 'code':
        format = 'HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = session.tzinfo
    elif server_tz:
        timezone = config.DEFAULT_TIMEZONE
    if isinstance(timezone, basestring):
        timezone = get_timezone(timezone)
    rv = _format_time(t, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #12
0
ファイル: i18n.py プロジェクト: OmeGak/indico
def gettext_unicode(*args, **kwargs):
    from indico.util.string import inject_unicode_debug
    func_name = kwargs.pop('func_name', 'ugettext')
    plugin_name = kwargs.pop('plugin_name', None)
    force_unicode = kwargs.pop('force_unicode', False)

    if not isinstance(args[0], unicode):
        args = [(text.decode('utf-8') if isinstance(text, str) else text) for text in args]
        using_unicode = force_unicode
    else:
        using_unicode = True

    translations = get_translation_domain(plugin_name).get_translations()
    res = getattr(translations, func_name)(*args, **kwargs)
    res = inject_unicode_debug(res)
    if not using_unicode:
        res = res.encode('utf-8')
    return res
コード例 #13
0
def format_time(t, format='short', locale=None, timezone=None, server_tz=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    inject_unicode = True
    if format == 'code':
        format = 'HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = DisplayTZ().getDisplayTZ()
    elif server_tz:
        timezone = Config.getInstance().getDefaultTimezone()
    if timezone:
        timezone = get_timezone(timezone)

    rv = _format_time(t, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #14
0
def format_datetime(dt, format='medium', locale=None, timezone=None, server_tz=False, keep_tz=False):
    """
    Basically a wrapper around Babel's own format_datetime
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if keep_tz:
        assert timezone is None
        timezone = dt.tzinfo
    elif not timezone and dt.tzinfo:
        timezone = DisplayTZ().getDisplayTZ()
    elif server_tz:
        timezone = Config.getInstance().getDefaultTimezone()

    rv = _format_datetime(dt, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #15
0
ファイル: date_time.py プロジェクト: bkolobara/indico
def format_datetime(dt, format='medium', locale=None, timezone=None, server_tz=False, keep_tz=False):
    """
    Basically a wrapper around Babel's own format_datetime
    """
    inject_unicode = True
    if format == 'code':
        format = 'dd/MM/yyyy HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if keep_tz:
        assert timezone is None
        timezone = dt.tzinfo
    elif not timezone and dt.tzinfo:
        timezone = session.tzinfo
    elif server_tz:
        timezone = config.DEFAULT_TIMEZONE

    rv = _format_datetime(dt, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #16
0
def format_time(t,
                format='short',
                locale=None,
                timezone=None,
                server_tz=False):
    """
    Basically a wrapper around Babel's own format_time
    """
    inject_unicode = True
    if format == 'code':
        format = 'HH:mm'
        inject_unicode = False
    if not locale:
        locale = get_current_locale()
    if not timezone and t.tzinfo:
        timezone = DisplayTZ().getDisplayTZ()
    elif server_tz:
        timezone = Config.getInstance().getDefaultTimezone()
    if timezone:
        timezone = get_timezone(timezone)

    rv = _format_time(t, format=format, locale=locale, tzinfo=timezone)
    return inject_unicode_debug(
        rv, 2).encode('utf-8') if inject_unicode else rv.encode('utf-8')
コード例 #17
0
ファイル: date_time.py プロジェクト: indico/indico
def format_number(number, locale=None):
    if not locale:
        locale = get_current_locale()
    rv = _format_number(number, locale=locale)
    return inject_unicode_debug(rv, 2).encode('utf-8')
コード例 #18
0
def format_number(number, locale=None):
    if not locale:
        locale = get_current_locale()
    rv = _format_number(number, locale=locale)
    return inject_unicode_debug(rv, 2).encode('utf-8')