]> git.ipfire.org Git - ipfire.org.git/commitdiff
people: Format phone numbers
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 Oct 2018 16:17:00 +0000 (17:17 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 Oct 2018 16:17:00 +0000 (17:17 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/templates/people/modules/cdr.html
src/templates/people/modules/channels.html
src/web/__init__.py

index f50421364b5e32d2fdcd6363f926d1c81f9f960d..80d1ceca28120a7a38fc2ff3c6fff81fda1ab16d 100644 (file)
@@ -16,7 +16,7 @@
                                                {% if c.callee %}
                                                        <a href="/users/{{ c.callee.uid }}">{{ c.callee }}</a>
                                                {% else %}
-                                                       {{ c.callee_number }}
+                                                       {{ format_phone_number(c.callee_number) }}
                                                {% end %}
                                        {% elif c.direction == "outbound" %}
                                                <span class="fas fa-arrow-left text-success"></span>
@@ -24,7 +24,7 @@
                                                {% if c.caller %}
                                                        <a href="/users/{{ c.caller.uid }}">{{ c.caller }}</a>
                                                {% else %}
-                                                       {{ c.caller_number }}
+                                                       {{ format_phone_number(c.caller_number) }}
                                                {% end %}
                                        {% end %}
 
index bd04aeb70927e93fa4a49f043c5a1153757d02b5..0731bcf64bbb2a79023eece995f6a2673b081ee2 100644 (file)
                                                                                        {{ chan.callee_name }}
                                                                                {% end %}
                
-                                                                               <span class="text-muted">({{ chan.callee_number }})</span>
+                                                                               <span class="text-muted">({{ format_phone_number(chan.callee_number) }})</span>
 
                                                                        {% else %}
-                                                                               {{ chan.called_number }}
+                                                                               {{ format_phone_number(chan.called_number) }}
                                                                        {% end %}
                                                                {% elif chan.direction == "outbound" %}
                                                                        <span class="fas fa-arrow-right text-success"></span>
@@ -39,7 +39,7 @@
                                                                                {{ chan.caller_name }}
                                                                        {% end %}
        
-                                                                       <span class="text-muted">({{ chan.caller_number }})</span>
+                                                                       <span class="text-muted">({{ format_phone_number(chan.caller_number) }})</span>
                                                                {% end %}
                
                                                                <br>
index 90653f656f3930aa0eac75c451ea8bfbd76a8e05..807425ca3f7d6335d392f675e4d9f93b97406207 100644 (file)
@@ -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):
        """