def send_reply(request,msg_body,msg_subject,msg_receiver,parent_id): ''' JSON-RPC view : meow.sendMsgReply Returns True, if the currently authenticated user is successful in sending the reply message. Inbound parameters: test string 'msg_body' & 'msg_subject'. text string 'msg_receiver' shld be username of MEOW user, 'parent_id' shld be the msg id of an existing mesage. Requires authentication to call this function. ''' try: logging.debug('start meow.sendMsgReply with %s %s %s %d ' % (msg_body,msg_subject,msg_receiver, parent_id)) msg_receiver_user = User.objects.all().filter(username=msg_receiver) if len(msg_receiver_user) != 1: return False msg_receiver_user = msg_receiver_user[0] logging.debug(" MSG %s %s %s %s %d" % (request.user, msg_receiver_user, msg_subject, msg_body,parent_id)) msg = Message( sender = request.user, recipient = msg_receiver_user, subject = msg_subject, body = msg_body, ) parent_msg_obj = Message.objects.filter(id=parent_id) if (len(parent_msg_obj)!=1): return False msg.parent_msg=parent_msg_obj[0] msg.save() return True except: logging.error('meow.sendMsgReply got exception') return False
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
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([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): 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) UserOnBoardNotification.objects.create(user=r, title="Nachricht", notify_typ="info", notify_message="Hallo, " + str( sender) + " hat Ihnen eine Nachricht zugesendet!") UserOnBoardNotification.objects.create(user=sender, title="Nachricht", notify_typ="info", notify_message="Ihr Nachricht wurde erfolgreich versendet!") 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
def save(self, parent_msg=None): # recipients = self.cleaned_data['recipient'] recipient = self.cleaned_data['recipient'] subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] # for r in recipients: r = recipient if True: msg = Message( sender = self.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.conversation = parent_msg.conversation msg.save() # FIXME: workaround to make sure msg.conversation is saved # even when creating a new conversation if not msg.conversation: msg.conversation = msg msg.save() return msg
def save(self, sender, parent_msg=None): recipients = self.cleaned_data['recipient'] subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] final_recipients = set() for r in recipients: if isinstance(r, User): final_recipients.add(r) elif isinstance(r, Group): [final_recipients.add(u) for u in r.user_set.all()] else: raise NotImplementedError for r in final_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([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): 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) 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) # some notification message should not send here,such as # 'messages_replied' and 'messages_sent' 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
def send_reply(request, msg_body, msg_subject, msg_receiver, parent_id): ''' JSON-RPC view : meow.sendMsgReply Returns True, if the currently authenticated user is successful in sending the reply message. Inbound parameters: test string 'msg_body' & 'msg_subject'. text string 'msg_receiver' shld be username of MEOW user, 'parent_id' shld be the msg id of an existing mesage. Requires authentication to call this function. ''' try: logging.debug('start meow.sendMsgReply with %s %s %s %d ' % (msg_body, msg_subject, msg_receiver, parent_id)) msg_receiver_user = User.objects.all().filter(username=msg_receiver) if len(msg_receiver_user) != 1: return False msg_receiver_user = msg_receiver_user[0] logging.debug(" MSG %s %s %s %s %d" % (request.user, msg_receiver_user, msg_subject, msg_body, parent_id)) msg = Message( sender=request.user, recipient=msg_receiver_user, subject=msg_subject, body=msg_body, ) parent_msg_obj = Message.objects.filter(id=parent_id) if (len(parent_msg_obj) != 1): return False msg.parent_msg = parent_msg_obj[0] msg.save() return True except: logging.error('meow.sendMsgReply got exception') return False
def save(self, sender, parent_msg=None): groupname = self.cleaned_data['recipient'] subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] # Added by SFH - Process group messages if present # Group identifiers are in the form "group-offering-12345" or "group-world-3434" if groupname.startswith("group-"): grouptype = groupname.split('-')[1] groupid = groupname.split('-')[2] if grouptype == "offering": offering = Offering.objects.get(course_sec_id=groupid) recipients = [profile.user for profile in offering.students.all()] 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
def save(self, sender, recipient, parent_msg=None): subject = self.cleaned_data['subject'] body = self.cleaned_data['body'] message_list = [] msg = Message( sender = sender, recipient = recipient, 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
def send_reply(self, parent_msg, body): message_list = [] recipient = parent_msg.sender sender = parent_msg.recipient subject = "re: %s" % re.sub(r"^(re:\s*)+","",parent_msg.subject) msg = Message( sender = sender, recipient = recipient, subject = subject, body = body, ) 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([recipient], "messages_reply_received", {'message': msg,}, from_address=settings.MESSAGES_HANDLER_ADDRESS) else: notification.send([sender], "messages_sent", {'message': msg,}) notification.send([recipient], "messages_received", {'message': msg,}, from_address=settings.MESSAGES_HANDLER_ADDRESS) 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'] group_recipient = self.cleaned_data['group_recipient'] message_list = [] for r in recipients: msg = Message( sender=sender, recipient=r, subject=subject, body=body, #by lxy group_recipient=group_recipient) 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([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): 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() signals.message_repled.send(sender=ComposeForm, message=msg, user=sender) else: msg.save() signals.message_sent.send(sender=ComposeForm, message=msg, user=sender) message_list.append(msg) return message_list