Skip to content

Commit

Permalink
issue #1098 - Eventlog - emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw committed Dec 10, 2024
1 parent d727b7b commit 056e3d5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion classification/models/classification_import_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def outstanding_import_check(sender, instance: ClassificationImportRun, **kwargs
ongoing_imports = ClassificationImportRun.ongoing_imports()

nb = NotificationBuilder("Import started")
emoji = ":golfer:" if instance.status == ClassificationImportRunStatus.COMPLETED else ":skunk:"
emoji = ":golf:" if instance.status == ClassificationImportRunStatus.COMPLETED else ":skunk:"
ongoing_message = f" ongoing imports {ongoing_imports}" if ongoing_imports else ""
nb.add_markdown(f"{emoji} Import {instance.get_status_display()} {instance.identifier} {instance.row_count} rows{ongoing_message if ongoing_imports else ''}")
# provide full details of import numbers in notification
Expand Down
5 changes: 4 additions & 1 deletion eventlog/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from django.db.models import QuerySet
from django.http import HttpRequest
from rich.text import Text

from eventlog.models import Event
from library.enums.log_level import LogLevel
from library.guardian_utils import bot_group
from library.utils import emoji_to_unicode
from snpdb.views.datatable_view import DatatableConfig, RichColumn, SortOrder


Expand All @@ -15,7 +17,8 @@ def render_data(self, row: dict[str, Any]):
if filename := row.get('filename'):
return filename
elif detail := row.get('details'):
return detail.split('\n', 1)[0]
d = detail.split('\n', 1)[0]
return emoji_to_unicode(d)

def __init__(self, request: HttpRequest):
super().__init__(request)
Expand Down
14 changes: 14 additions & 0 deletions library/utils/text_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import string
from typing import Collection, Any, Optional, Callable

from rich.text import Text


def pretty_label(label: str) -> str:
label = label.replace('_', ' ')
Expand Down Expand Up @@ -112,3 +114,15 @@ def clean_string(input_string: str) -> str:
return ""
""" Removes non-printable characters, strips whitespace """
return re.sub(f'[^{re.escape(string.printable)}]', '', input_string.strip())


def emoji_to_unicode(text_with_emojis) -> str:
_replace = {
":male-doctor:": ":man_health_worker:",
":female-doctor:": "woman_health_worker",
}
for old, new in _replace.items():
text_with_emojis = text_with_emojis.replace(old, new)

s = Text.from_markup(text_with_emojis)
return str(s)
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ redis==3.5.3
reportlab
requests>=2.32.0
requests_oauthlib
rich
rollbar
scipy
simplejson
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ redis==3.5.3
reportlab==3.6.13
requests==2.32.0
requests_oauthlib==1.3.1
rich==13.9.4
rollbar==0.16.3
scipy==1.14.1
simplejson==3.18.0
Expand Down

0 comments on commit 056e3d5

Please sign in to comment.