def save(self, sender, parent_msg=None): subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] for r in self.cleaned_data['recipient']: try: profile = r.get_profile() if profile.blocked_users.filter(id=sender.id).exists(): continue except: pass msg = Message( sender=sender, recipient=r, subject=subject, body=body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) if notification: pass # if parent_msg is not None: # notification.send([sender], "messages_replied", {'message': msg,}) # notification.send([r], "messages_reply_received", {'message': msg,}) # else: # notification.send([sender], "messages_sent", {'message': msg,}) # notification.send([r], "messages_received", {'message': msg,}) return message_list
def save(self, sender, parent_msg=None): r = self.cleaned_data['recipient'] subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] r = User.objects.get(id=r) msg = Message( sender = sender, recipient = r, subject = subject, body = body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) if notification: if parent_msg is not None: notification.send([sender], "messages_replied", {'message': msg,}) else: notification.send([sender], "messages_sent", {'message': msg,}) return message_list
def save(self, sender, parent_msg=None): project = self.cleaned_data['project'] try: project = Project.objects.get(id=int(project)) except Project.DoesNotExist: raise forms.ValidationError( _(u'That study group does not exist.')) recipients = project.participants() subject = "[p2pu-%s] " % project.slug + self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] for r in recipients: msg = Message( sender=sender, recipient=r.user.user, subject=subject, body=body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) return message_list
def save(self, sender, parent_msg=None): project = self.cleaned_data['project'] try: project = Project.objects.get(id=int(project)) except Project.DoesNotExist: raise forms.ValidationError(_(u'That study group does not exist.')) recipients = project.organizers() subject = "[%s] " % project.name[:20] + self.cleaned_data['subject'] body = self.cleaned_data['body'] body = '%s\n\n%s' % ( self.cleaned_data['body'], _('You received this message through the Contact Organizer form ' 'at %(project)s: http://%(domain)s%(url)s') % { 'project': project.name, 'domain': Site.objects.get_current().domain, 'url': project.get_absolute_url() }) message_list = [] for r in recipients: msg = Message( sender=sender, recipient=r.user.user, subject=subject, body=body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) return message_list
def save(self, sender, parent_msg=None): if parent_msg is None: recipients = sender.recipients.all() else: recipients = [parent_msg.sender] subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] token='' message_list = [] for r in recipients: msg = Message( sender = sender, recipient = r, subject = subject, body = body, token = token, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) if notification: if parent_msg is not None: notification.send([sender], "messages_replied", {'message': msg,}) notification.send(recipients, "messages_reply_received", {'message': msg,}) else: notification.send([sender], "messages_sent", {'message': msg,}) notification.send(recipients, "messages_received", {'message': msg,}) return message_list
def save(self, sender, parent_msg=None): project = self.cleaned_data['project'] try: project = Project.objects.get(id=int(project)) except Project.DoesNotExist: raise forms.ValidationError(_(u'That study group does not exist.')) recipients = project.organizers() subject = "[%s] " % project.name[:20] + self.cleaned_data['subject'] body = self.cleaned_data['body'] body = '%s\n\n%s' % (self.cleaned_data['body'], _('You received this message through the Contact Organizer form ' 'at %(project)s: http://%(domain)s%(url)s') % {'project':project.name, 'domain':Site.objects.get_current().domain, 'url':project.get_absolute_url()}) message_list = [] for r in recipients: msg = Message( sender=sender, recipient=r.user.user, subject=subject, body=body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) return message_list
def save(self, sender, parent_msg=None): project = self.cleaned_data['project'] try: project = Project.objects.get(id=int(project)) except Project.DoesNotExist: raise forms.ValidationError( _(u'Hmm, that does not look like a valid project')) recipients = project.followers() subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] for r in recipients: msg = Message( sender=sender, recipient=r.user, subject=subject, body=body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) return message_list
def save(self, sender, parent_msg=None): r = self.cleaned_data['recipient'] subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] r = User.objects.get(id=r) msg = Message( sender=sender, recipient=r, subject=subject, body=body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) if notification: if parent_msg is not None: notification.send([sender], "messages_replied", { 'message': msg, }) else: notification.send([sender], "messages_sent", { 'message': msg, }) return message_list
def save(self, sender, parent_msg=None): subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] role = self.cleaned_data['recipient'] user = role.profile.user msg = Message( sender = sender, recipient = user, subject = subject, body = body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) send_mail( u"Анклав: новое сообщение в личных", u"Вам было послано сообщение. Вы можете прочитать его по ссылке http://%s%s" % (settings.DOMAIN, reverse('messages_inbox')), settings.DEFAULT_FROM_EMAIL, [user.email], ) return message_list
def save(self, sender, parent_msg=None): project = self.cleaned_data['project'] try: project = Project.objects.get(id=int(project)) except Project.DoesNotExist: raise forms.ValidationError( _(u'Hmm, that does not look like a valid course')) recipients = project.followers() subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] for r in recipients: msg = Message( sender=sender, recipient=r.user, subject=subject, body=body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) return message_list
def run(self, form, messages, **kwargs): log = self.get_logger(**kwargs) log.debug("Sending email to %d user(s)." % (len(messages),)) for message in messages: (sender, recipient, subject, body, parent) = message msg = Message(sender=sender, recipient=recipient, subject=subject, body=body) if parent is not None: msg.parent_msg = parent parent.replied_at = datetime.datetime.now() parent.save() msg.save()
def save(self, sender, parent_msg=None): recipients = self.cleaned_data['recipient'] subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] send_to_email = self.cleaned_data['send_to_email'] send_to_students = self.cleaned_data['send_to_students'] send_to_mentors = self.cleaned_data['send_to_mentors'] if isinstance(recipients, str): recipients = [] if send_to_students: student_list = [stud.pk for stud in StudentProfile.objects.all()] students_as_users = [u for u in User.objects.all().filter(user__profile__pk__in=student_list)] recipients.extend(students_as_users) if send_to_mentors: mentor_list = [ment.pk for ment in MentorProfile.objects.all()] mentors_as_users = [u for u in User.objects.all().filter(user__profile__pk__in=mentor_list)] recipients.extend(mentors_as_users) # filter only unique users recipients = list(set(recipients)) message_list = [] if send_to_email: recipient_emails = [r.get_profile().email for r in recipients] for email in recipient_emails: send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [email], priority="high") else: for r in recipients: msg = Message( sender = sender, recipient = r, subject = subject, body = body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) if notification: if parent_msg is not None: notification.send([sender], "messages_replied", {'message': msg,}) notification.send(recipients, "messages_reply_received", {'message': msg,}) else: notification.send([sender], "messages_sent", {'message': msg,}) notification.send(recipients, "messages_received", {'message': msg,}) return message_list
def save(self, sender, parent_msg=None): recipients = self.cleaned_data["recipient"] subject = self.cleaned_data["subject"] body = self.cleaned_data["body"] message_list = [] for r in recipients: msg = Message(sender=sender, recipient=r, subject=subject, body=body) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = datetime.datetime.now() parent_msg.save() msg.save() message_list.append(msg) if notification: if parent_msg is not None: notification.send([sender], "messages_replied", {"message": msg}) notification.send(recipients, "messages_reply_received", {"message": msg}) else: notification.send([sender], "messages_sent", {"message": msg}) notification.send(recipients, "messages_received", {"message": msg}) return message_list
def save(self, sender, parent_msg=None): if sender is None: raise ValidationError(self.error_messages['empty_sender'], code='empty_sender') recipients = self.cleaned_data['recipient'] subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] for r in recipients: msg = Message( sender=sender, recipient=r, subject=subject, body=body, ) if parent_msg is not None: msg.parent_msg = parent_msg parent_msg.replied_at = timezone.now() parent_msg.save() msg.save() message_list.append(msg) if notification: if parent_msg is not None: notification.send([sender], "messages_replied", { 'message': msg, }) notification.send([r], "messages_reply_received", { 'message': msg, }) else: notification.send([sender], "messages_sent", { 'message': msg, }) notification.send([r], "messages_received", { 'message': msg, }) return message_list