More code cleanup

This commit is contained in:
Christopher Grebs
2014-02-22 14:23:04 +01:00
parent ff8e5d7a62
commit 2948312d3e
5 changed files with 17 additions and 23 deletions

View File

@@ -200,7 +200,7 @@ would render: **4/1/07**, and
would render: **Sun, Apr 01 2007 AD**
### `datetimefmt`
### `datetimefmt`
Renders a string representation of a date and time.

View File

@@ -1,10 +1,7 @@
# -*- coding: utf-8 -*-
from babel.core import *
from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
from django.utils.translation.trans_real import inline_re, block_re, \
endblock_re, plural_re, \
constant_re
from django.utils.translation.trans_real import (
inline_re, block_re, endblock_re, plural_re, constant_re)
def extract_django(fileobj, keywords, comment_tags, options):
@@ -89,7 +86,7 @@ def extract_django(fileobj, keywords, comment_tags, options):
yield lineno, None, unicode(cmatch.group(1)), []
for p in parts[1:]:
if p.find(':_(') >= 0:
p1 = p.split(':',1)[1]
p1 = p.split(':', 1)[1]
if p1[0] == '_':
p1 = p1[1:]
if p1[0] == '(':

View File

@@ -23,6 +23,7 @@ def get_current_locale():
class LocaleMiddleware(object):
"""Simple Django middleware that makes available a Babel `Locale` object
via the `request.locale` attribute.
"""

View File

@@ -1,15 +1,4 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 Edgewall Software
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://babel.edgewall.org/wiki/License.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://babel.edgewall.org/log/.
from django.conf import settings
from django.template import Library
@@ -27,6 +16,7 @@ Locale = babel.core.Locale
register = Library()
def _get_format():
locale = get_current_locale()
if not locale:
@@ -37,34 +27,42 @@ def _get_format():
tzinfo = None
return Format(locale, tzinfo)
def datefmt(date=None, format='medium'):
return _get_format().date(date, format=format)
datefmt = register.filter(datefmt)
def datetimefmt(datetime=None, format='medium'):
return _get_format().datetime(datetime, format=format)
datetimefmt = register.filter(datetimefmt)
def timefmt(time=None, format='medium'):
return _get_format().time(time, format=format)
timefmt = register.filter(timefmt)
def numberfmt(number):
return _get_format().number(number)
numberfmt = register.filter(numberfmt)
def decimalfmt(number, format=None):
return _get_format().decimal(number, format=format)
decimalfmt = register.filter(decimalfmt)
def currencyfmt(number, currency):
return _get_format().currency(number, currency)
currencyfmt = register.filter(currencyfmt)
def percentfmt(number, format=None):
return _get_format().percent(number, format=format)
percentfmt = register.filter(percentfmt)
def scientificfmt(number):
return _get_format().scientific(number)
scientificfmt = register.filter(scientificfmt)

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup
from setuptools import setup, find_packages
setup(
@@ -12,9 +12,7 @@ setup(
author='Christopher Lenz',
author_email='cmlenz@gmail.com',
url='http://github.com/graingert/django-babel/',
packages=find_packages(
exclude=["*.tests", "*.tests.*", "tests.*", "tests"],
),
packages=find_packages(exclude=('tests',)),
install_requires=['Babel'],
classifiers=[
'Development Status :: 4 - Beta',
@@ -25,7 +23,7 @@ setup(
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
],
entry_points = """
entry_points="""
[babel.extractors]
django = babeldjango.extract:extract_django
""",