Skip to content

Commit 55f1ded

Browse files
⚡🔨 refactor(handlers): Update template context data to include formatted date and time
- Refactored EmailHandler to add two new time formats ( ormatted_date and ormatted_time) for inclusion in the email template. - ormatted_date now uses the format %d %B %Y, with the month name in uppercase. - ormatted_time uses the format %I:%M %p. - Updated the context in ender_template to include date and ime for enhanced readability in the email notifications. - Ensured backward compatibility with the existing log entry and request data.
1 parent d3c00dd commit 55f1ded

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

django_logging/handlers/email_handler.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ def render_template(
4545
RequestLogMiddleware.get_user_agent(request) if request else "Unknown"
4646
)
4747

48+
# Get current time
49+
current_time = now()
50+
51+
# Format date and time separately
52+
formatted_date = current_time.strftime("%d %B %Y").replace(current_time.strftime("%B"), current_time.strftime("%B").upper())
53+
formatted_time = current_time.strftime("%I:%M %p")
54+
55+
4856
context = {
4957
"message": log_entry,
50-
"time": now(),
58+
"date": formatted_date,
59+
"time": formatted_time,
5160
"browser_type": user_agent,
5261
"ip_address": ip_address,
5362
}

0 commit comments

Comments
 (0)