Skip to content

Commit d4658f0

Browse files
committed
Feriennet display phone numbers in international format
1 parent 141cfdb commit d4658f0

File tree

7 files changed

+24
-17
lines changed

7 files changed

+24
-17
lines changed

src/onegov/feriennet/templates/bookings.pt

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
<i class="fa fa-envelope" aria-hidden="true"></i>
226226
</a>
227227

228-
<a href="tel:${row.phone}" tal:condition="row.phone" title="${row.phone}">
228+
<a href="tel:${layout.format_phone_number(row.phone)}" tal:condition="row.phone" title="${layout.format_phone_number(row.phone)}">
229229
<span class="show-for-sr" i18n:translate>
230230
Call <tal:b i18n:name="name">${row.parent}</tal:b>
231231
</span>

src/onegov/feriennet/templates/macros.pt

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
</div>
282282
<div tal:define="phone user.data.get('phone')" tal:condition="phone">
283283
<dt i18n:translate>Phone</dt>
284-
<dd><a href="tel:${phone}">${phone}</a></dd>
284+
<dd><a href="tel:${layout.format_phone_number(phone)}">${layout.format_phone_number(phone)}</a></dd>
285285
</div>
286286
</metal:b
287287

@@ -415,7 +415,7 @@
415415
</tal:b>
416416
<tal:b condition="'phone' in public">
417417
<li class="organiser-phone" tal:condition="organiser.data.phone|nothing">
418-
<a href="tel:${organiser.data.phone}">${organiser.data.phone}</a>
418+
<a href="tel:${layout.format_phone_number(organiser.data.phone)}">${layout.format_phone_number(organiser.data.phone)}</a>
419419
</li>
420420
</tal:b>
421421
<tal:b condition="'website' in public">

src/onegov/feriennet/templates/occasion_attendees.pt

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@
5555
</div>
5656
<div>
5757
<span i18n:translate>Phone:</span>
58-
<span><a href="tel:${volunteer.phone}">${volunteer.phone}</a></span>
58+
<span><a href="tel:${layout.format_phone_number(volunteer.phone)}">${layout.format_phone_number(volunteer.phone)}</a></span>
5959
</div>
6060
</li>
6161
</ul>
6262
</tal:b>
6363

64-
6564
<h4 i18n:translate>Attendees</h4>
6665
<ul class="attendees">
6766
<li tal:repeat="details occasions[occasion]">

src/onegov/feriennet/templates/volunteers.pt

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
</a>
100100
</li>
101101
<li>
102-
<a href="tel:${record.phone}">
102+
<a href="tel:${layout.format_phone_number(record.phone)}">
103103
<i class="fa fa-fw fa-phone-square" aria-hidden="true"></i>
104104
<tal:b i18n:translate>
105105
Contact by phone
@@ -183,7 +183,7 @@
183183
<div>
184184
<dt i18n:translate>Phone</dt>
185185
<dd>
186-
<a href="tel:${record.phone}">${record.phone}</a>
186+
<a href="tel:${layout.format_phone_number(record.phone)}">${layout.format_phone_number(record.phone)}</a>
187187
</dd>
188188
</div>
189189
</dl>

src/onegov/org/utils.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,11 @@ def format_phone_number(phone_number: str) -> str:
12581258
if not phone_number:
12591259
return ''
12601260

1261-
parsed = phonenumbers.parse(phone_number, 'CH')
1262-
return phonenumbers.format_number(
1263-
parsed,
1264-
phonenumbers.PhoneNumberFormat.INTERNATIONAL
1265-
)
1261+
try:
1262+
parsed = phonenumbers.parse(phone_number, 'CH')
1263+
1264+
return phonenumbers.format_number(
1265+
parsed, phonenumbers.PhoneNumberFormat.INTERNATIONAL
1266+
)
1267+
except phonenumbers.phonenumberutil.NumberParseException:
1268+
return phone_number

tests/onegov/feriennet/test_views.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def test_organiser_info(client, scenario):
549549
contact.form['zip_code'] = '20001'
550550
contact.form['place'] = 'Washington'
551551
contact.form['email'] = '[email protected]'
552-
contact.form['phone'] = '+41 23 456 789'
552+
contact.form['phone'] = '+41234567890'
553553
contact.form['website'] = 'https://www.example.org'
554554
contact.form['emergency'] = '+01 234 56 78 (Peter)'
555555
contact.form.submit()
@@ -600,28 +600,28 @@ def with_public_organiser_data(values):
600600
assert "Admins Association" not in page
601601
assert "Washington" in page
602602
assert "[email protected]" not in page
603-
assert "+41 23 456 789" not in page
603+
assert "+41 23 456 78 90" not in page
604604
assert "https://www.example.org" not in page
605605

606606
page = with_public_organiser_data(['email'])
607607
assert "Admins Association" not in page
608608
assert "Washington" not in page
609609
assert "[email protected]" in page
610-
assert "+41 23 456 789" not in page
610+
assert "+41 23 456 78 90" not in page
611611
assert "https://www.example.org" not in page
612612

613613
page = with_public_organiser_data(['phone'])
614614
assert "Admins Association" not in page
615615
assert "Washington" not in page
616616
assert "[email protected]" not in page
617-
assert "+41 23 456 789" in page
617+
assert "+41 23 456 78 90" in page
618618
assert "https://www.example.org" not in page
619619

620620
page = with_public_organiser_data(['website'])
621621
assert "Admins Association" not in page
622622
assert "Washington" not in page
623623
assert "[email protected]" not in page
624-
assert "+41 23 456 789" not in page
624+
assert "+41 23 456 78 90" not in page
625625
assert "https://www.example.org" in page
626626

627627

tests/onegov/org/test_utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,8 @@ def test_format_phone_number():
322322
assert utils.format_phone_number('41') == '+41 41'
323323
assert utils.format_phone_number('') == ''
324324
assert utils.format_phone_number(None) == ''
325+
326+
# force error (too long for phone number), will return the input
327+
long_text = ('You can reach me during office hours at 041 111 22 33 '
328+
'otherwise at 041 111 22 44')
329+
assert utils.format_phone_number(long_text) == long_text

0 commit comments

Comments
 (0)