Skip to content

Commit

Permalink
Better display of phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
jtilander committed Jul 5, 2018
1 parent 15fe329 commit 11f1770
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
18 changes: 12 additions & 6 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion backend/scripts/ldapmunge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions frontend/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
});
2 changes: 1 addition & 1 deletion frontend/app/pages/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<td><img widht="96" height="96" src="/photos/{{result.id}}.jpg" /></td>
<td><a href="#/users/{{result.id}}">{{result.fullname}}</a></td>
<td><a href="mailto:{{result.email}}">{{result.email}}</a></td>
<td><a href="tel:{{result.phone}}">{{result.phone}}</a></td>
<td><a href="tel:{{result.phone| phonenumber}}">{{result.phone}}</a></td>
<td>{{ result.title }}</td>
<td>{{ result.company }}</td>
<td><a href="#/users/{{result.manager}}">{{result.managername}}</a></td>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/pages/user_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>{{user.fullname}}</h1>
</tr>
<tr>
<td>Phone</td>
<td><a href="tel:{{user.phone}}">{{user.phone}}</a></td>
<td><a href="tel:{{user.phone | phonenumber}}">{{user.phone}}</a></td>
</tr>
<tr>
<td>Address</td>
Expand Down

0 comments on commit 11f1770

Please sign in to comment.