From: Michael Tremer Date: Mon, 15 Oct 2018 16:17:00 +0000 (+0100) Subject: people: Format phone numbers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c01ad25324d8b833c0e1bd863f3aef950854a655;p=ipfire.org.git people: Format phone numbers Signed-off-by: Michael Tremer --- diff --git a/src/templates/people/modules/cdr.html b/src/templates/people/modules/cdr.html index f5042136..80d1ceca 100644 --- a/src/templates/people/modules/cdr.html +++ b/src/templates/people/modules/cdr.html @@ -16,7 +16,7 @@ {% if c.callee %} {{ c.callee }} {% else %} - {{ c.callee_number }} + {{ format_phone_number(c.callee_number) }} {% end %} {% elif c.direction == "outbound" %} @@ -24,7 +24,7 @@ {% if c.caller %} {{ c.caller }} {% else %} - {{ c.caller_number }} + {{ format_phone_number(c.caller_number) }} {% end %} {% end %} diff --git a/src/templates/people/modules/channels.html b/src/templates/people/modules/channels.html index bd04aeb7..0731bcf6 100644 --- a/src/templates/people/modules/channels.html +++ b/src/templates/people/modules/channels.html @@ -25,10 +25,10 @@ {{ chan.callee_name }} {% end %} - ({{ chan.callee_number }}) + ({{ format_phone_number(chan.callee_number) }}) {% else %} - {{ chan.called_number }} + {{ format_phone_number(chan.called_number) }} {% end %} {% elif chan.direction == "outbound" %} @@ -39,7 +39,7 @@ {{ chan.caller_name }} {% end %} - ({{ chan.caller_number }}) + ({{ format_phone_number(chan.caller_number) }}) {% end %}
diff --git a/src/web/__init__.py b/src/web/__init__.py index 90653f65..807425ca 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -3,6 +3,7 @@ import logging import itertools import os.path +import phonenumbers import tornado.locale import tornado.options import tornado.web @@ -39,8 +40,9 @@ class Application(tornado.web.Application): # UI Modules "ui_methods" : { - "format_month_name" : self.format_month_name, - "grouper" : grouper, + "format_month_name" : self.format_month_name, + "format_phone_number" : self.format_phone_number, + "grouper" : grouper, }, "ui_modules" : { "Menu" : ui_modules.MenuModule, @@ -290,6 +292,11 @@ class Application(tornado.web.Application): return month + def format_phone_number(self, handler, s): + number = phonenumbers.parse(s, None) + + return phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.INTERNATIONAL) + def grouper(handler, iterator, n): """