Skip to content

Commit

Permalink
⚡🔨 refactor(handlers): Update template context data to include format…
Browse files Browse the repository at this point in the history
…ted 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.
  • Loading branch information
FATEMEH-Z-HASHEMI committed Sep 17, 2024
1 parent d3c00dd commit 55f1ded
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion django_logging/handlers/email_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ def render_template(
RequestLogMiddleware.get_user_agent(request) if request else "Unknown"
)

# Get current time
current_time = now()

# Format date and time separately
formatted_date = current_time.strftime("%d %B %Y").replace(current_time.strftime("%B"), current_time.strftime("%B").upper())
formatted_time = current_time.strftime("%I:%M %p")


context = {
"message": log_entry,
"time": now(),
"date": formatted_date,
"time": formatted_time,
"browser_type": user_agent,
"ip_address": ip_address,
}
Expand Down

0 comments on commit 55f1ded

Please sign in to comment.