1
0
mirror of https://github.com/django/django.git synced 2024-12-25 10:35:48 +00:00

Fixed #12613 -- Added Q and Z to the list of characters supported by the phone2numeric filter. Thanks to gabrielhurley for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12425 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-02-13 14:36:21 +00:00
parent 03924929ba
commit 0e5836dc07
2 changed files with 7 additions and 6 deletions

View File

@ -157,12 +157,12 @@ recapitalize = allow_lazy(recapitalize)
def phone2numeric(phone): def phone2numeric(phone):
"Converts a phone number with letters into its numeric equivalent." "Converts a phone number with letters into its numeric equivalent."
letters = re.compile(r'[A-PR-Y]', re.I) letters = re.compile(r'[A-Z]', re.I)
char2number = lambda m: {'a': '2', 'c': '2', 'b': '2', 'e': '3', char2number = lambda m: {'a': '2', 'b': '2', 'c': '2', 'd': '3', 'e': '3',
'd': '3', 'g': '4', 'f': '3', 'i': '4', 'h': '4', 'k': '5', 'f': '3', 'g': '4', 'h': '4', 'i': '4', 'j': '5', 'k': '5', 'l': '5',
'j': '5', 'm': '6', 'l': '5', 'o': '6', 'n': '6', 'p': '7', 'm': '6', 'n': '6', 'o': '6', 'p': '7', 'q': '7', 'r': '7', 's': '7',
's': '7', 'r': '7', 'u': '8', 't': '8', 'w': '9', 'v': '8', 't': '8', 'u': '8', 'v': '8', 'w': '9', 'x': '9', 'y': '9', 'z': '9',
'y': '9', 'x': '9'}.get(m.group(0).lower()) }.get(m.group(0).lower())
return letters.sub(char2number, phone) return letters.sub(char2number, phone)
phone2numeric = allow_lazy(phone2numeric) phone2numeric = allow_lazy(phone2numeric)

View File

@ -257,6 +257,7 @@ def get_filter_tests():
'filter-phone2numeric01': ('{{ a|phone2numeric }} {{ b|phone2numeric }}', {"a": "<1-800-call-me>", "b": mark_safe("<1-800-call-me>") }, "&lt;1-800-2255-63&gt; <1-800-2255-63>"), 'filter-phone2numeric01': ('{{ a|phone2numeric }} {{ b|phone2numeric }}', {"a": "<1-800-call-me>", "b": mark_safe("<1-800-call-me>") }, "&lt;1-800-2255-63&gt; <1-800-2255-63>"),
'filter-phone2numeric02': ('{% autoescape off %}{{ a|phone2numeric }} {{ b|phone2numeric }}{% endautoescape %}', {"a": "<1-800-call-me>", "b": mark_safe("<1-800-call-me>") }, "<1-800-2255-63> <1-800-2255-63>"), 'filter-phone2numeric02': ('{% autoescape off %}{{ a|phone2numeric }} {{ b|phone2numeric }}{% endautoescape %}', {"a": "<1-800-call-me>", "b": mark_safe("<1-800-call-me>") }, "<1-800-2255-63> <1-800-2255-63>"),
'filter-phone2numeric03': ('{{ a|phone2numeric }}', {"a": "How razorback-jumping frogs can level six piqued gymnasts!"}, "469 729672225-5867464 37647 226 53835 749 747833 49662787!"),
# Ensure iriencode keeps safe strings: # Ensure iriencode keeps safe strings:
'filter-iriencode01': ('{{ url|iriencode }}', {'url': '?test=1&me=2'}, '?test=1&amp;me=2'), 'filter-iriencode01': ('{{ url|iriencode }}', {'url': '?test=1&me=2'}, '?test=1&amp;me=2'),