Skip to content

Commit

Permalink
Merge pull request #106 from DerBiasto/vcard/more-phonenumber-types
Browse files Browse the repository at this point in the history
Added vCard properties:
* cellphone (TEL;TYPE=CELL)
* homephone (TEL;TYPE=HOME)
* workphone (TEL;TYPE=WORK)

Thanks for your contribution.
  • Loading branch information
heuer committed May 9, 2022
2 parents 0a752fa + 9ef4f6e commit 2907fcc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
26 changes: 23 additions & 3 deletions segno/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ def make_vcard_data(name, displayname, email=None, phone=None, fax=None,
videophone=None, memo=None, nickname=None, birthday=None,
url=None, pobox=None, street=None, city=None, region=None,
zipcode=None, country=None, org=None, lat=None, lng=None,
source=None, rev=None, title=None, photo_uri=None):
source=None, rev=None, title=None, photo_uri=None,
cellphone=None, homephone=None, workphone=None):
"""\
Creates a string encoding the contact information as vCard 3.0.
Expand Down Expand Up @@ -291,6 +292,12 @@ def make_vcard_data(name, displayname, email=None, phone=None, fax=None,
:type title: str, iterable of strings, or None
:param photo_uri: Photo URI. Multiple values are allowed.
:type photo_uri: str, iterable of strings, or None
:param cellphone: Cell phone number. Multiple values are allowed.
:type cellphone: str, iterable of strings, or None
:param homephone: Home phone number. Multiple values are allowed.
:type homephone: str, iterable of strings, or None
:param workphone: Work phone number. Multiple values are allowed.
:type workphone: str, iterable of strings, or None
:rtype: str
"""
def make_multifield(name, val):
Expand All @@ -310,6 +317,9 @@ def make_multifield(name, val):
data.extend(make_multifield('TEL', phone))
data.extend(make_multifield('TEL;TYPE=FAX', fax))
data.extend(make_multifield('TEL;TYPE=VIDEO', videophone))
data.extend(make_multifield('TEL;TYPE=CELL', cellphone))
data.extend(make_multifield('TEL;TYPE=HOME', homephone))
data.extend(make_multifield('TEL;TYPE=WORK', workphone))
data.extend(make_multifield('URL', url))
data.extend(make_multifield('TITLE', title))
data.extend(make_multifield('PHOTO;VALUE=uri', photo_uri))
Expand Down Expand Up @@ -352,7 +362,8 @@ def make_vcard(name, displayname, email=None, phone=None, fax=None,
videophone=None, memo=None, nickname=None, birthday=None,
url=None, pobox=None, street=None, city=None, region=None,
zipcode=None, country=None, org=None, lat=None, lng=None,
source=None, rev=None, title=None, photo_uri=None):
source=None, rev=None, title=None, photo_uri=None,
cellphone=None, homephone=None, workphone=None):
"""\
Creates a QR code which encodes a `vCard <https://en.wikipedia.org/wiki/VCard>`_
version 3.0.
Expand Down Expand Up @@ -406,6 +417,12 @@ def make_vcard(name, displayname, email=None, phone=None, fax=None,
:type title: str, iterable of strings, or None
:param photo_uri: Photo URI. Multiple values are allowed.
:type photo_uri: str, iterable of strings, or None
:param cellphone: Cell phone number. Multiple values are allowed.
:type cellphone: str, iterable of strings, or None
:param homephone: Home phone number. Multiple values are allowed.
:type homephone: str, iterable of strings, or None
:param workphone: Work phone number. Multiple values are allowed.
:type workphone: str, iterable of strings, or None
:rtype: segno.QRCode
"""
return segno.make_qr(make_vcard_data(name, displayname, email=email,
Expand All @@ -417,7 +434,10 @@ def make_vcard(name, displayname, email=None, phone=None, fax=None,
zipcode=zipcode, country=country,
org=org, lat=lat, lng=lng,
source=source, rev=rev, title=title,
photo_uri=photo_uri))
photo_uri=photo_uri,
cellphone=cellphone,
homephone=homephone,
workphone=workphone))


def make_geo_data(lat, lng):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ def test_vcard_data():
'PHOTO;VALUE=uri:{0}\r\n' \
'PHOTO;VALUE=uri:{1}\r\n' \
'END:VCARD\r\n'.format(*photo_uris) == vcard
vcard = helpers.make_vcard_data('Doe;John', 'John Doe',
phone='+1', fax='+12', videophone='+123',
cellphone='+1234', homephone='+12345',
workphone='+123456')
assert 'BEGIN:VCARD\r\n' \
'VERSION:3.0\r\n' \
'N:Doe;John\r\n' \
'FN:John Doe\r\n' \
'TEL:+1\r\n' \
'TEL;TYPE=FAX:+12\r\n' \
'TEL;TYPE=VIDEO:+123\r\n' \
'TEL;TYPE=CELL:+1234\r\n' \
'TEL;TYPE=HOME:+12345\r\n' \
'TEL;TYPE=WORK:+123456\r\n' \
'END:VCARD\r\n' == vcard



def test_photo_uri():
Expand Down

0 comments on commit 2907fcc

Please sign in to comment.