def hcard_to_html(hcard, parent_props=None): """Renders an h-card as HTML. Args: hcard: dict, decoded JSON h-card parent_props: list of strings, the properties of the parent object where this object is embedded, e.g. ['p-author'] Returns: string, rendered HTML """ if not hcard: return '' if not parent_props: parent_props = [] # extract first value from multiply valued properties props = hcard.get('properties', {}) prop = first_props(props) if not prop: return '' prop.setdefault('uid', '') photo = prop.get('photo') return HCARD.substitute( prop, types=' '.join(util.uniquify(parent_props + hcard.get('type', []))), photo=img(photo, 'u-photo', '') if photo else '', linked_name=maybe_linked_name(props))
def object_urls(obj): """Returns an object's unique URLs, preserving order. """ if isinstance(obj, basestring): return obj return uniquify(util.trim_nulls( [obj.get('url')] + [u.get('value') for u in obj.get('urls', [])]))
def hcard_to_html(hcard, parent_props=None): """Renders an h-card as HTML. Args: hcard: dict, decoded JSON h-card parent_props: list of strings, the properties of the parent object where this object is embedded, e.g. ['p-author'] Returns: string, rendered HTML """ if not hcard: return '' if not parent_props: parent_props = [] # extract first value from multiply valued properties props = hcard.get('properties', {}) prop = first_props(props) if not prop: return '' return HCARD.substitute( types=' '.join(uniquify(parent_props + hcard.get('type', []))), ids='\n'.join(['<data class="p-uid" value="%s"></data>' % uid for uid in props.get('uid', []) if uid] + ['<data class="p-numeric-id" value="%s"></data>' % nid for nid in props.get('numeric-id', []) if nid]), linked_name=maybe_linked_name(props), nicknames='\n'.join('<span class="p-nickname">%s</span>' % nick for nick in props.get('nickname', []) if nick), photos='\n'.join(img(photo) for photo in props.get('photo', []) if photo), )
def object_urls(obj): """Returns an object's unique URLs, preserving order. """ if isinstance(obj, str): return obj return uniquify(util.trim_nulls( [obj.get('url')] + [u.get('value') for u in obj.get('urls', [])]))
def object_urls(obj): """Returns an object's unique URLs, preserving order. """ return util.uniquify(util.trim_nulls( [obj.get('url')] + [u.get('value') for u in obj.get('urls', [])]))