mirror of
https://github.com/django/django.git
synced 2025-10-30 17:16:10 +00:00
Fixed #2986 -- Made the JavaScript code that drives related model instance addition in a popup window handle a model representation containing new lines. Also, moved the escapejs functionality yoo django.utils.html so it can be used from Python code. Thanks andrewwatts for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -64,29 +64,10 @@ def capfirst(value):
|
||||
capfirst.is_safe=True
|
||||
capfirst = stringfilter(capfirst)
|
||||
|
||||
_base_js_escapes = (
|
||||
('\\', r'\u005C'),
|
||||
('\'', r'\u0027'),
|
||||
('"', r'\u0022'),
|
||||
('>', r'\u003E'),
|
||||
('<', r'\u003C'),
|
||||
('&', r'\u0026'),
|
||||
('=', r'\u003D'),
|
||||
('-', r'\u002D'),
|
||||
(';', r'\u003B'),
|
||||
(u'\u2028', r'\u2028'),
|
||||
(u'\u2029', r'\u2029')
|
||||
)
|
||||
|
||||
# Escape every ASCII character with a value less than 32.
|
||||
_js_escapes = (_base_js_escapes +
|
||||
tuple([('%c' % z, '\\u%04X' % z) for z in range(32)]))
|
||||
|
||||
def escapejs(value):
|
||||
"""Hex encodes characters for use in JavaScript strings."""
|
||||
for bad, good in _js_escapes:
|
||||
value = value.replace(bad, good)
|
||||
return value
|
||||
from django.utils.html import escapejs
|
||||
return escapejs(value)
|
||||
escapejs = stringfilter(escapejs)
|
||||
|
||||
def fix_ampersands(value):
|
||||
@@ -745,7 +726,6 @@ timesince.is_safe = False
|
||||
def timeuntil(value, arg=None):
|
||||
"""Formats a date as the time until that date (i.e. "4 days, 6 hours")."""
|
||||
from django.utils.timesince import timeuntil
|
||||
from datetime import datetime
|
||||
if not value:
|
||||
return u''
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user