fairdm.contrib.contributors.profiles#

Pure helpers behind the person and organization overview pages.

Nothing here touches the database or a request, so each function can be tested with plain values.

Module Contents#

Functions#

link_host

Name a link by the site it points at.

language_names

Name each ISO 639-1 code in the active language.

ranked_shares

Rank counts, largest first, each with its share of the largest.

fill_slots

Fit a list into a fixed number of slots.

active_then_recent

Order items with the active ones first, each group most recently updated first.

checklist

Sum up a checklist.

API#

Name a link by the site it points at.

Args: url: The link.

Returns: The host without a leading www., or the link as written when it has no host.

language_names(codes: collections.abc.Iterable[str] | None) → list[str][source]#

Name each ISO 639-1 code in the active language.

Args: codes: The language codes.

Returns: One name per code, in the order given. A code Django does not know is kept as written.

ranked_shares(counts: collections.abc.Mapping[str, int]) → list[dict[str, Any]][source]#

Rank counts, largest first, each with its share of the largest.

Args: counts: A count for each label.

Returns: One {"label", "count", "percent"} entry per label, where the largest count is 100.

fill_slots(items: collections.abc.Sequence[Any], slots: int, reserve: bool = False) → dict[str, Any][source]#

Fit a list into a fixed number of slots.

Args: items: Everything there is to show, in order. slots: How many slots there are. reserve: Keep the last slot for a “+n more” entry when the items do not all fit, so the list never takes more than slots places.

Returns: shown (the items that fit), more (how many do not) and total.

active_then_recent(items: collections.abc.Iterable[Any], modified: collections.abc.Callable[[Any], Any], active: collections.abc.Callable[[Any], bool] | None = None) → list[Any][source]#

Order items with the active ones first, each group most recently updated first.

Args: items: The items to order. modified: Returns when an item was last updated. active: Says whether an item is active, or None when the items have no such state.

Returns: The items in order.

checklist(items: collections.abc.Sequence[collections.abc.Mapping[str, Any]]) → dict[str, Any][source]#

Sum up a checklist.

Args: items: The checklist’s items, each with a done flag.

Returns: The items, how many are done, the total, and whether all of them are (ready).