SealSkin

branding

The brand the web app wears: the name, logo, accent, wallpaper, app links, and links an administrator gives it.

The brand is a shared object, branding/branding.yml, kept beside the pictures an administrator uploads, branding/logo.<ext> and branding/wallpaper.<ext>; every node serves the same brand, and a deployment can seed it by writing those files. load reads them into state.branding and this module's picture cache, the defaults standing in for whatever is missing or invalid. A picture's address carries the hash of its bytes, so a browser caches it for a year and still sees a new upload at once.

Every page the server serves carries the brand in its head (brand_page): the title, the favicon, an application-name meta the translator fills {brand} with, a sealskin-brand meta holding the rest as JSON, and a style block that derives the accent palette from the one color. The pages run no inline script, so the brand travels as attributes.

attributelogger
= logging.getLogger(__name__)
attributeIMAGE_LIMITS
= {'logo': 1000000, 'wallpaper': 8000000}
attributeFORMATS
= {'PNG': ('png', 'image/png'), 'JPEG': ('jpg', 'image/jpeg'), 'WEBP': ('webp', 'image/webp')}
attributeDEFAULT_ACCENT
= '#8b7cf6'
attributeDEFAULT_GRADIENT
= ('#e04fb0', '#7c6cf0')
attributeYAML_NAME
= 'branding.yml'
func_dir() -> str

Return the directory of the brand.

Returns

str
func_yaml_path() -> str

Return the path of the brand's record.

Returns

str
func_inspect(data) -> tuple[str, str, int, int]

Return the extension, media type, width, and height of a picture, or raise ValueError.

paramdatabytes

Returns

tuple[str, str, int, int]
func_load_images() -> None

Read the uploaded pictures beside the record into the cache.

Returns

None
funcload() -> None

Read the brand into state.branding and the picture cache; defaults stand in for an invalid record.

Returns

None
funcsave(branding) -> None

Write the brand's record and take it up.

parambrandingBranding

Returns

None
funcreset() -> None

Remove the record and the pictures, leaving the defaults.

Returns

None
funcsave_image(kind, encoded) -> None

Keep an uploaded picture as the brand's logo or wallpaper.

paramkindstr

logo or wallpaper.

paramencodedstr

The picture, base64 encoded.

Returns

None
funcremove_image(kind, reload=True) -> None

Delete the brand's logo or wallpaper, whatever its format.

paramkindstr
paramreloadbool
= True

Returns

None
funcimage(kind) -> BrandImage | None

Describe an uploaded picture for the pages, or return None where there is none.

paramkindstr

Returns

app.models.BrandImage | None
funcimage_response(kind) -> Response

Answer with an uploaded picture, cached for a year under its versioned address.

paramkindstr

Returns

fastapi.Response
funcview() -> BrandingView

Return the brand with its pictures.

Returns

app.models.BrandingView
func_rgb(color) -> tuple[int, int, int]

Split #rrggbb into its channels.

paramcolorstr

Returns

tuple[int, int, int]
func_hex(rgb) -> str

Join channels into #rrggbb.

paramrgbtuple[float, float, float]

Returns

str
func_mix(color, other, amount) -> str

Move color toward other by amount of the way.

paramcolorstr
paramotherstr
paramamountfloat

Returns

str
func_luminance(color) -> float

Return the relative luminance of a color, 0 for black and 1 for white.

paramcolorstr

Returns

float
funcaccent_css(accent) -> str

Derive the stylesheets' accent palette from one color, as a rule on :root.

The mixes mirror accentVars of the dashboard's branding preview, which paints the same palette before the brand is saved.

paramaccentstr

Returns

str
funcclient_brand() -> dict[str, Any]

Return what every page reads from its sealskin-brand meta.

Returns

dict[str, typing.Any]
funcbrand_page(page) -> str

Return a served page wearing the brand.

The title and the wordmarks say the name, the favicon and the default pictures become the logo where one was uploaded, and the head gains the metas and the accent style described in the module docstring.

parampagestr

Returns

str