Skip to content

Commit

Permalink
BibFormat: vCard support for people collection
Browse files Browse the repository at this point in the history
* Adds vCard support for detailed profile pages for the people
  collection and contains full name, affiliation, email, phone,
  mobile, and fax number.
  Uses microformats hCard 1.0.

Signed-off-by: Jochen Klein <[email protected]>
  • Loading branch information
jochenklein committed Feb 17, 2016
1 parent 6042737 commit 28c909f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ table tr td {
}
</style>

<div class="vcard">
<div class="row">
<BFE_FIELD tag="100__a" prefix='<h1>' suffix='</h1>' />
<BFE_FIELD tag="371__0" />
<BFE_FIELD tag="100__a" prefix="<h1 class='fn'>" suffix="</h1>" />
<BFE_FIELD tag="371__0" prefix="<span class='org'>" suffix="</span>" />
</div>

<h2>Personal Information</h2>
Expand Down Expand Up @@ -112,6 +113,7 @@ table tr td {
<BFE_AUTHORITY_CONTACT
prefix="<table><tbody>"
suffix="</tbody></table>"
vcard_support="yes"
default="<i>No contact information.</i>" />
</div>
<div class="column">
Expand All @@ -121,6 +123,7 @@ table tr td {
default="<i>No profiles.</i>"/>
</div>
</div>
</div>

<h2>Publications</h2>
<BFE_AUTHORITY_PUBLICATIONS
Expand Down
44 changes: 36 additions & 8 deletions modules/bibformat/lib/elements/bfe_authority_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,74 @@
from invenio.messages import gettext_set_language


def format_email(email, email_href="yes", icon="no"):
def format_email(email, email_href="yes", icon="no", vcard_support="no"):
"""Return formatted email address."""
vcard_enabled = True if vcard_support.lower() == "yes" else False

if email_href.lower() == "yes":
email = "<a href='mailto:{0}'>{0}</a>".format(email)
email = "<a {0}href='mailto:{1}'>{1}</a>".format(
"class='email' " if vcard_enabled else "", email)
else:
if vcard_enabled:
email = "<span class='email'>{0}</span>".format(email)
if icon.lower() == "yes":
icon_class = "fa fa-envelope"
email = "<i class='{0}' style='font-size: 0.9em;'></i> {1}".format(
icon_class, email)
return email


def format_phone_number(phone_number, icon="no"):
def format_phone_number(phone_number, icon="no", vcard_support="no"):
"""Return formatted phone number."""
if vcard_support.lower() == "yes":
phone_number = (
"<span class='tel'>"
"<span class='type' style='display: none;'>work</span>"
"<span class='value'>{0}</span>"
"</span>".format(phone_number))
if icon.lower() == "yes":
icon_class = "fa fa-phone"
phone_number = "<i class='{0}'></i> {1}".format(
icon_class, phone_number)
return phone_number


def format_mobile_number(mobile_number, icon="no"):
def format_mobile_number(mobile_number, icon="no", vcard_support="no"):
"""Return formatted mobile phone number."""
if vcard_support.lower() == "yes":
mobile_number = (
"<span class='tel'>"
"<span class='type' style='display: none;'>cell</span>"
"<span class='value'>{0}</span>"
"</span>".format(mobile_number))
if icon.lower() == "yes":
icon_class = "fa fa-mobile"
mobile_number = "<i class='{0}'></i> {1}".format(
icon_class, mobile_number)
return mobile_number


def format_fax_number(fax_number, icon="no"):
def format_fax_number(fax_number, icon="no", vcard_support="no"):
"""Return formatted fax number."""
if vcard_support.lower() == "yes":
fax_number = (
"<span class='tel'>"
"<span class='type' style='display: none;'>fax</span>"
"<span class='value'>{0}</span>"
"</span>".format(fax_number))
if icon.lower() == "yes":
icon_class = "fa fa-fax"
fax_number = "<i class='{0}'></i> {1}".format(icon_class, fax_number)
return fax_number


def format_element(bfo, contact_type="all", email_href="yes", icon="no"):
def format_element(bfo, contact_type="all", vcard_support="no",
email_href="yes", icon="no"):
"""Return contact information for the record.
:param string contact_type: return all contact information if 'all',
other values: 'email', 'phone', 'mobile', or 'fax'
:param string vcard_support: enables vCard support if 'yes'
:param string email_href: link email address using mailto if 'yes'
:param string icon: display icon for the specified contact_type if 'yes'
"""
Expand All @@ -79,10 +105,12 @@ def format_element(bfo, contact_type="all", email_href="yes", icon="no"):
tbl_row = "<tr><th>{0}</th><td>{1}</td></tr>"
if email:
result += tbl_row.format(
_("Email address"), format_email(email[0].lower(), email_href))
_("Email address"), format_email(
email[0].lower(), email_href, vcard_support=vcard_support))
if phone_number:
result += tbl_row.format(
_("Phone number"), format_phone_number(phone_number[0]))
_("Phone number"), format_phone_number(
phone_number[0], vcard_support=vcard_support))
if mobile_number:
result += tbl_row.format(
_("Mobile number"), format_mobile_number(mobile_number[0]))
Expand Down

0 comments on commit 28c909f

Please sign in to comment.