Python django.utils.formats.get_format() Examples

The following are 30 code examples of django.utils.formats.get_format(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.utils.formats , or try the search function .
Example #1
Source File: i18n.py    From python2017 with MIT License 6 votes vote down vote up
def get_formats():
    """
    Returns all formats strings required for i18n to work
    """
    FORMAT_SETTINGS = (
        'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
        'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
        'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
        'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
        'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
    )
    result = {}
    for attr in FORMAT_SETTINGS:
        result[attr] = get_format(attr)
    formats = {}
    for k, v in result.items():
        if isinstance(v, (six.string_types, int)):
            formats[k] = force_text(v)
        elif isinstance(v, (tuple, list)):
            formats[k] = [force_text(value) for value in v]
    return formats 
Example #2
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def _parse_date_fmt():
    fmt = get_format('DATE_FORMAT')
    escaped = False
    output = []
    for char in fmt:
        if escaped:
            escaped = False
        elif char == '\\':
            escaped = True
        elif char in 'Yy':
            output.append('year')
            #if not self.first_select: self.first_select = 'year'
        elif char in 'bEFMmNn':
            output.append('month')
            #if not self.first_select: self.first_select = 'month'
        elif char in 'dj':
            output.append('day')
            #if not self.first_select: self.first_select = 'day'
    return output 
Example #3
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == "0":
            return None
        if y and m and d:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    return '%s-%s-%s' % (y, m, d)
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            else:
                return '%s-%s-%s' % (y, m, d)
        return data.get(name, None) 
Example #4
Source File: i18n.py    From openhgsenti with Apache License 2.0 6 votes vote down vote up
def get_formats():
    """
    Returns all formats strings required for i18n to work
    """
    FORMAT_SETTINGS = (
        'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
        'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
        'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
        'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
        'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
    )
    result = {}
    for module in [settings] + get_format_modules(reverse=True):
        for attr in FORMAT_SETTINGS:
            result[attr] = get_format(attr)
    formats = {}
    for k, v in result.items():
        if isinstance(v, (six.string_types, int)):
            formats[k] = smart_text(v)
        elif isinstance(v, (tuple, list)):
            formats[k] = [smart_text(value) for value in v]
    return formats 
Example #5
Source File: i18n.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
def get_formats():
    """
    Returns all formats strings required for i18n to work
    """
    FORMAT_SETTINGS = (
        'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
        'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
        'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
        'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
        'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
    )
    result = {}
    for module in [settings] + get_format_modules(reverse=True):
        for attr in FORMAT_SETTINGS:
            result[attr] = get_format(attr)
    formats = {}
    for k, v in result.items():
        if isinstance(v, (six.string_types, int)):
            formats[k] = smart_text(v)
        elif isinstance(v, (tuple, list)):
            formats[k] = [smart_text(value) for value in v]
    return formats 
Example #6
Source File: i18n.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def get_formats():
    """
    Returns all formats strings required for i18n to work
    """
    FORMAT_SETTINGS = (
        'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
        'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
        'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
        'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
        'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
    )
    result = {}
    for module in [settings] + get_format_modules(reverse=True):
        for attr in FORMAT_SETTINGS:
            result[attr] = get_format(attr)
    src = []
    for k, v in result.items():
        if isinstance(v, (six.string_types, int)):
            src.append("formats['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(smart_text(v))))
        elif isinstance(v, (tuple, list)):
            v = [javascript_quote(smart_text(value)) for value in v]
            src.append("formats['%s'] = ['%s'];\n" % (javascript_quote(k), "', '".join(v)))
    return ''.join(src) 
Example #7
Source File: widgets.py    From python with Apache License 2.0 6 votes vote down vote up
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == "0":
            return None
        if y and m and d:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    return '%s-%s-%s' % (y, m, d)
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            else:
                return '%s-%s-%s' % (y, m, d)
        return data.get(name) 
Example #8
Source File: widgets.py    From python with Apache License 2.0 6 votes vote down vote up
def format_value(self, value):
        """
        Return a dict containing the year, month, and day of the current value.
        Use dict instead of a datetime to allow invalid dates such as February
        31 to display correctly.
        """
        year, month, day = None, None, None
        if isinstance(value, (datetime.date, datetime.datetime)):
            year, month, day = value.year, value.month, value.day
        elif isinstance(value, six.string_types):
            if settings.USE_L10N:
                try:
                    input_format = get_format('DATE_INPUT_FORMATS')[0]
                    d = datetime.datetime.strptime(force_str(value), input_format)
                    year, month, day = d.year, d.month, d.day
                except ValueError:
                    pass
            match = self.date_re.match(value)
            if match:
                year, month, day = [int(val) for val in match.groups()]
        return {'year': year, 'month': month, 'day': day} 
Example #9
Source File: i18n.py    From python with Apache License 2.0 6 votes vote down vote up
def get_formats():
    """
    Returns all formats strings required for i18n to work
    """
    FORMAT_SETTINGS = (
        'DATE_FORMAT', 'DATETIME_FORMAT', 'TIME_FORMAT',
        'YEAR_MONTH_FORMAT', 'MONTH_DAY_FORMAT', 'SHORT_DATE_FORMAT',
        'SHORT_DATETIME_FORMAT', 'FIRST_DAY_OF_WEEK', 'DECIMAL_SEPARATOR',
        'THOUSAND_SEPARATOR', 'NUMBER_GROUPING',
        'DATE_INPUT_FORMATS', 'TIME_INPUT_FORMATS', 'DATETIME_INPUT_FORMATS'
    )
    result = {}
    for attr in FORMAT_SETTINGS:
        result[attr] = get_format(attr)
    formats = {}
    for k, v in result.items():
        if isinstance(v, (six.string_types, int)):
            formats[k] = force_text(v)
        elif isinstance(v, (tuple, list)):
            formats[k] = [force_text(value) for value in v]
    return formats 
Example #10
Source File: widgets.py    From openhgsenti with Apache License 2.0 6 votes vote down vote up
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == "0":
            return None
        if y and m and d:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    return '%s-%s-%s' % (y, m, d)
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            else:
                return '%s-%s-%s' % (y, m, d)
        return data.get(name) 
Example #11
Source File: widgets.py    From Hands-On-Application-Development-with-PyCharm with MIT License 6 votes vote down vote up
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == '':
            return None
        if y is not None and m is not None and d is not None:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    pass
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            # Return pseudo-ISO dates with zeros for any unselected values,
            # e.g. '2017-0-23'.
            return '%s-%s-%s' % (y or 0, m or 0, d or 0)
        return data.get(name) 
Example #12
Source File: widgets.py    From Hands-On-Application-Development-with-PyCharm with MIT License 6 votes vote down vote up
def format_value(self, value):
        """
        Return a dict containing the year, month, and day of the current value.
        Use dict instead of a datetime to allow invalid dates such as February
        31 to display correctly.
        """
        year, month, day = None, None, None
        if isinstance(value, (datetime.date, datetime.datetime)):
            year, month, day = value.year, value.month, value.day
        elif isinstance(value, str):
            match = self.date_re.match(value)
            if match:
                # Convert any zeros in the date to empty strings to match the
                # empty option value.
                year, month, day = [int(val) or '' for val in match.groups()]
            elif settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    d = datetime.datetime.strptime(value, input_format)
                except ValueError:
                    pass
                else:
                    year, month, day = d.year, d.month, d.day
        return {'year': year, 'month': month, 'day': day} 
Example #13
Source File: widgets.py    From python2017 with MIT License 6 votes vote down vote up
def format_value(self, value):
        """
        Return a dict containing the year, month, and day of the current value.
        Use dict instead of a datetime to allow invalid dates such as February
        31 to display correctly.
        """
        year, month, day = None, None, None
        if isinstance(value, (datetime.date, datetime.datetime)):
            year, month, day = value.year, value.month, value.day
        elif isinstance(value, six.string_types):
            if settings.USE_L10N:
                try:
                    input_format = get_format('DATE_INPUT_FORMATS')[0]
                    d = datetime.datetime.strptime(force_str(value), input_format)
                    year, month, day = d.year, d.month, d.day
                except ValueError:
                    pass
            match = self.date_re.match(value)
            if match:
                year, month, day = [int(val) for val in match.groups()]
        return {'year': year, 'month': month, 'day': day} 
Example #14
Source File: widgets.py    From python2017 with MIT License 6 votes vote down vote up
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == "0":
            return None
        if y and m and d:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    return '%s-%s-%s' % (y, m, d)
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            else:
                return '%s-%s-%s' % (y, m, d)
        return data.get(name) 
Example #15
Source File: widgets.py    From bioforum with MIT License 6 votes vote down vote up
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == "0":
            return None
        if y and m and d:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    return '%s-%s-%s' % (y, m, d)
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            else:
                return '%s-%s-%s' % (y, m, d)
        return data.get(name) 
Example #16
Source File: widgets.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
def value_from_datadict(self, data, files, name):
        y = data.get(self.year_field % name)
        m = data.get(self.month_field % name)
        d = data.get(self.day_field % name)
        if y == m == d == "0":
            return None
        if y and m and d:
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    date_value = datetime.date(int(y), int(m), int(d))
                except ValueError:
                    return '%s-%s-%s' % (y, m, d)
                else:
                    date_value = datetime_safe.new_date(date_value)
                    return date_value.strftime(input_format)
            else:
                return '%s-%s-%s' % (y, m, d)
        return data.get(name, None) 
Example #17
Source File: widgets.py    From bioforum with MIT License 6 votes vote down vote up
def format_value(self, value):
        """
        Return a dict containing the year, month, and day of the current value.
        Use dict instead of a datetime to allow invalid dates such as February
        31 to display correctly.
        """
        year, month, day = None, None, None
        if isinstance(value, (datetime.date, datetime.datetime)):
            year, month, day = value.year, value.month, value.day
        elif isinstance(value, str):
            if settings.USE_L10N:
                input_format = get_format('DATE_INPUT_FORMATS')[0]
                try:
                    d = datetime.datetime.strptime(value, input_format)
                except ValueError:
                    pass
                else:
                    year, month, day = d.year, d.month, d.day
            match = self.date_re.match(value)
            if match:
                year, month, day = [int(val) for val in match.groups()]
        return {'year': year, 'month': month, 'day': day} 
Example #18
Source File: test_weeks.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testSundayStartingWeek(self):
        # FIRST_DAY_OF_WEEK is Sunday for Australia
        self.assertEqual(get_format('FIRST_DAY_OF_WEEK'), 0)
        importlib.reload(ls.joyous.utils.weeks)
        from ls.joyous.utils.weeks import (week_info, num_weeks_in_year,
                gregorian_to_week_date, week_of_month, weekday_abbr, weekday_name,
                _ssweek_info, _ssweek_num_weeks, _gregorian_to_ssweek, _ssweek_of_month)
        self.assertIs(week_info, _ssweek_info)
        self.assertIs(num_weeks_in_year, _ssweek_num_weeks)
        self.assertIs(gregorian_to_week_date, _gregorian_to_ssweek)
        self.assertIs(week_of_month, _ssweek_of_month)
        self.assertEqual(weekday_abbr, ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"))
        self.assertEqual(weekday_name, ("Sunday","Monday","Tuesday","Wednesday","Thursday",
                                        "Friday","Saturday")) 
Example #19
Source File: widgets.py    From python2017 with MIT License 5 votes vote down vote up
def _parse_date_fmt():
        fmt = get_format('DATE_FORMAT')
        escaped = False
        for char in fmt:
            if escaped:
                escaped = False
            elif char == '\\':
                escaped = True
            elif char in 'Yy':
                yield 'year'
            elif char in 'bEFMmNn':
                yield 'month'
            elif char in 'dj':
                yield 'day' 
Example #20
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, six.string_types):
                if settings.USE_L10N:
                    try:
                        input_format = get_format('DATE_INPUT_FORMATS')[0]
                        v = datetime.datetime.strptime(value, input_format)
                        year_val, month_val, day_val = v.year, v.month, v.day
                    except ValueError:
                        pass
                else:
                    match = RE_DATE.match(value)
                    if match:
                        year_val, month_val, day_val = [int(v) for v in match.groups()]
        choices = [(i, i) for i in self.years]
        year_html = self.create_select(name, self.year_field, value, year_val, choices)
        choices = list(six.iteritems(MONTHS))
        month_html = self.create_select(name, self.month_field, value, month_val, choices)
        choices = [(i, i) for i in range(1, 32)]
        day_html = self.create_select(name, self.day_field, value, day_val,  choices)

        output = []
        for field in _parse_date_fmt():
            if field == 'year':
                output.append(year_html)
            elif field == 'month':
                output.append(month_html)
            elif field == 'day':
                output.append(day_html)
        return mark_safe('\n'.join(output)) 
Example #21
Source File: test_weeks.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testMondayStartingWeek(self):
        # FIRST_DAY_OF_WEEK is Monday for Great Britain
        self.assertEqual(get_format('FIRST_DAY_OF_WEEK'), 1)
        importlib.reload(ls.joyous.utils.weeks)
        from ls.joyous.utils.weeks import (week_info, num_weeks_in_year,
                gregorian_to_week_date, week_of_month, weekday_abbr, weekday_name,
                _iso_info, _iso_num_weeks, _gregorian_to_iso, _iso_week_of_month)
        self.assertIs(week_info, _iso_info)
        self.assertIs(num_weeks_in_year, _iso_num_weeks)
        self.assertIs(gregorian_to_week_date, _gregorian_to_iso)
        self.assertIs(week_of_month, _iso_week_of_month)
        self.assertEqual(weekday_abbr, ("Mon","Tue","Wed","Thu","Fri","Sat","Sun"))
        self.assertEqual(weekday_name, ("Monday","Tuesday","Wednesday","Thursday",
                                        "Friday","Saturday","Sunday")) 
Example #22
Source File: widgets.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def _has_changed(self, initial, data):
        try:
            input_format = get_format('DATE_INPUT_FORMATS')[0]
            data = datetime_safe.datetime.strptime(data, input_format).date()
        except (TypeError, ValueError):
            pass
        return super(SelectDateWidget, self)._has_changed(initial, data) 
Example #23
Source File: test_edit_handlers.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testNZLocaleTimeInput(self):
        importlib.reload(ls.joyous.edit_handlers)
        format = get_format('TIME_INPUT_FORMATS')
        self.assertIn('%I:%M%p', format)
        self.assertIn('%I%p', format)


# ------------------------------------------------------------------------------ 
Example #24
Source File: widgets.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_context(self, name, value, attrs):
        context = super().get_context(name, value, attrs)
        config = {
            'dayOfWeekStart': get_format('FIRST_DAY_OF_WEEK'),
            'format':         self.js_format,
        }
        context['widget']['valid_dates'] = json.dumps(self.valid_dates())
        context['widget']['config_json'] = json.dumps(config)
        return context 
Example #25
Source File: views.py    From TWLight with MIT License 5 votes vote down vote up
def get_formats():
    """
    Returns all formats strings required for i18n to work
    """
    FORMAT_SETTINGS = (
        "DATE_FORMAT",
        "DATETIME_FORMAT",
        "TIME_FORMAT",
        "YEAR_MONTH_FORMAT",
        "MONTH_DAY_FORMAT",
        "SHORT_DATE_FORMAT",
        "SHORT_DATETIME_FORMAT",
        "FIRST_DAY_OF_WEEK",
        "DECIMAL_SEPARATOR",
        "THOUSAND_SEPARATOR",
        "NUMBER_GROUPING",
        "DATE_INPUT_FORMATS",
        "TIME_INPUT_FORMATS",
        "DATETIME_INPUT_FORMATS",
    )
    result = {}
    for module in [settings] + get_format_modules(reverse=True):
        for attr in FORMAT_SETTINGS:
            result[attr] = get_format(attr)
    formats = {}
    for k, v in list(result.items()):
        if isinstance(v, (six.string_types, int)):
            formats[k] = smart_text(v)
        elif isinstance(v, (tuple, list)):
            formats[k] = [smart_text(value) for value in v]
    return formats 
Example #26
Source File: widgets.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def _format_value(self, value):
        return formats.localize_input(value,
            self.format or formats.get_format(self.format_key)[0]) 
Example #27
Source File: widgets.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def _parse_date_fmt():
        fmt = get_format('DATE_FORMAT')
        escaped = False
        for char in fmt:
            if escaped:
                escaped = False
            elif char == '\\':
                escaped = True
            elif char in 'Yy':
                yield 'year'
            elif char in 'bEFMmNn':
                yield 'month'
            elif char in 'dj':
                yield 'day' 
Example #28
Source File: utils.py    From django-datatables-view with MIT License 5 votes vote down vote up
def parse_date(formatted_date):
    parsed_date = None
    for date_format in formats.get_format('DATE_INPUT_FORMATS'):
        try:
            parsed_date = datetime.datetime.strptime(formatted_date, date_format)
        except ValueError:
            continue
        else:
            break
    if not parsed_date:
        raise ValueError
    return parsed_date.date() 
Example #29
Source File: widgets.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def render(self, name, value, attrs=None):
        try:
            year_val, month_val, day_val = value.year, value.month, value.day
        except AttributeError:
            year_val = month_val = day_val = None
            if isinstance(value, six.string_types):
                if settings.USE_L10N:
                    try:
                        input_format = get_format('DATE_INPUT_FORMATS')[0]
                        v = datetime.datetime.strptime(force_str(value), input_format)
                        year_val, month_val, day_val = v.year, v.month, v.day
                    except ValueError:
                        pass
                if year_val is None:
                    match = self.date_re.match(value)
                    if match:
                        year_val, month_val, day_val = [int(val) for val in match.groups()]
        html = {}
        choices = [(i, i) for i in self.years]
        html['year'] = self.create_select(name, self.year_field, value, year_val, choices, self.year_none_value)
        choices = list(self.months.items())
        html['month'] = self.create_select(name, self.month_field, value, month_val, choices, self.month_none_value)
        choices = [(i, i) for i in range(1, 32)]
        html['day'] = self.create_select(name, self.day_field, value, day_val, choices, self.day_none_value)

        output = []
        for field in self._parse_date_fmt():
            output.append(html[field])
        return mark_safe('\n'.join(output)) 
Example #30
Source File: user_language.py    From iguana with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def get_user_locale_format(format_key):
    lang = get_user_language()
    frmat = formats.get_format(format_key, lang=lang, use_l10n=True)
    for php_format, py_format in php_py_format_map:
        frmat = frmat.replace(php_format, py_format)
    return frmat