fastpluggy-ui-tools 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fastpluggy-ui-tools might be problematic. Click here for more details.

Files changed (36) hide show
  1. fastpluggy_ui_tools-0.0.5/MANIFEST.in +12 -0
  2. fastpluggy_ui_tools-0.0.5/PKG-INFO +97 -0
  3. fastpluggy_ui_tools-0.0.5/README.md +87 -0
  4. fastpluggy_ui_tools-0.0.5/fastpluggy_ui_tools.egg-info/PKG-INFO +97 -0
  5. fastpluggy_ui_tools-0.0.5/fastpluggy_ui_tools.egg-info/SOURCES.txt +34 -0
  6. fastpluggy_ui_tools-0.0.5/fastpluggy_ui_tools.egg-info/dependency_links.txt +1 -0
  7. fastpluggy_ui_tools-0.0.5/fastpluggy_ui_tools.egg-info/entry_points.txt +2 -0
  8. fastpluggy_ui_tools-0.0.5/fastpluggy_ui_tools.egg-info/requires.txt +2 -0
  9. fastpluggy_ui_tools-0.0.5/fastpluggy_ui_tools.egg-info/top_level.txt +1 -0
  10. fastpluggy_ui_tools-0.0.5/pyproject.toml +30 -0
  11. fastpluggy_ui_tools-0.0.5/setup.cfg +4 -0
  12. fastpluggy_ui_tools-0.0.5/src/__init__.py +1 -0
  13. fastpluggy_ui_tools-0.0.5/src/extra_widget/__init__.py +0 -0
  14. fastpluggy_ui_tools-0.0.5/src/extra_widget/display/__init__.py +0 -0
  15. fastpluggy_ui_tools-0.0.5/src/extra_widget/display/alert.py +51 -0
  16. fastpluggy_ui_tools-0.0.5/src/extra_widget/display/card.py +79 -0
  17. fastpluggy_ui_tools-0.0.5/src/extra_widget/display/code.py +57 -0
  18. fastpluggy_ui_tools-0.0.5/src/extra_widget/display/stats.py +90 -0
  19. fastpluggy_ui_tools-0.0.5/src/extra_widget/layout/__init__.py +0 -0
  20. fastpluggy_ui_tools-0.0.5/src/extra_widget/layout/grid.py +187 -0
  21. fastpluggy_ui_tools-0.0.5/src/html_render.py +136 -0
  22. fastpluggy_ui_tools-0.0.5/src/image_tools.py +79 -0
  23. fastpluggy_ui_tools-0.0.5/src/localization.py +30 -0
  24. fastpluggy_ui_tools-0.0.5/src/plugin.py +41 -0
  25. fastpluggy_ui_tools-0.0.5/src/static/script.js +71 -0
  26. fastpluggy_ui_tools-0.0.5/src/static/style.css +22 -0
  27. fastpluggy_ui_tools-0.0.5/src/template_tools.py +66 -0
  28. fastpluggy_ui_tools-0.0.5/src/templates/extra_widget/__init__.py +0 -0
  29. fastpluggy_ui_tools-0.0.5/src/templates/extra_widget/display/alert.html.j2 +28 -0
  30. fastpluggy_ui_tools-0.0.5/src/templates/extra_widget/display/card.html.j2 +47 -0
  31. fastpluggy_ui_tools-0.0.5/src/templates/extra_widget/display/code.html.j2 +35 -0
  32. fastpluggy_ui_tools-0.0.5/src/templates/extra_widget/display/stats.html.j2 +34 -0
  33. fastpluggy_ui_tools-0.0.5/src/templates/extra_widget/display/status.html.j2 +42 -0
  34. fastpluggy_ui_tools-0.0.5/src/templates/extra_widget/layout/grid.html.j2 +30 -0
  35. fastpluggy_ui_tools-0.0.5/src/templates/mime.html.j2 +14 -0
  36. fastpluggy_ui_tools-0.0.5/tests/test_template_tools.py +63 -0
@@ -0,0 +1,12 @@
1
+ # Include all Python files
2
+ recursive-include src *.py
3
+
4
+ # Include all template files
5
+ recursive-include src/templates *.html *.j2
6
+
7
+ # Include all static files (CSS, JS, etc.)
8
+ recursive-include src/static *
9
+
10
+ # Include README and license files
11
+ include README.md
12
+ include LICENSE
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastpluggy-ui-tools
3
+ Version: 0.0.5
4
+ Summary: UI Tools plugin for Fastpluggy
5
+ Author: FastPluggy Team
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: jinja2
9
+ Requires-Dist: babel
10
+
11
+ # UI Tools Module for FastPluggy
12
+
13
+ A FastPluggy module that provides a collection of Jinja2 template filters and HTML rendering utilities for building user interfaces.
14
+ It includes base64 encoding, Pydantic model dumping, localization, JSON rendering, and image embedding.
15
+
16
+ ## Features
17
+
18
+ * **Base64 Encoding**: `b64encode` filter to convert binary data to Base64 strings.
19
+ * **Pydantic Model Dump**: `pydantic_model_dump` filter to serialize Pydantic `BaseModel` or `BaseSettings` instances to dictionaries.
20
+ * **Localization**: `localizedcurrency`, `localizeddate`, and `nl2br` filters for number, date/time formatting, and newline-to-HTML conversions using Babel.
21
+ * **JSON Rendering**: `from_json` filter and HTML list conversion utilities for safely displaying JSON data.
22
+ * **Image Rendering**: Embed Base64-encoded images directly into templates with `<img>` tags.
23
+ * **Seamless Integration**: Easy registration with FastPluggy via the `UiToolsModule` plugin.
24
+
25
+ # Extra Widget
26
+
27
+ TODO: add widget description
28
+
29
+ ## Requirements
30
+
31
+ * Python 3.7 or higher
32
+ * [Babel](https://pypi.org/project/Babel/)
33
+ * [Pillow](https://pypi.org/project/Pillow/)
34
+
35
+ Install dependencies:
36
+
37
+ ```bash
38
+ pip install -r requirements.txt
39
+ ```
40
+
41
+
42
+
43
+ ## Usage
44
+
45
+ ### Template Filters
46
+
47
+ | Filter | Description |
48
+ | --------------------- |------------------------------------------------------------------|
49
+ | `b64encode` | Base64-encode binary data (`bytes → str`). |
50
+ | `pydantic_model_dump` | Dump Pydantic models/settings to dictionaries. |
51
+ | `localizedcurrency` | Format a number as localized currency (default: `EUR`, `fr_FR`). |
52
+ | `localizeddate` | Format dates/datetimes with various styles/locales/timezones. |
53
+ | `nl2br` | Convert newline characters to `<br>` tags. |
54
+ | `from_json` | Parse a JSON string into Python objects (`list`/`dict`). |
55
+ | `render_bytes_size` | Format a size into human readable |
56
+
57
+ **Example in a Jinja2 template:**
58
+
59
+ ```jinja
60
+ <h2>{{ user.name }}</h2>
61
+ <p>Balance: {{ user.balance | localizedcurrency('USD', 'en_US') }}</p>
62
+ <p>Joined: {{ user.joined_at | localizeddate('long', 'short', 'en_US') }}</p>
63
+ <pre>{{ config | pydantic_model_dump | pprint }}</pre>
64
+ ```
65
+
66
+ ### HTML Rendering Utilities
67
+
68
+ Import and use functions from `html_render.py` to render JSON or image data in HTML:
69
+
70
+ ```python
71
+ from ui_tools.html_render import render_data_field, render_safe_data_field
72
+
73
+ # Render JSON string as HTML list
74
+ html_list = render_data_field(json_string)
75
+
76
+ # Safely render arbitrary data
77
+ safe_html = render_safe_data_field(raw_input)
78
+ ```
79
+
80
+ ## Running Tests
81
+
82
+ Ensure you have `pytest` installed, then run:
83
+
84
+ ```bash
85
+ pytest tests/
86
+ ```
87
+
88
+ ## Contributing
89
+
90
+ 1. Fork the repository.
91
+ 2. Create a new branch: `git checkout -b feature/your-feature`.
92
+ 3. Commit your changes and push to your fork.
93
+ 4. Open a pull request for review.
94
+
95
+ ## License
96
+
97
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,87 @@
1
+ # UI Tools Module for FastPluggy
2
+
3
+ A FastPluggy module that provides a collection of Jinja2 template filters and HTML rendering utilities for building user interfaces.
4
+ It includes base64 encoding, Pydantic model dumping, localization, JSON rendering, and image embedding.
5
+
6
+ ## Features
7
+
8
+ * **Base64 Encoding**: `b64encode` filter to convert binary data to Base64 strings.
9
+ * **Pydantic Model Dump**: `pydantic_model_dump` filter to serialize Pydantic `BaseModel` or `BaseSettings` instances to dictionaries.
10
+ * **Localization**: `localizedcurrency`, `localizeddate`, and `nl2br` filters for number, date/time formatting, and newline-to-HTML conversions using Babel.
11
+ * **JSON Rendering**: `from_json` filter and HTML list conversion utilities for safely displaying JSON data.
12
+ * **Image Rendering**: Embed Base64-encoded images directly into templates with `<img>` tags.
13
+ * **Seamless Integration**: Easy registration with FastPluggy via the `UiToolsModule` plugin.
14
+
15
+ # Extra Widget
16
+
17
+ TODO: add widget description
18
+
19
+ ## Requirements
20
+
21
+ * Python 3.7 or higher
22
+ * [Babel](https://pypi.org/project/Babel/)
23
+ * [Pillow](https://pypi.org/project/Pillow/)
24
+
25
+ Install dependencies:
26
+
27
+ ```bash
28
+ pip install -r requirements.txt
29
+ ```
30
+
31
+
32
+
33
+ ## Usage
34
+
35
+ ### Template Filters
36
+
37
+ | Filter | Description |
38
+ | --------------------- |------------------------------------------------------------------|
39
+ | `b64encode` | Base64-encode binary data (`bytes → str`). |
40
+ | `pydantic_model_dump` | Dump Pydantic models/settings to dictionaries. |
41
+ | `localizedcurrency` | Format a number as localized currency (default: `EUR`, `fr_FR`). |
42
+ | `localizeddate` | Format dates/datetimes with various styles/locales/timezones. |
43
+ | `nl2br` | Convert newline characters to `<br>` tags. |
44
+ | `from_json` | Parse a JSON string into Python objects (`list`/`dict`). |
45
+ | `render_bytes_size` | Format a size into human readable |
46
+
47
+ **Example in a Jinja2 template:**
48
+
49
+ ```jinja
50
+ <h2>{{ user.name }}</h2>
51
+ <p>Balance: {{ user.balance | localizedcurrency('USD', 'en_US') }}</p>
52
+ <p>Joined: {{ user.joined_at | localizeddate('long', 'short', 'en_US') }}</p>
53
+ <pre>{{ config | pydantic_model_dump | pprint }}</pre>
54
+ ```
55
+
56
+ ### HTML Rendering Utilities
57
+
58
+ Import and use functions from `html_render.py` to render JSON or image data in HTML:
59
+
60
+ ```python
61
+ from ui_tools.html_render import render_data_field, render_safe_data_field
62
+
63
+ # Render JSON string as HTML list
64
+ html_list = render_data_field(json_string)
65
+
66
+ # Safely render arbitrary data
67
+ safe_html = render_safe_data_field(raw_input)
68
+ ```
69
+
70
+ ## Running Tests
71
+
72
+ Ensure you have `pytest` installed, then run:
73
+
74
+ ```bash
75
+ pytest tests/
76
+ ```
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork the repository.
81
+ 2. Create a new branch: `git checkout -b feature/your-feature`.
82
+ 3. Commit your changes and push to your fork.
83
+ 4. Open a pull request for review.
84
+
85
+ ## License
86
+
87
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastpluggy-ui-tools
3
+ Version: 0.0.5
4
+ Summary: UI Tools plugin for Fastpluggy
5
+ Author: FastPluggy Team
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: jinja2
9
+ Requires-Dist: babel
10
+
11
+ # UI Tools Module for FastPluggy
12
+
13
+ A FastPluggy module that provides a collection of Jinja2 template filters and HTML rendering utilities for building user interfaces.
14
+ It includes base64 encoding, Pydantic model dumping, localization, JSON rendering, and image embedding.
15
+
16
+ ## Features
17
+
18
+ * **Base64 Encoding**: `b64encode` filter to convert binary data to Base64 strings.
19
+ * **Pydantic Model Dump**: `pydantic_model_dump` filter to serialize Pydantic `BaseModel` or `BaseSettings` instances to dictionaries.
20
+ * **Localization**: `localizedcurrency`, `localizeddate`, and `nl2br` filters for number, date/time formatting, and newline-to-HTML conversions using Babel.
21
+ * **JSON Rendering**: `from_json` filter and HTML list conversion utilities for safely displaying JSON data.
22
+ * **Image Rendering**: Embed Base64-encoded images directly into templates with `<img>` tags.
23
+ * **Seamless Integration**: Easy registration with FastPluggy via the `UiToolsModule` plugin.
24
+
25
+ # Extra Widget
26
+
27
+ TODO: add widget description
28
+
29
+ ## Requirements
30
+
31
+ * Python 3.7 or higher
32
+ * [Babel](https://pypi.org/project/Babel/)
33
+ * [Pillow](https://pypi.org/project/Pillow/)
34
+
35
+ Install dependencies:
36
+
37
+ ```bash
38
+ pip install -r requirements.txt
39
+ ```
40
+
41
+
42
+
43
+ ## Usage
44
+
45
+ ### Template Filters
46
+
47
+ | Filter | Description |
48
+ | --------------------- |------------------------------------------------------------------|
49
+ | `b64encode` | Base64-encode binary data (`bytes → str`). |
50
+ | `pydantic_model_dump` | Dump Pydantic models/settings to dictionaries. |
51
+ | `localizedcurrency` | Format a number as localized currency (default: `EUR`, `fr_FR`). |
52
+ | `localizeddate` | Format dates/datetimes with various styles/locales/timezones. |
53
+ | `nl2br` | Convert newline characters to `<br>` tags. |
54
+ | `from_json` | Parse a JSON string into Python objects (`list`/`dict`). |
55
+ | `render_bytes_size` | Format a size into human readable |
56
+
57
+ **Example in a Jinja2 template:**
58
+
59
+ ```jinja
60
+ <h2>{{ user.name }}</h2>
61
+ <p>Balance: {{ user.balance | localizedcurrency('USD', 'en_US') }}</p>
62
+ <p>Joined: {{ user.joined_at | localizeddate('long', 'short', 'en_US') }}</p>
63
+ <pre>{{ config | pydantic_model_dump | pprint }}</pre>
64
+ ```
65
+
66
+ ### HTML Rendering Utilities
67
+
68
+ Import and use functions from `html_render.py` to render JSON or image data in HTML:
69
+
70
+ ```python
71
+ from ui_tools.html_render import render_data_field, render_safe_data_field
72
+
73
+ # Render JSON string as HTML list
74
+ html_list = render_data_field(json_string)
75
+
76
+ # Safely render arbitrary data
77
+ safe_html = render_safe_data_field(raw_input)
78
+ ```
79
+
80
+ ## Running Tests
81
+
82
+ Ensure you have `pytest` installed, then run:
83
+
84
+ ```bash
85
+ pytest tests/
86
+ ```
87
+
88
+ ## Contributing
89
+
90
+ 1. Fork the repository.
91
+ 2. Create a new branch: `git checkout -b feature/your-feature`.
92
+ 3. Commit your changes and push to your fork.
93
+ 4. Open a pull request for review.
94
+
95
+ ## License
96
+
97
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,34 @@
1
+ MANIFEST.in
2
+ README.md
3
+ pyproject.toml
4
+ fastpluggy_ui_tools.egg-info/PKG-INFO
5
+ fastpluggy_ui_tools.egg-info/SOURCES.txt
6
+ fastpluggy_ui_tools.egg-info/dependency_links.txt
7
+ fastpluggy_ui_tools.egg-info/entry_points.txt
8
+ fastpluggy_ui_tools.egg-info/requires.txt
9
+ fastpluggy_ui_tools.egg-info/top_level.txt
10
+ src/__init__.py
11
+ src/html_render.py
12
+ src/image_tools.py
13
+ src/localization.py
14
+ src/plugin.py
15
+ src/template_tools.py
16
+ src/extra_widget/__init__.py
17
+ src/extra_widget/display/__init__.py
18
+ src/extra_widget/display/alert.py
19
+ src/extra_widget/display/card.py
20
+ src/extra_widget/display/code.py
21
+ src/extra_widget/display/stats.py
22
+ src/extra_widget/layout/__init__.py
23
+ src/extra_widget/layout/grid.py
24
+ src/static/script.js
25
+ src/static/style.css
26
+ src/templates/mime.html.j2
27
+ src/templates/extra_widget/__init__.py
28
+ src/templates/extra_widget/display/alert.html.j2
29
+ src/templates/extra_widget/display/card.html.j2
30
+ src/templates/extra_widget/display/code.html.j2
31
+ src/templates/extra_widget/display/stats.html.j2
32
+ src/templates/extra_widget/display/status.html.j2
33
+ src/templates/extra_widget/layout/grid.html.j2
34
+ tests/test_template_tools.py
@@ -0,0 +1,2 @@
1
+ [fastpluggy.plugins]
2
+ ui_tools = fastpluggy_plugin.ui_tools.plugin:UiToolsModule
@@ -0,0 +1 @@
1
+ fastpluggy_plugin
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "fastpluggy-ui-tools"
7
+ version = "0.0.5"
8
+ description = "UI Tools plugin for Fastpluggy"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ authors = [
12
+ {name = "FastPluggy Team"}
13
+ ]
14
+ dependencies = [
15
+ "jinja2",
16
+ "babel",
17
+ ]
18
+
19
+ # add optionnal package Pillow
20
+
21
+ [tool.setuptools]
22
+ packages = ["fastpluggy_plugin.ui_tools"]
23
+ package-dir = { "fastpluggy_plugin.ui_tools" = "src" }
24
+ include-package-data = true
25
+
26
+ [tool.setuptools.package-data]
27
+ "fastpluggy_plugin.ui_tools" = ["**/*","templates/**/*.html", "templates/**/*.j2", "static/**/*"]
28
+
29
+ [project.entry-points."fastpluggy.plugins"]
30
+ ui_tools = "fastpluggy_plugin.ui_tools.plugin:UiToolsModule"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .plugin import UiToolsModule
File without changes
@@ -0,0 +1,51 @@
1
+ """
2
+ Alert widget for displaying messages.
3
+ """
4
+
5
+ from typing import Optional
6
+ from fastpluggy.core.widgets.base import AbstractWidget
7
+
8
+
9
+ class AlertWidget(AbstractWidget):
10
+ """Bootstrap alert widget for displaying messages."""
11
+
12
+ widget_type = "alert"
13
+ template_name = "ui_tools/extra_widget/display/alert.html.j2"
14
+ category = "display"
15
+ description = "Bootstrap alert component for displaying contextual feedback messages"
16
+ icon = "exclamation-triangle"
17
+
18
+ def __init__(
19
+ self,
20
+ message: str = "",
21
+ alert_type: str = "info",
22
+ dismissible: bool = True,
23
+ auto_dismiss: Optional[int] = None,
24
+ icon: Optional[str] = None,
25
+ **kwargs
26
+ ):
27
+ super().__init__(**kwargs)
28
+ self.message = message
29
+ self.alert_type = alert_type
30
+ self.dismissible = dismissible
31
+ self.auto_dismiss = auto_dismiss
32
+ self.icon = icon
33
+
34
+ def process(self, **kwargs) -> None:
35
+ """Build alert classes and configuration."""
36
+ css_classes = [f"alert alert-{self.alert_type}"]
37
+
38
+ if self.dismissible:
39
+ css_classes.append("alert-dismissible fade show")
40
+
41
+ self.css_classes = " ".join(css_classes)
42
+
43
+ # Default icons for alert types
44
+ if not self.icon:
45
+ icon_mapping = {
46
+ "success": "check-circle",
47
+ "danger": "exclamation-circle",
48
+ "warning": "exclamation-triangle",
49
+ "info": "info-circle"
50
+ }
51
+ self.icon = icon_mapping.get(self.alert_type, "info-circle")
@@ -0,0 +1,79 @@
1
+ """
2
+ Card widget for content display.
3
+ """
4
+
5
+ from typing import Optional, List
6
+ from fastpluggy.core.widgets.base import AbstractWidget
7
+
8
+
9
+ class CardWidget(AbstractWidget):
10
+ """Bootstrap-style card widget for content display."""
11
+
12
+ widget_type = "card"
13
+ template_name = "ui_tools/extra_widget/display/card.html.j2"
14
+ macro_name = "render_card"
15
+ render_method = "macro"
16
+
17
+ category = "display"
18
+ description = "Bootstrap card component for displaying content with optional header, body, and footer"
19
+ icon = "rectangle-list"
20
+
21
+ def __init__(
22
+ self,
23
+ title: Optional[str] = None,
24
+ content: Optional[str | List[str]] = None,
25
+ footer: Optional[str] = None,
26
+ header: Optional[str] = None,
27
+ card_type: str = "default",
28
+ text_color: Optional[str] = None,
29
+ bg_color: Optional[str] = None,
30
+ border_color: Optional[str] = None,
31
+ image_url: Optional[str] = None,
32
+ image_position: str = "top",
33
+ links: Optional[List] = None,
34
+ **kwargs
35
+ ):
36
+ self.title = title
37
+ self.content = content
38
+ self.footer = footer
39
+ self.header = header
40
+ self.card_type = card_type
41
+ self.text_color = text_color
42
+ self.bg_color = bg_color
43
+ self.border_color = border_color
44
+ self.image_url = image_url
45
+ self.image_position = image_position
46
+ self.links = links or []
47
+ super().__init__(**kwargs)
48
+
49
+ def process(self, **kwargs) -> None:
50
+ """Build CSS classes for the card."""
51
+ css_classes = ["card"]
52
+
53
+ if self.card_type and self.card_type != "default":
54
+ card_type_mapping = {
55
+ "primary": "border-primary",
56
+ "secondary": "border-secondary",
57
+ "success": "border-success",
58
+ "danger": "border-danger",
59
+ "warning": "border-warning",
60
+ "info": "border-info",
61
+ "light": "border-light",
62
+ "dark": "border-dark"
63
+ }
64
+ if self.card_type in card_type_mapping:
65
+ css_classes.append(card_type_mapping[self.card_type])
66
+
67
+ if self.bg_color:
68
+ css_classes.append(self.bg_color)
69
+ if self.text_color:
70
+ css_classes.append(self.text_color)
71
+ if self.border_color:
72
+ css_classes.append(self.border_color)
73
+
74
+ # Convert list content to string if needed
75
+ if isinstance(self.content, list):
76
+ self.content = ''.join(self.content)
77
+
78
+ self.css_classes = " ".join(css_classes)
79
+ self.has_actions = bool(self.footer or self.links)
@@ -0,0 +1,57 @@
1
+ """
2
+ Code widget for displaying code with syntax highlighting.
3
+ """
4
+
5
+ from typing import Optional
6
+ from fastpluggy.core.widgets.base import AbstractWidget
7
+
8
+
9
+ class CodeWidget(AbstractWidget):
10
+ """Widget for displaying code with syntax highlighting."""
11
+
12
+ widget_type = "code"
13
+ template_name = "ui_tools/extra_widget/display/code.html.j2"
14
+ macro_name = "render_code"
15
+ render_method = "macro"
16
+
17
+ category = "display"
18
+ description = "Display code with syntax highlighting"
19
+ icon = "code"
20
+
21
+ def __init__(
22
+ self,
23
+ code: str,
24
+ language: Optional[str] = None,
25
+ title: Optional[str] = None,
26
+ line_numbers: bool = True,
27
+ theme: str = "default",
28
+ **kwargs
29
+ ):
30
+ """
31
+ Initialize a code widget.
32
+
33
+ Args:
34
+ code: The code to display
35
+ language: The programming language for syntax highlighting
36
+ title: Optional title for the code block
37
+ line_numbers: Whether to show line numbers
38
+ theme: The syntax highlighting theme
39
+ """
40
+ self.code = code
41
+ self.language = language
42
+ self.title = title
43
+ self.line_numbers = line_numbers
44
+ self.theme = theme
45
+ super().__init__(**kwargs)
46
+
47
+ def process(self, **kwargs) -> None:
48
+ """Process the widget before rendering."""
49
+ css_classes = ["code-widget"]
50
+
51
+ if self.language:
52
+ css_classes.append(f"language-{self.language}")
53
+
54
+ if self.theme and self.theme != "default":
55
+ css_classes.append(f"theme-{self.theme}")
56
+
57
+ self.css_classes = " ".join(css_classes)
@@ -0,0 +1,90 @@
1
+ """
2
+ Statistics and status widgets for displaying KPIs and status information.
3
+ """
4
+
5
+ from typing import Optional
6
+ from fastpluggy.core.widgets.base import AbstractWidget
7
+
8
+
9
+ class StatsWidget(AbstractWidget):
10
+ """Statistics display widget with icon, value, and trend."""
11
+
12
+ widget_type = "stats"
13
+ template_name = "ui_tools/extra_widget/display/stats.html.j2"
14
+ category = "display"
15
+ description = "Statistics card showing KPI with icon, value, and optional trend indicator"
16
+ icon = "bar-chart"
17
+
18
+ def __init__(
19
+ self,
20
+ title: str = "",
21
+ value: str = "",
22
+ icon: str = "bar-chart",
23
+ color: str = "primary",
24
+ trend: Optional[str] = None, # "up", "down", or percentage
25
+ subtitle: Optional[str] = None,
26
+ **kwargs
27
+ ):
28
+ super().__init__(**kwargs)
29
+ self.title = title
30
+ self.value = value
31
+ self.icon = icon
32
+ self.color = color
33
+ self.trend = trend
34
+ self.subtitle = subtitle
35
+
36
+ def process(self, **kwargs) -> None:
37
+ """Process stats data and determine trend styling."""
38
+ self.card_classes = f"card bg-{self.color} text-white"
39
+
40
+ # Process trend indicator
41
+ if self.trend:
42
+ if self.trend.startswith(('+', '-')) or '%' in self.trend:
43
+ self.trend_value = self.trend
44
+ self.trend_icon = "trending-up" if self.trend.startswith('+') else "trending-down"
45
+ self.trend_color = "success" if self.trend.startswith('+') else "danger"
46
+ elif self.trend in ['up', 'down']:
47
+ self.trend_icon = f"trending-{self.trend}"
48
+ self.trend_color = "success" if self.trend == 'up' else "danger"
49
+
50
+
51
+ class StatusWidget(AbstractWidget):
52
+ """Status display widget with label and value using tabler.io components."""
53
+
54
+ widget_type = "status"
55
+ template_name = "ui_tools/extra_widget/display/status.html.j2"
56
+ category = "display"
57
+ description = "Status indicator showing label and value with color-coded icon and card"
58
+ icon = "info-circle"
59
+
60
+ def __init__(
61
+ self,
62
+ label: str = "",
63
+ value: str = "",
64
+ status: str = "primary", # Bootstrap color: primary, success, danger, warning, info
65
+ icon: str = None, # Tabler icon name (without the ti ti- prefix)
66
+ **kwargs
67
+ ):
68
+ super().__init__(**kwargs)
69
+ self.label = label
70
+ self.value = value
71
+ self.status = status
72
+ self.icon = icon or self._get_default_icon(status)
73
+
74
+ def _get_default_icon(self, status: str) -> str:
75
+ """Get a default icon based on the status."""
76
+ status_icons = {
77
+ "primary": "info-circle",
78
+ "secondary": "circle-check",
79
+ "success": "check",
80
+ "danger": "alert-triangle",
81
+ "warning": "alert-circle",
82
+ "info": "info-circle"
83
+ }
84
+ return status_icons.get(status, "info-circle")
85
+
86
+ def process(self, **kwargs) -> None:
87
+ """Process status data."""
88
+ # Ensure icon is set
89
+ if not self.icon:
90
+ self.icon = self._get_default_icon(self.status)