Python helpers#
The module plonegovbr.socialmedia.utils provides functions to build, add, merge, and read the value of a social_links field, as The social_links value describes it.
No function modifies the links it is given. A function that adds or merges links returns a new list.
Important
Assign the returned list to the field. The database does not notice a stored list changed in place.
Values#
SocialLinkThe type of one link:
dict[str, str | list[dict[str, str]]].EMPTY_VALUESThe texts that count as empty in a network id or an address:
"","None","none", and"null". Leading and trailing spaces are stripped before the comparison.PATTERNSThe regular expressions that read a username from a profile address, by network id. It has entries for
facebookandx, as Computed usernames describes.
link_target#
Returns the address of a link's first target.
Parameter |
Type |
Description |
|---|---|---|
|
|
A link. |
- Returns
The
@idof the first object in the link'shref, stripped of leading and trailing spaces. An empty string when the link is not an object, itshrefis not a list or does not start with an object, or that object's@idis not a string or is one ofEMPTY_VALUES.
extract_username_from_profile#
Returns the username in a profile address.
Parameter |
Type |
Description |
|---|---|---|
|
|
A profile address, such as |
|
|
The network, such as |
- Returns
The username that the network's entry in
PATTERNSreads from the address. An empty string when the network has no entry, or the address does not match it.