Use plain Bulma themes when possible
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
@@ -174,6 +175,60 @@ def _service_label(service: str) -> str:
|
||||
return labels.get(key, key.title() if key else "Unknown")
|
||||
|
||||
|
||||
def _format_task_event_payload(raw_payload):
|
||||
payload = raw_payload
|
||||
if payload is None:
|
||||
payload = {}
|
||||
if isinstance(payload, str):
|
||||
text = payload.strip()
|
||||
if not text:
|
||||
return {
|
||||
"summary_items": [],
|
||||
"pretty_text": "{}",
|
||||
"is_mapping": False,
|
||||
}
|
||||
try:
|
||||
parsed = json.loads(text)
|
||||
payload = parsed
|
||||
except Exception:
|
||||
return {
|
||||
"summary_items": [("text", text[:140])],
|
||||
"pretty_text": text,
|
||||
"is_mapping": False,
|
||||
}
|
||||
|
||||
if isinstance(payload, dict):
|
||||
summary = []
|
||||
preferred = ("source", "reason", "reaction", "emoji", "presence", "last_seen_ts")
|
||||
for key in preferred:
|
||||
if key in payload:
|
||||
summary.append((key, str(payload.get(key))))
|
||||
if not summary:
|
||||
for key in list(payload.keys())[:4]:
|
||||
summary.append((str(key), str(payload.get(key))))
|
||||
pretty = json.dumps(payload, indent=2, ensure_ascii=False, sort_keys=True)
|
||||
return {
|
||||
"summary_items": summary,
|
||||
"pretty_text": pretty,
|
||||
"is_mapping": True,
|
||||
}
|
||||
|
||||
if isinstance(payload, (list, tuple)):
|
||||
pretty = json.dumps(list(payload), indent=2, ensure_ascii=False)
|
||||
return {
|
||||
"summary_items": [("items", str(len(payload)))],
|
||||
"pretty_text": pretty,
|
||||
"is_mapping": False,
|
||||
}
|
||||
|
||||
text = str(payload)
|
||||
return {
|
||||
"summary_items": [("value", text[:140])],
|
||||
"pretty_text": text,
|
||||
"is_mapping": False,
|
||||
}
|
||||
|
||||
|
||||
def _creator_label_for_message(user, service: str, message) -> str:
|
||||
msg = message
|
||||
if msg is None:
|
||||
@@ -800,6 +855,7 @@ class TaskDetail(LoginRequiredMixin, View):
|
||||
raw_actor = str(getattr(row, "actor_identifier", "") or "").strip()
|
||||
if raw_actor:
|
||||
row.actor_display = raw_actor
|
||||
row.payload_view = _format_task_event_payload(getattr(row, "payload", None))
|
||||
task.creator_label = _creator_label_for_message(
|
||||
request.user,
|
||||
str(getattr(task, "source_service", "") or "").strip().lower(),
|
||||
|
||||
Reference in New Issue
Block a user