Skip to main content

UI Tools plugin for Fastpluggy

Project description

UI Tools Module for FastPluggy

A FastPluggy module that provides a collection of Jinja2 template filters and HTML rendering utilities for building user interfaces. It includes base64 encoding, Pydantic model dumping, localization, JSON rendering, and image embedding.

Features

  • Base64 Encoding: b64encode filter to convert binary data to Base64 strings.
  • Pydantic Model Dump: pydantic_model_dump filter to serialize Pydantic BaseModel or BaseSettings instances to dictionaries.
  • Localization: localizedcurrency, localizeddate, and nl2br filters for number, date/time formatting, and newline-to-HTML conversions using Babel.
  • JSON Rendering: from_json filter and HTML list conversion utilities for safely displaying JSON data.
  • Image Rendering: Embed Base64-encoded images directly into templates with <img> tags.
  • Seamless Integration: Easy registration with FastPluggy via the UiToolsModule plugin.

Extra Widget

TODO: add widget description

Requirements

Install dependencies:

pip install -r requirements.txt

Usage

Template Filters

Filter Description
b64encode Base64-encode binary data (bytes → str).
pydantic_model_dump Dump Pydantic models/settings to dictionaries.
localizedcurrency Format a number as localized currency (default: EUR, fr_FR).
localizeddate Format dates/datetimes with various styles/locales/timezones.
nl2br Convert newline characters to <br> tags.
from_json Parse a JSON string into Python objects (list/dict).
render_bytes_size Format a size into human readable

Example in a Jinja2 template:

<h2>{{ user.name }}</h2>
<p>Balance: {{ user.balance | localizedcurrency('USD', 'en_US') }}</p>
<p>Joined: {{ user.joined_at | localizeddate('long', 'short', 'en_US') }}</p>
<pre>{{ config | pydantic_model_dump | pprint }}</pre>

HTML Rendering Utilities

Import and use functions from html_render.py to render JSON or image data in HTML:

from ui_tools.html_render import render_data_field, render_safe_data_field

# Render JSON string as HTML list
html_list = render_data_field(json_string)

# Safely render arbitrary data
safe_html = render_safe_data_field(raw_input)

Running Tests

Ensure you have pytest installed, then run:

pytest tests/

Contributing

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/your-feature.
  3. Commit your changes and push to your fork.
  4. Open a pull request for review.

License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastpluggy_ui_tools-0.0.5.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastpluggy_ui_tools-0.0.5-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file fastpluggy_ui_tools-0.0.5.tar.gz.

File metadata

  • Download URL: fastpluggy_ui_tools-0.0.5.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for fastpluggy_ui_tools-0.0.5.tar.gz
Algorithm Hash digest
SHA256 5371d24ff74b619ff9fa772faec40916ebf827f6d83eb29897a0a3ec5e60767d
MD5 d38bb30257db3029f4bdfc6056698e06
BLAKE2b-256 9527da557a096ed3634d4776d92876d2eea6a7f46e33a75fd87bfab4612148e3

See more details on using hashes here.

File details

Details for the file fastpluggy_ui_tools-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for fastpluggy_ui_tools-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 84917c6b5e993bfe44e2d43580fe57776b889ec62e502f5a168b865d05ef1c27
MD5 b6dd632a705dd245ce7922d066417819
BLAKE2b-256 ee86217813570dc88e5d9c477ae81f1170e94647c58a2e58b820fd166f377929

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page