-
Notifications
You must be signed in to change notification settings - Fork 290
[Feature] Add column_type_formatters_detail
#999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mmzeynalli
merged 12 commits into
smithyhq:main
from
maxim-f1:column-type-formatters-detail
Jul 13, 2026
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1015d36
[Feature] Column type formatters are now separated for list and detai…
451315c
Merge branch 'main' into column-type-formatters-detail
1a5b34d
Merge branch 'refs/heads/main' into column-type-formatters-detail
30bba27
* Now lists from `relationship` fields will be automatically unpacked.
477f62d
* Fix `StrEnum` compatibility
a411380
* Fix `StrEnum` compatibility
0ce4141
* Fix `StrEnum` compatibility
1ad7ed7
* Fix `StrEnum` compatibility
2080ace
Merge branch 'main' into column-type-formatters-detail
mmzeynalli 030e925
fix: made copy safer and fixed _default_formatter
mmzeynalli 6a2d1ff
Merge branch 'main' into column-type-formatters-detail
mmzeynalli d59837d
Merge branch 'main' into column-type-formatters-detail
mmzeynalli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,89 @@ | ||
| import datetime | ||
| import enum | ||
| import sys | ||
| from typing import Any | ||
|
|
||
| from markupsafe import Markup | ||
|
|
||
| from sqladmin._types import BASE_FORMATTERS_TYPE | ||
|
|
||
| def empty_formatter(value: Any) -> str: | ||
| if sys.version_info < (3, 11): | ||
|
|
||
| class StrEnum(str, enum.Enum): | ||
| __str__ = str.__str__ | ||
| __repr__ = enum.Enum.__repr__ | ||
| else: | ||
| from enum import StrEnum as StrEnum # noqa: F401 | ||
|
|
||
|
|
||
| def empty_formatter(value: Any) -> Markup: | ||
| """Return empty string for `None` value""" | ||
| return "" | ||
|
|
||
| return Markup("") # nosec | ||
|
|
||
|
|
||
| def bool_formatter(value: bool) -> Markup: | ||
| """Return check icon if value is `True` or X otherwise.""" | ||
|
|
||
| icon_class = "fa-check text-success" if value else "fa-times text-danger" | ||
| return Markup("<i class='fa {}'></i>").format(icon_class) | ||
| return Markup("<i class='fa {}'></i>").format(icon_class) # nosec | ||
|
|
||
|
|
||
| def str_enum_formatter(value: StrEnum) -> Markup: | ||
| """Return badge for value and list of available StrEnum values in tooltip.""" | ||
|
|
||
| title = "" | ||
| if hasattr(value, "_member_names_") and len(value._member_names_) > 0: | ||
| title = f'title="Available values: {", ".join(value._member_names_)}">' | ||
|
|
||
| return Markup( | ||
| f'<span class="my-1 py-1 px-2 badge bg-secondary ' | ||
| f'text-light lead d-inline-block text-truncate" ' | ||
| f'data-bs-toggle="tooltip" ' | ||
| f'data-bs-html="true" ' | ||
| f'data-bs-placement="bottom" ' | ||
| f"{title}" | ||
| f"{value}" | ||
| f"</span>" | ||
| ) # nosec | ||
|
|
||
|
|
||
| def datetime_formatter(value: datetime.datetime) -> Markup: | ||
| """Return badge for easy viewing of datetime.""" | ||
|
|
||
| return Markup( | ||
| f"<span " | ||
| f'class="my-1 py-1 px-2 badge bg-secondary text-light ' | ||
| f'lead d-inline-block text-truncate" ' | ||
| f'data-bs-toggle="tooltip" ' | ||
| f'data-bs-html="true" ' | ||
| f'data-bs-placement="bottom" ' | ||
| f'title="{value}"' | ||
| f">" | ||
| f'<i class="fa-solid fa-calendar-days"></i> ' | ||
| f"{value.strftime('%d %B %Y %H:%M:%S')}" | ||
| f"</span>" | ||
| ) # nosec | ||
|
|
||
|
|
||
| def copy_to_clipboard_formatter(value: Any) -> Markup: | ||
| """Return value with copy to clipboard button and alert.""" | ||
|
|
||
| return Markup( | ||
| f'<div class="d-flex justify-content-start align-items-center">' | ||
| f'<div class="me-2">{value}</div>' | ||
| f"<button " | ||
| f'class="btn btn-link p-2 me-2" ' | ||
| f"""onclick='copyToClipboard(this, "{value}")'""" | ||
| f">" | ||
| f'<i class="fas fa-copy"></i>' | ||
| f"</button>" | ||
| f'<div class="alert alert-primary fade mb-0 p-1">Copied!</div>' | ||
| f"</div>" | ||
| ) # nosec | ||
|
|
||
|
|
||
| BASE_FORMATTERS = { | ||
| BASE_FORMATTERS: BASE_FORMATTERS_TYPE = { | ||
| type(None): empty_formatter, | ||
| bool: bool_formatter, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import StrEnum from formatters