Ejemplo n.º 1
0
def ru_strftime(date, format="%d.%m.%Y", inflected_day=False, preposition=False):
    """
    Russian strftime, formats date with given format.

    Value is a date (supports datetime.date and datetime.datetime),
    parameter is a format (string). For explainings about format,
    see documentation for original strftime:
    http://docs.python.org/lib/module-time.html

    Examples::
        {{ some_date|ru_strftime:"%d %B %Y, %A" }}
    """
    try:
        uformat = utils.provide_unicode(format, encoding, default=u"%d.%m.%Y")
        ures = dt.ru_strftime(uformat,
                              date,
                              inflected=True,
                              inflected_day=inflected_day,
                              preposition=preposition)
        res = utils.provide_str(ures, encoding)
    except Exception, err:
        # because filter must die silently
        try:
            default_date = date.strftime(format)
        except Exception:
            default_date = str(date)
        res = default_value % {'error': err, 'value': default_date}
Ejemplo n.º 2
0
def slugify(stext):
    """Make slug from (russian) text"""
    try:
        res = translit.slugify(
            utils.provide_unicode(
                stext,
                encoding,
                default=default_value
                ))
    except Exception, err:
        # because filter must die silently
        res = default_value % {'error': err, 'value': stext}