def save(self, *args, **kwargs): # No owner specified; use sender try: self.owner except User.DoesNotExist: self.owner = self.sender # No sent_at specified; use now if not self.sent_at: self.sent_at = datetime.datetime.now() try: if self.owner == self.sender: from parthenon_chat.utils import publish_public_notification publish_public_notification( self.recipient, "{username} just sent you a message '{subject}'.".format( username = self.owner.username, subject = self.subject, ), "notification" ) except ImportError: pass super(Message, self).save(*args, **kwargs)
def save(self, *args, **kwargs): # No owner specified; use sender try: self.owner except User.DoesNotExist: self.owner = self.sender # No sent_at specified; use now if not self.sent_at: self.sent_at = datetime.datetime.now() try: if self.owner == self.sender: from parthenon_chat.utils import publish_public_notification publish_public_notification( self.recipient, "{username} just sent you a message '{subject}'.".format( username = self.owner.username, subject = self.subject, ), "notification" ) except ImportError: pass do_send_message = False try: from activity_messages.models import ActivityMessage do_send_message = True except ImportError: do_send_message = False r = super(Message, self).save(*args, **kwargs) if do_send_message: ActivityMessage.quick_create( actor = self.sender, action = 'email-received', user = self.recipient, content_object = self ) return r