magic-removal: Merged to [1817]

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1818 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-04 17:06:16 +00:00
parent d694478813
commit 1db708d4d7
16 changed files with 543 additions and 175 deletions

View File

@ -19,6 +19,6 @@ for (dirpath, dirnames, filenames) in os.walk(basedir):
if file.endswith('.po'):
sys.stderr.write('processing file %s in %s\n' % (file, dirpath))
pf = os.path.splitext(os.path.join(dirpath, file))[0]
cmd = 'msgfmt -o %s.mo %s.po' % (pf, pf)
cmd = 'msgfmt -o "%s.mo" "%s.po"' % (pf, pf)
os.system(cmd)

View File

@ -118,7 +118,7 @@ for lang in languages:
os.unlink(os.path.join(dirpath, thefile))
if os.path.exists(potfile):
(stdin, stdout, stderr) = os.popen3('msguniq %s' % potfile, 'b')
(stdin, stdout, stderr) = os.popen3('msguniq "%s"' % potfile, 'b')
msgs = stdout.read()
errors = stderr.read()
if errors:
@ -127,7 +127,7 @@ for lang in languages:
sys.exit(8)
open(potfile, 'w').write(msgs)
if os.path.exists(pofile):
(stdin, stdout, stderr) = os.popen3('msgmerge -q %s %s' % (pofile, potfile), 'b')
(stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
msgs = stdout.read()
errors = stderr.read()
if errors:

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2005-12-29 00:05+0100\n"
"POT-Creation-Date: 2005-12-30 23:37-0500\n"
"PO-Revision-Date: 2005-11-10 23:22-0500\n"
"Last-Translator: Vladimir Labath <vlado@labath.org>\n"
"Language-Team: Slovak <sk@li.org>\n"
@ -16,6 +16,37 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: contrib/redirects/models/redirects.py:7
msgid "redirect from"
msgstr "presmerovaný z"
#: contrib/redirects/models/redirects.py:8
msgid ""
"This should be an absolute path, excluding the domain name. Example: '/"
"events/search/'."
msgstr ""
"Tu by sa mala použiť absolútna cesta, bez domény. Napr.: '/events/search/'."
#: contrib/redirects/models/redirects.py:9
msgid "redirect to"
msgstr "presmerovaný na "
#: contrib/redirects/models/redirects.py:10
msgid ""
"This can be either an absolute path (as above) or a full URL starting with "
"'http://'."
msgstr ""
"Tu môže byť buď absolútna cesta (ako hore) alebo plné URL začínajúce s "
"'http://'."
#: contrib/redirects/models/redirects.py:12
msgid "redirect"
msgstr "presmerovanie"
#: contrib/redirects/models/redirects.py:13
msgid "redirects"
msgstr "presmerovania"
#: contrib/comments/models/comments.py:8
#: contrib/comments/models/comments.py:161
msgid "object ID"
@ -286,6 +317,58 @@ msgstr ""
msgid "The comment form didn't provide either 'preview' or 'post'"
msgstr "Formulár komentára neposkytuje odpoveď buď 'prezri' alebo 'pošli'"
#: contrib/flatpages/models/flatpages.py:6 contrib/admin/views/doc.py:267
msgid "URL"
msgstr "URL"
#: contrib/flatpages/models/flatpages.py:7
msgid ""
"Example: '/about/contact/'. Make sure to have leading and trailing slashes."
msgstr ""
"Príklad: '/about/contact/'. Uistite sa, že máte vložené ako úvodné tak aj "
"záverečné lomítka."
#: contrib/flatpages/models/flatpages.py:8
msgid "title"
msgstr "názov"
#: contrib/flatpages/models/flatpages.py:9
msgid "content"
msgstr "obsah"
#: contrib/flatpages/models/flatpages.py:10
msgid "enable comments"
msgstr "povolené komentáre"
#: contrib/flatpages/models/flatpages.py:11
msgid "template name"
msgstr "meno predlohy"
#: contrib/flatpages/models/flatpages.py:12
msgid ""
"Example: 'flatpages/contact_page'. If this isn't provided, the system will "
"use 'flatpages/default'."
msgstr ""
"Príklad: 'flatpages/contact_page'. Ak sa toto nevykonalo, systém použije "
"'flatpages/default'."
#: contrib/flatpages/models/flatpages.py:13
msgid "registration required"
msgstr "musíte byť zaregistrovaný"
#: contrib/flatpages/models/flatpages.py:13
msgid "If this is checked, only logged-in users will be able to view the page."
msgstr ""
"Ak je toto označené, potom len prihlásený užívateľ môže vidieť túto stránku."
#: contrib/flatpages/models/flatpages.py:17
msgid "flat page"
msgstr "plochá stránka"
#: contrib/flatpages/models/flatpages.py:18
msgid "flat pages"
msgstr "ploché stránky"
#: contrib/admin/filterspecs.py:40
#, python-format
msgid ""
@ -563,10 +646,6 @@ msgstr "Text"
msgid "Time"
msgstr "Čas"
#: contrib/admin/views/doc.py:267 contrib/flatpages/models/flatpages.py:6
msgid "URL"
msgstr "URL"
#: contrib/admin/views/doc.py:268
msgid "U.S. state (two uppercase letters)"
msgstr "U.S. štát (dve veľké písmena)"
@ -575,11 +654,27 @@ msgstr "U.S. štát (dve veľké písmena)"
msgid "XML text"
msgstr "XML text"
#: contrib/admin/templates/widget/date_time.html:3
msgid "Date:"
msgstr ""
#: contrib/admin/templates/widget/date_time.html:4
msgid "Time:"
msgstr "Čas"
#: contrib/admin/templates/widget/file.html:2
msgid "Currently:"
msgstr ""
#: contrib/admin/templates/widget/file.html:3
msgid "Change:"
msgstr "Zmeň:"
#: contrib/admin/templates/admin/object_history.html:3
#: contrib/admin/templates/admin/change_list.html:4
#: contrib/admin/templates/admin/change_form.html:9
#: contrib/admin/templates/admin/base.html:23
#: contrib/admin/templates/admin/delete_confirmation.html:3
#: contrib/admin/templates/admin/change_form.html:9
#: contrib/admin/templates/admin_doc/bookmarklets.html:4
#: contrib/admin/templates/admin_doc/view_detail.html:4
#: contrib/admin/templates/admin_doc/template_tag_index.html:5
@ -595,9 +690,9 @@ msgstr "Zmena hesla"
#: contrib/admin/templates/admin/object_history.html:3
#: contrib/admin/templates/admin/change_list.html:4
#: contrib/admin/templates/admin/change_form.html:9
#: contrib/admin/templates/admin/base.html:23
#: contrib/admin/templates/admin/delete_confirmation.html:3
#: contrib/admin/templates/admin/change_form.html:9
#: contrib/admin/templates/admin_doc/bookmarklets.html:4
#: contrib/admin/templates/admin_doc/view_detail.html:4
#: contrib/admin/templates/admin_doc/template_tag_index.html:5
@ -612,10 +707,10 @@ msgid "Log out"
msgstr "Odhlásenie"
#: contrib/admin/templates/admin/object_history.html:5
#: contrib/admin/templates/admin/500.html:4
#: contrib/admin/templates/admin/change_list.html:5
#: contrib/admin/templates/admin/base.html:29
#: contrib/admin/templates/admin/500.html:4
#: contrib/admin/templates/admin/change_form.html:12
#: contrib/admin/templates/admin/base.html:29
#: contrib/admin/templates/registration/password_change_done.html:4
#: contrib/admin/templates/registration/password_reset_form.html:4
#: contrib/admin/templates/registration/logged_out.html:4
@ -654,13 +749,15 @@ msgstr ""
"Tento object nemá históriu zmien. Možno nebol pridaný prostredníctvom tohoto "
"web admina"
#: contrib/admin/templates/admin/base_site.html:4
msgid "Django site admin"
msgstr "Django web admin"
#: contrib/admin/templates/admin/change_list.html:10
#, python-format
msgid "Add %(name)s"
msgstr ""
#: contrib/admin/templates/admin/base_site.html:7
msgid "Django administration"
msgstr "Administrácia Django"
#: contrib/admin/templates/admin/filter.html:2
#, python-format
msgid " By %(title)s "
msgstr " Od %(title)s "
#: contrib/admin/templates/admin/500.html:4
msgid "Server error"
@ -682,14 +779,17 @@ msgstr ""
"Vznikla chyba. Prostredníctvom e-mailu bol o nej informovaný správca a "
"chyba by mala byť o chviľu odstránená. Ďakujeme za vašu trpezlivosť."
#: contrib/admin/templates/admin/404.html:4
#: contrib/admin/templates/admin/404.html:8
msgid "Page not found"
msgstr "Stránka nebola nájdená"
#: contrib/admin/templates/admin/search_form.html:8
msgid "Go"
msgstr "Choď"
#: contrib/admin/templates/admin/404.html:10
msgid "We're sorry, but the requested page could not be found."
msgstr "Ľutujeme, ale požadovaná stránka nebola nájdená."
#: contrib/admin/templates/admin/base_site.html:4
msgid "Django site admin"
msgstr "Django web admin"
#: contrib/admin/templates/admin/base_site.html:7
msgid "Django administration"
msgstr "Administrácia Django"
#: contrib/admin/templates/admin/index.html:27
#: contrib/admin/templates/admin/change_form.html:14
@ -716,10 +816,14 @@ msgstr "Moje udalosti"
msgid "None available"
msgstr "Nepovolené"
#: contrib/admin/templates/admin/change_list.html:10
#, python-format
msgid "Add %(name)s"
msgstr ""
#: contrib/admin/templates/admin/404.html:4
#: contrib/admin/templates/admin/404.html:8
msgid "Page not found"
msgstr "Stránka nebola nájdená"
#: contrib/admin/templates/admin/404.html:10
msgid "We're sorry, but the requested page could not be found."
msgstr "Ľutujeme, ale požadovaná stránka nebola nájdená."
#: contrib/admin/templates/admin/login.html:15
msgid "Username:"
@ -733,6 +837,24 @@ msgstr "Heslo:"
msgid "Have you <a href=\"/password_reset/\">forgotten your password</a>?"
msgstr "Zabudli ste<a href=\"/password_reset/\"> vaše heslo</a>?"
#: contrib/admin/templates/admin/change_form.html:20
msgid "View on site"
msgstr "Pozri na webe"
#: contrib/admin/templates/admin/change_form.html:28
msgid "Please correct the error below."
msgid_plural "Please correct the errors below."
msgstr[0] "Opravte chybu, čo je nižšie, prosím."
msgstr[1] "Opravte chyby, čo sú nižšie, prosím."
#: contrib/admin/templates/admin/change_form.html:45
msgid "Ordering"
msgstr "Určenie"
#: contrib/admin/templates/admin/change_form.html:48
msgid "Order:"
msgstr "Poradie:"
#: contrib/admin/templates/admin/base.html:23
msgid "Welcome,"
msgstr "Vítajte,"
@ -761,33 +883,6 @@ msgstr ""
msgid "Yes, I'm sure"
msgstr "Ano, som si istý"
#: contrib/admin/templates/admin/filter.html:2
#, python-format
msgid " By %(title)s "
msgstr " Od %(title)s "
#: contrib/admin/templates/admin/search_form.html:7
msgid "Go"
msgstr "Choď"
#: contrib/admin/templates/admin/change_form.html:20
msgid "View on site"
msgstr "Pozri na webe"
#: contrib/admin/templates/admin/change_form.html:28
msgid "Please correct the error below."
msgid_plural "Please correct the errors below."
msgstr[0] "Opravte chybu, čo je nižšie, prosím."
msgstr[1] "Opravte chyby, čo sú nižšie, prosím."
#: contrib/admin/templates/admin/change_form.html:45
msgid "Ordering"
msgstr "Určenie"
#: contrib/admin/templates/admin/change_form.html:48
msgid "Order:"
msgstr "Poradie:"
#: contrib/admin/templates/admin/submit_line.html:3
msgid "Delete"
msgstr "Vymazať"
@ -996,101 +1091,6 @@ msgstr "Editujte tento objekt (nové okno)"
msgid "As above, but opens the admin page in a new window."
msgstr "Ako vyššie, ale stranka admina sa otvorí v novom okne."
#: contrib/admin/templates/widget/date_time.html:3
msgid "Date:"
msgstr ""
#: contrib/admin/templates/widget/date_time.html:4
msgid "Time:"
msgstr "Čas"
#: contrib/admin/templates/widget/file.html:2
msgid "Currently:"
msgstr ""
#: contrib/admin/templates/widget/file.html:3
msgid "Change:"
msgstr "Zmeň:"
#: contrib/redirects/models/redirects.py:7
msgid "redirect from"
msgstr "presmerovaný z"
#: contrib/redirects/models/redirects.py:8
msgid ""
"This should be an absolute path, excluding the domain name. Example: '/"
"events/search/'."
msgstr ""
"Tu by sa mala použiť absolútna cesta, bez domény. Napr.: '/events/search/'."
#: contrib/redirects/models/redirects.py:9
msgid "redirect to"
msgstr "presmerovaný na "
#: contrib/redirects/models/redirects.py:10
msgid ""
"This can be either an absolute path (as above) or a full URL starting with "
"'http://'."
msgstr ""
"Tu môže byť buď absolútna cesta (ako hore) alebo plné URL začínajúce s "
"'http://'."
#: contrib/redirects/models/redirects.py:12
msgid "redirect"
msgstr "presmerovanie"
#: contrib/redirects/models/redirects.py:13
msgid "redirects"
msgstr "presmerovania"
#: contrib/flatpages/models/flatpages.py:7
msgid ""
"Example: '/about/contact/'. Make sure to have leading and trailing slashes."
msgstr ""
"Príklad: '/about/contact/'. Uistite sa, že máte vložené ako úvodné tak aj "
"záverečné lomítka."
#: contrib/flatpages/models/flatpages.py:8
msgid "title"
msgstr "názov"
#: contrib/flatpages/models/flatpages.py:9
msgid "content"
msgstr "obsah"
#: contrib/flatpages/models/flatpages.py:10
msgid "enable comments"
msgstr "povolené komentáre"
#: contrib/flatpages/models/flatpages.py:11
msgid "template name"
msgstr "meno predlohy"
#: contrib/flatpages/models/flatpages.py:12
msgid ""
"Example: 'flatpages/contact_page'. If this isn't provided, the system will "
"use 'flatpages/default'."
msgstr ""
"Príklad: 'flatpages/contact_page'. Ak sa toto nevykonalo, systém použije "
"'flatpages/default'."
#: contrib/flatpages/models/flatpages.py:13
msgid "registration required"
msgstr "musíte byť zaregistrovaný"
#: contrib/flatpages/models/flatpages.py:13
msgid "If this is checked, only logged-in users will be able to view the page."
msgstr ""
"Ak je toto označené, potom len prihlásený užívateľ môže vidieť túto stránku."
#: contrib/flatpages/models/flatpages.py:17
msgid "flat page"
msgstr "plochá stránka"
#: contrib/flatpages/models/flatpages.py:18
msgid "flat pages"
msgstr "ploché stránky"
#: utils/translation.py:350
msgid "DATE_FORMAT"
msgstr ""
@ -1827,3 +1827,5 @@ msgid ""
"Your Web browser doesn't appear to have cookies enabled. Cookies are "
"required for logging in."
msgstr ""
"Vyzerá, že váš web prehliadač nedovoľuje prístup ku cookies. Cookies sú "
" nevýhnutné aby ste sa mohli prilásiť."

View File

@ -21,7 +21,7 @@ class RedirectFallbackMiddleware:
if r is not None:
if r == '':
return httpwrappers.HttpResponseGone()
return httpwrappers.HttpResponseRedirect(r.new_path)
return httpwrappers.HttpResponsePermanentRedirect(r.new_path)
# No redirect was found. Return the response.
return response

View File

@ -32,6 +32,9 @@ The CACHE_BACKEND setting is a quasi-URI; examples are:
locmem:/// A more sophisticaed local memory cache;
this is multi-process- and thread-safe.
dummy:/// Doesn't actually cache. For use in test
environments.
All caches may take arguments; these are given in query-string style. Valid
arguments are:
@ -275,6 +278,29 @@ class _LocMemCache(_SimpleCache):
finally:
self._lock.writer_leaves()
###############
# Dummy cache #
###############
class _DummyCache(_Cache):
def __init__(self, *args, **kwargs):
pass
def get(self, *args, **kwargs):
pass
def set(self, *args, **kwargs):
pass
def delete(self, *args, **kwargs):
pass
def get_many(self, *args, **kwargs):
pass
def has_key(self, *args, **kwargs):
return False
####################
# File-based cache #
####################
@ -443,11 +469,12 @@ class _DBCache(_Cache):
from cgi import parse_qsl
_BACKENDS = {
'memcached' : _MemcachedCache,
'simple' : _SimpleCache,
'locmem' : _LocMemCache,
'file' : _FileCache,
'db' : _DBCache,
'memcached': _MemcachedCache,
'simple': _SimpleCache,
'locmem': _LocMemCache,
'file': _FileCache,
'db': _DBCache,
'dummy': _DummyCache,
}
def get_cache(backend_uri):

View File

@ -117,7 +117,8 @@ def urlize(value):
def urlizetrunc(value, limit):
"""
Converts URLs into clickable links, truncating URLs to the given character limit
Converts URLs into clickable links, truncating URLs to the given character limit,
and adding 'rel=nofollow' attribute to discourage spamming.
Argument: Length to truncate URLs to.
"""
@ -254,7 +255,14 @@ def slice_(value, arg):
for an introduction.
"""
try:
return value[slice(*[x and int(x) or None for x in arg.split(':')])]
bits = []
for x in arg.split(':'):
if len(x) == 0:
bits.append(None)
else:
bits.append(int(x))
return value[slice(*bits)]
except (ValueError, TypeError):
return value # Fail silently.

View File

@ -46,7 +46,7 @@ class CommonMiddleware:
newurl = new_url[1]
if request.GET:
newurl += '?' + request.GET.urlencode()
return httpwrappers.HttpResponseRedirect(newurl)
return httpwrappers.HttpResponsePermanentRedirect(newurl)
return None

View File

@ -212,6 +212,12 @@ class HttpResponseRedirect(HttpResponse):
self['Location'] = redirect_to
self.status_code = 302
class HttpResponsePermanentRedirect(HttpResponse):
def __init__(self, redirect_to):
HttpResponse.__init__(self)
self['Location'] = redirect_to
self.status_code = 301
class HttpResponseNotModified(HttpResponse):
def __init__(self):
HttpResponse.__init__(self)

View File

@ -24,14 +24,16 @@ def timesince(d, now=None):
else:
tz = None
now = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz)
delta = now - d
# ignore microsecond part of 'd' since we removed it from 'now'
delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
since = delta.days * 24 * 60 * 60 + delta.seconds
for i, (seconds, name) in enumerate(chunks):
count = since / seconds
if count != 0:
break
if count < 0:
return '%d milliseconds' % math.floor(delta.microseconds / 1000)
return '%d milliseconds' % math.floor((now - d).microseconds / 1000)
s = '%d %s' % (count, name(count))
if i + 1 < len(chunks):
# Now get the second item

View File

@ -1,28 +1,28 @@
from django.core.extensions import DjangoContext, render_to_response
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect, HttpResponseGone
from django.utils.httpwrappers import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone
def direct_to_template(request, template, **kwargs):
"""
Render a given template with any extra URL parameters in the context as
Render a given template with any extra URL parameters in the context as
``{{ params }}``.
"""
return render_to_response(template, {'params' : kwargs}, context_instance=DjangoContext(request))
def redirect_to(request, url, **kwargs):
"""
Redirect to a given URL.
The given url may contain dict-style string formatting which will be
Redirect to a given URL.
The given url may contain dict-style string formatting, which will be
interpolated against the params in the URL. For example, to redirect from
``/foo/<id>/`` to ``/bar/<id>/``, you could use the following urlpattern::
``/foo/<id>/`` to ``/bar/<id>/``, you could use the following URLconf::
urlpatterns = patterns('',
('^foo/(?p<id>\d+)/$', 'django.views.generic.simple.redirect_to', {'url' : '/bar/%(id)s/'}),
)
If the given url is ``None``, a HttpResponseGone (410) will be issued.
"""
if url is not None:
return HttpResponseRedirect(url % kwargs)
return HttpResponsePermanentRedirect(url % kwargs)
else:
return HttpResponseGone()
return HttpResponseGone()

View File

@ -47,6 +47,12 @@ Examples:
locmem:/// A more sophisticated local memory cache;
this is multi-process- and thread-safe.
dummy:/// **New in Django development version.**
Doesn't actually cache; just implements the
cache backend interface and doesn't do
anything. This is an easy way to turn off
caching for a test environment.
============================== ===========================================
All caches may take arguments -- they're given in query-string style. Valid

View File

@ -357,7 +357,14 @@ types of HTTP responses. Like ``HttpResponse``, these subclasses live in
``HttpResponseRedirect``
The constructor takes a single argument -- the path to redirect to. This
can be a fully qualified URL (e.g. ``"http://www.yahoo.com/search/"``) or an
absolute URL with no domain (e.g. ``"/search/"``).
absolute URL with no domain (e.g. ``"/search/"``). Note that this returns
an HTTP status code 302.
``HttpResponsePermanentRedirect``
**New in Django development version.***
Like ``HttpResponseRedirect``, but it returns a permanent redirect (HTTP
status code 301) instead of a "found" redirect (status code 302).
``HttpResponseNotModified``
The constructor doesn't take any arguments. Use this to designate that a

View File

@ -328,7 +328,7 @@ the following example is valid::
)
# In foo/urls/blog.py
urlpatterns = patterns('foo.views'
urlpatterns = patterns('foo.views',
(r'^$', 'blog.index'),
(r'^archive/$', 'blog.archive'),
)

View File

@ -11,9 +11,319 @@
'0.0'
>>> floatformat(0.0)
'0'
>>> addslashes('"double quotes" and \\'single quotes\\'')
'\\\\"double quotes\\\\" and \\\\\\'single quotes\\\\\\''
>>> capfirst('hello world')
'Hello world'
>>> fix_ampersands('Jack & Jill & Jeroboam')
'Jack &amp; Jill &amp; Jeroboam'
>>> linenumbers('line 1\\nline 2')
'1. line 1\\n2. line 2'
>>> linenumbers('\\n'.join(['x'] * 10))
'01. x\\n02. x\\n03. x\\n04. x\\n05. x\\n06. x\\n07. x\\n08. x\\n09. x\\n10. x'
>>> lower('TEST')
'test'
>>> lower(u'\\xcb') # uppercase E umlaut
u'\\xeb'
>>> make_list('abc')
['a', 'b', 'c']
>>> make_list(1234)
['1', '2', '3', '4']
>>> slugify(' Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/')
'jack-jill-like-numbers-123-and-4-and-silly-characters'
>>> stringformat(1, '03d')
'001'
>>> stringformat(1, 'z')
''
>>> title('a nice title, isn\\'t it?')
"A Nice Title, Isn't It?"
>>> truncatewords('A sentence with a few words in it', 1)
'A ...'
>>> truncatewords('A sentence with a few words in it', 5)
'A sentence with a few ...'
>>> truncatewords('A sentence with a few words in it', 100)
'A sentence with a few words in it'
>>> truncatewords('A sentence with a few words in it', 'not a number')
'A sentence with a few words in it'
>>> upper('Mixed case input')
'MIXED CASE INPUT'
>>> upper(u'\\xeb') # lowercase e umlaut
u'\\xcb'
>>> urlencode('jack & jill')
'jack%20%26%20jill'
>>> urlizetrunc('http://short.com/', 20)
'<a href="http://short.com/" rel="nofollow">http://short.com/</a>'
>>> urlizetrunc('http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 20)
'<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google.co...</a>'
>>> wordcount('')
0
>>> wordcount('oneword')
1
>>> wordcount('lots of words')
3
>>> wordwrap('this is a long paragraph of text that really needs to be wrapped I\\'m afraid', 14)
"this is a long\\nparagraph of\\ntext that\\nreally needs\\nto be wrapped\\nI'm afraid"
>>> ljust('test', 10)
'test '
>>> ljust('test', 3)
'test'
>>> rjust('test', 10)
' test'
>>> rjust('test', 3)
'test'
>>> center('test', 6)
' test '
>>> cut('a string to be mangled', 'a')
' string to be mngled'
>>> cut('a string to be mangled', 'ng')
'a stri to be maled'
>>> cut('a string to be mangled', 'strings')
'a string to be mangled'
>>> escape('<some html & special characters > here')
'&lt;some html &amp; special characters &gt; here'
>>> linebreaks('line 1')
'<p>line 1</p>'
>>> linebreaks('line 1\\nline 2')
'<p>line 1<br />line 2</p>'
>>> removetags('some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags', 'script img')
'some <b>html</b> with alert("You smell") disallowed tags'
>>> striptags('some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags')
'some html with alert("You smell") disallowed tags'
>>> dictsort([{'age': 23, 'name': 'Barbara-Ann'},\
{'age': 63, 'name': 'Ra Ra Rasputin'},\
{'name': 'Jonny B Goode', 'age': 18}], 'age')
[{'age': 18, 'name': 'Jonny B Goode'},\
{'age': 23, 'name': 'Barbara-Ann'},\
{'age': 63, 'name': 'Ra Ra Rasputin'}]
>>> dictsortreversed([{'age': 23, 'name': 'Barbara-Ann'},\
{'age': 63, 'name': 'Ra Ra Rasputin'},\
{'name': 'Jonny B Goode', 'age': 18}], 'age')
[{'age': 63, 'name': 'Ra Ra Rasputin'},\
{'age': 23, 'name': 'Barbara-Ann'},\
{'age': 18, 'name': 'Jonny B Goode'}]
>>> first([0,1,2])
0
>>> first('')
''
>>> first('test')
't'
>>> join([0,1,2], 'glue')
'0glue1glue2'
>>> length('1234')
4
>>> length([1,2,3,4])
4
>>> length_is([], 0)
True
>>> length_is([], 1)
False
>>> length_is('a', 1)
True
>>> length_is('a', 10)
False
>>> slice_('abcdefg', '0')
''
>>> slice_('abcdefg', '1')
'a'
>>> slice_('abcdefg', '-1')
'abcdef'
>>> slice_('abcdefg', '1:2')
'b'
>>> slice_('abcdefg', '1:3')
'bc'
>>> slice_('abcdefg', '0::2')
'aceg'
>>> unordered_list(['item 1', []])
'\\t<li>item 1</li>'
>>> unordered_list(['item 1', [['item 1.1', []]]])
'\\t<li>item 1\\n\\t<ul>\\n\\t\\t<li>item 1.1</li>\\n\\t</ul>\\n\\t</li>'
>>> unordered_list(['item 1', [['item 1.1', []], ['item 1.2', []]]])
'\\t<li>item 1\\n\\t<ul>\\n\\t\\t<li>item 1.1</li>\\n\\t\\t<li>item 1.2</li>\\n\\t</ul>\\n\\t</li>'
>>> add('1', '2')
3
>>> get_digit(123, 1)
3
>>> get_digit(123, 2)
2
>>> get_digit(123, 3)
1
>>> get_digit(123, 4)
0
>>> get_digit(123, 0)
123
>>> get_digit('xyz', 0)
'xyz'
# real testing of date() is in dateformat.py
>>> date(datetime.datetime(2005, 12, 29), "d F Y")
'29 December 2005'
# real testing of time() is done in dateformat.py
>>> time(datetime.time(13), "h")
'01'
# real testing is done in timesince.py, where we can provide our own 'now'
>>> timesince(datetime.datetime.now() - datetime.timedelta(1))
'1 day'
>>> default("val", "default")
'val'
>>> default(None, "default")
'default'
>>> default('', "default")
'default'
>>> default_if_none("val", "default")
'val'
>>> default_if_none(None, "default")
'default'
>>> default_if_none('', "default")
''
>>> divisibleby(4, 2)
True
>>> divisibleby(4, 3)
False
>>> yesno(True)
'yes'
>>> yesno(False)
'no'
>>> yesno(None)
'maybe'
>>> yesno(True, 'certainly,get out of town,perhaps')
'certainly'
>>> yesno(False, 'certainly,get out of town,perhaps')
'get out of town'
>>> yesno(None, 'certainly,get out of town,perhaps')
'perhaps'
>>> yesno(None, 'certainly,get out of town')
'get out of town'
>>> filesizeformat(1023)
'1023 bytes'
>>> filesizeformat(1024)
'1.0 KB'
>>> filesizeformat(10*1024)
'10.0 KB'
>>> filesizeformat(1024*1024-1)
'1024.0 KB'
>>> filesizeformat(1024*1024)
'1.0 MB'
>>> filesizeformat(1024*1024*50)
'50.0 MB'
>>> filesizeformat(1024*1024*1024-1)
'1024.0 MB'
>>> filesizeformat(1024*1024*1024)
'1.0 GB'
>>> pluralize(1)
''
>>> pluralize(0)
's'
>>> pluralize(2)
's'
>>> phone2numeric('0800 flowers')
'0800 3569377'
"""
from django.core.template.defaultfilters import *
import datetime
if __name__ == '__main__':
import doctest

View File

@ -208,7 +208,7 @@ if __name__ == "__main__":
parser.add_option('-v', help='How verbose should the output be? Choices are 0, 1 and 2, where 2 is most verbose. Default is 0.',
type='choice', choices=['0', '1', '2'])
parser.add_option('--settings',
help='Python path to settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')
help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')
options, args = parser.parse_args()
verbosity_level = 0
if options.v: