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() -> strReturn the directory of the brand.
Returns
strfunc_yaml_path() -> strReturn the path of the brand's record.
Returns
strfunc_inspect(data) -> tuple[str, str, int, int]Return the extension, media type, width, and height of a picture, or raise ValueError.
paramdatabytesReturns
tuple[str, str, int, int]func_load_images() -> NoneRead the uploaded pictures beside the record into the cache.
Returns
Nonefuncload() -> NoneRead the brand into state.branding and the picture cache; defaults stand in for an invalid record.
Returns
Nonefuncsave(branding) -> NoneWrite the brand's record and take it up.
parambrandingBrandingReturns
Nonefuncreset() -> NoneRemove the record and the pictures, leaving the defaults.
Returns
Nonefuncsave_image(kind, encoded) -> NoneKeep an uploaded picture as the brand's logo or wallpaper.
paramkindstrlogo or wallpaper.
paramencodedstrThe picture, base64 encoded.
Returns
Nonefuncremove_image(kind, reload=True) -> NoneDelete the brand's logo or wallpaper, whatever its format.
paramkindstrparamreloadbool= TrueReturns
Nonefuncimage(kind) -> BrandImage | NoneDescribe an uploaded picture for the pages, or return None where there is none.
paramkindstrReturns
app.models.BrandImage | Nonefuncimage_response(kind) -> ResponseAnswer with an uploaded picture, cached for a year under its versioned address.
paramkindstrReturns
fastapi.Responsefuncview() -> BrandingViewReturn the brand with its pictures.
Returns
app.models.BrandingViewfunc_rgb(color) -> tuple[int, int, int]Split #rrggbb into its channels.
paramcolorstrReturns
tuple[int, int, int]func_hex(rgb) -> strJoin channels into #rrggbb.
paramrgbtuple[float, float, float]Returns
strfunc_mix(color, other, amount) -> strMove color toward other by amount of the way.
paramcolorstrparamotherstrparamamountfloatReturns
strfunc_luminance(color) -> floatReturn the relative luminance of a color, 0 for black and 1 for white.
paramcolorstrReturns
floatfuncaccent_css(accent) -> strDerive 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.
paramaccentstrReturns
strfuncclient_brand() -> dict[str, Any]Return what every page reads from its sealskin-brand meta.
Returns
dict[str, typing.Any]funcbrand_page(page) -> strReturn 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.
parampagestrReturns
str