Skip to content

Commit

Permalink
update: add trim_string renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Apr 29, 2024
1 parent d1f3ca0 commit 51b5604
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
27 changes: 23 additions & 4 deletions ckanext/ap_main/col_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,26 @@ def day_passed(

days_passed = (current_date - datetime_obj).days

return tk.literal(tk.render(
"admin_panel/renderers/day_passed.html",
extra_vars={"value": days_passed},
))
return tk.literal(
tk.render(
"admin_panel/renderers/day_passed.html",
extra_vars={"value": days_passed},
)
)


@renderer
def trim_string(
value: str, options: dict[str, Any], name: str, record: Any, self: BaseSerializer
) -> str:
"""Trim string to a certain length"""
if not value:
return ""

max_length: int = options.get("max_length", 79)
trimmed_value: str = value[:max_length]

if tk.asbool(options.get("add_ellipsis", True)):
trimmed_value += "..."

return trimmed_value
1 change: 1 addition & 0 deletions ckanext/ap_main/collection/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ContentCollection(ApCollection):
"row_actions": "Actions",
},
serializers={
"notes": [("trim_string", {"max_length": 100})],
"creator_user_id": [("user_link", {})],
"metadata_created": [("date", {})],
"metadata_modified": [("date", {})],
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ckanext-admin-panel
version = 1.0.1
version = 1.0.11
description = Custom admin panel for CKAN to expand default functionality
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit 51b5604

Please sign in to comment.