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:
b64encodefilter to convert binary data to Base64 strings. - Pydantic Model Dump:
pydantic_model_dumpfilter to serialize PydanticBaseModelorBaseSettingsinstances to dictionaries. - Localization:
localizedcurrency,localizeddate, andnl2brfilters for number, date/time formatting, and newline-to-HTML conversions using Babel. - JSON Rendering:
from_jsonfilter 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
UiToolsModuleplugin.
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
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature. - Commit your changes and push to your fork.
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastpluggy_ui_tools-0.0.8.tar.gz.
File metadata
- Download URL: fastpluggy_ui_tools-0.0.8.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
998f3049151cbc08380b0a914c1fad1285a5c452532091734cbe5156ff64f410
|
|
| MD5 |
a3bd2bac5d21f5a661e5a76e0da510bc
|
|
| BLAKE2b-256 |
c26c63a41517b0f14cd3fed4fc8ec2d044d41b9774a05a6bdf269ed2389d9f52
|
File details
Details for the file fastpluggy_ui_tools-0.0.8-py3-none-any.whl.
File metadata
- Download URL: fastpluggy_ui_tools-0.0.8-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b24fdf1a9f83c313124fdb6aec510ad2ef5b78a362d25c4a040fc990248c649
|
|
| MD5 |
3f66f959a3f49ce5388fe336ddefc75f
|
|
| BLAKE2b-256 |
827de9b12b80957603001ce8c5fc381dc92f266f225385c6ea8d64661e99aa7b
|