From 11f1770f5146c35bb94d2cf588e507fdb7081f57 Mon Sep 17 00:00:00 2001 From: Jim Tilander Date: Wed, 4 Jul 2018 23:46:58 -0700 Subject: [PATCH] Better display of phone numbers --- backend/Dockerfile | 18 ++++++++++++------ backend/scripts/ldapmunge.py | 13 ++++++++++++- frontend/app/app.js | 10 ++++++++++ frontend/app/pages/main.html | 2 +- frontend/app/pages/user_details.html | 2 +- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index c6331d0..b6c4455 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -14,12 +14,18 @@ RUN apk add --no-cache \ ENV VISUAL=vi WORKER_COUNT=8 TIMEOUT=300 RUN pip --disable-pip-version-check --no-cache-dir install \ - elasticsearch \ - filelock \ - flask \ - flask-cors \ - flask_restful \ - huey + elasticsearch==6.3.0 \ + filelock==3.0.4 \ + Flask-Cors==3.0.6 \ + Flask-RESTful==0.3.6 \ + Flask==1.0.2 \ + huey==1.10.0 \ + phonenumbers==8.9.9 \ + && \ + pip --disable-pip-version-check --no-cache-dir freeze + + + # ENV HUEY_VERSION=1fbffc7d8ea099bb195d8cb0b4c8841e9fb13ce6 # RUN apk add --no-cache git && git clone https://github.com/coleifer/huey.git /tmp/huey && cd /tmp/huey && git checkout $HUEY_VERSION && python setup.py install && rm -rf /tmp/huey diff --git a/backend/scripts/ldapmunge.py b/backend/scripts/ldapmunge.py index e116945..0cce6ed 100755 --- a/backend/scripts/ldapmunge.py +++ b/backend/scripts/ldapmunge.py @@ -7,6 +7,7 @@ from pprint import pprint import time import datetime +import phonenumbers DEBUG = int(os.environ.get("DEBUG", "0")) DATADIR = os.environ.get("DATADIR", "/data") @@ -24,7 +25,17 @@ def strip_suffix(candidate, suffix): def sanitize_phone(candidate): - return candidate.strip().replace(' ', '').replace('-', '') + t = candidate.translate(None, ' -!()') + if len(t) == 0: + return t + try: + x = phonenumbers.parse(t, None) + return phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.INTERNATIONAL).encode('ascii', 'ignore') + except phonenumbers.phonenumberutil.NumberParseException as e: + logging.error("Failed to parse phone number \"%s\"" % candidate) + except Exception as e: + logging.exception(e) + return t def str_to_utc(datestring): diff --git a/frontend/app/app.js b/frontend/app/app.js index 7bc333c..ba1e8b6 100644 --- a/frontend/app/app.js +++ b/frontend/app/app.js @@ -99,3 +99,13 @@ myApp.controller('footerController', ['$scope', '$http', }); } ]); + +myApp.filter('phonenumber', function() { + return function(x) { + if( x == undefined ) + return x + cleaned = x.replace(/[-()\s]/g, '') + console.debug("Cleaning " + x + " to " + cleaned) + return cleaned; + }; +}); diff --git a/frontend/app/pages/main.html b/frontend/app/pages/main.html index 05d396c..eef95a8 100644 --- a/frontend/app/pages/main.html +++ b/frontend/app/pages/main.html @@ -21,7 +21,7 @@ {{result.fullname}} {{result.email}} - {{result.phone}} + {{result.phone}} {{ result.title }} {{ result.company }} {{result.managername}} diff --git a/frontend/app/pages/user_details.html b/frontend/app/pages/user_details.html index 1c74d79..908174b 100644 --- a/frontend/app/pages/user_details.html +++ b/frontend/app/pages/user_details.html @@ -22,7 +22,7 @@

{{user.fullname}}

Phone - {{user.phone}} + {{user.phone}} Address