From 2b09c5e45b3efb14a6698bfb6bd8d75dbac0d566 Mon Sep 17 00:00:00 2001 From: Bishwas Praveen Date: Thu, 2 May 2024 16:02:58 -0500 Subject: [PATCH 1/3] slack notifications for feedbacks --- feedback/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/feedback/models.py b/feedback/models.py index 1e1a228f..4b3d31ec 100644 --- a/feedback/models.py +++ b/feedback/models.py @@ -1,6 +1,8 @@ from django.db import models from django.utils import timezone +from sde_collections.utils.slack_utils import send_slack_message + class Feedback(models.Model): name = models.CharField(max_length=150) @@ -18,6 +20,28 @@ def save(self, *args, **kwargs): if not self.id: self.created_at = timezone.now() super().save(*args, **kwargs) + is_new = self._state.adding + if is_new: + message = self.format_notification_message() + try: + send_slack_message(message) + except Exception as e: + print(f"Failed to send slack message: {e}") + + def format_notification_message(self): + """ + Returns a formatted notification message containing details from this Feedback instance. + """ + notification_message = ( + f"New Feedback Received!\n" + f"Name: {self.name}\n" + f"Email: {self.email}\n" + f"Subject: {self.subject}\n" + f"Comments: {self.comments}\n" + f"Source: {self.source}\n" + f"Received on: {self.created_at.strftime('%Y-%m-%d %H:%M:%S')}" + ) + return notification_message class ContentCurationRequest(models.Model): From 47062d9795c4e9db7c41d7b485830f66be460bf8 Mon Sep 17 00:00:00 2001 From: Bishwas Praveen Date: Thu, 2 May 2024 16:40:50 -0500 Subject: [PATCH 2/3] made some aesthetic changes to the message --- feedback/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feedback/models.py b/feedback/models.py index 4b3d31ec..bc98536e 100644 --- a/feedback/models.py +++ b/feedback/models.py @@ -19,7 +19,6 @@ class Meta: def save(self, *args, **kwargs): if not self.id: self.created_at = timezone.now() - super().save(*args, **kwargs) is_new = self._state.adding if is_new: message = self.format_notification_message() @@ -27,13 +26,14 @@ def save(self, *args, **kwargs): send_slack_message(message) except Exception as e: print(f"Failed to send slack message: {e}") + super().save(*args, **kwargs) def format_notification_message(self): """ Returns a formatted notification message containing details from this Feedback instance. """ notification_message = ( - f"New Feedback Received!\n" + f" Hey team!! Good news! We've received a new feedback! :rocket: Here are the details : \n" f"Name: {self.name}\n" f"Email: {self.email}\n" f"Subject: {self.subject}\n" From 55fce28b26f64d0948f4057a255437a1916511e8 Mon Sep 17 00:00:00 2001 From: Bishwas Praveen Date: Thu, 2 May 2024 16:51:52 -0500 Subject: [PATCH 3/3] deleted aesthetics --- feedback/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feedback/models.py b/feedback/models.py index bc98536e..0666080f 100644 --- a/feedback/models.py +++ b/feedback/models.py @@ -33,7 +33,7 @@ def format_notification_message(self): Returns a formatted notification message containing details from this Feedback instance. """ notification_message = ( - f" Hey team!! Good news! We've received a new feedback! :rocket: Here are the details : \n" + f" New Feedback Received : \n" f"Name: {self.name}\n" f"Email: {self.email}\n" f"Subject: {self.subject}\n"