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#
Name a link by the site it points at. |
|
Name each ISO 639-1 code in the active language. |
|
Rank counts, largest first, each with its share of the largest. |
|
Fit a list into a fixed number of slots. |
|
Order items with the active ones first, each group most recently updated first. |
|
Sum up a checklist. |
API#
- link_host(url: str) str[source]#
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.
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
slotsplaces.Returns:
shown(the items that fit),more(how many do not) andtotal.
- 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.