def ReplyInvite(p_accept, p_messageID): msg_m = PM.Message.objects.get(id = p_messageID) # create the reply data and send it message = MP.MessageData() message.sender = msg_m.recipient.username message.recipients = msg_m.sender.username message.subject = "Friend Invite" message.body = "The invite was " + ("accepted." if int(p_accept) else "rejected.") hret = MP.Postman.ReplyMessageByData(message.__dict__, p_messageID) # make the user friends if int(p_accept): user1_m = AM.User.objects.get(username = msg_m.sender.username) user2_m = AM.User.objects.get(username = msg_m.recipient.username) rel_m, created = MT.Relationship.objects.get_or_create( User1FK = user1_m, User2FK = user2_m, RelationValue = 1) rel_m, created = MT.Relationship.objects.get_or_create( User1FK = user2_m, User2FK = user1_m, RelationValue = 1) # disable the links in the invite message msg_m = PM.Message.objects.get(id = p_messageID) # refresh message, now with thread_id set nStart = msg_m.body.find('<span id="body_block">') nStart += len('<span id="body_block">') nStop = msg_m.body.find('</span id="body_block">') bodyMsg = msg_m.body[nStart : nStop] import html.parser html_parser = html.parser.HTMLParser() unescaped = html_parser.unescape(bodyMsg) context = { 'body': unescaped, 'messageID': None, 'replied': True, } tnc = render_to_string("message_invite.html", context) msg_m.body = tnc msg_m.save() # mark the reply message as not-replyable threadID = msg_m.thread_id rpl_m = PM.Message.objects.get(parent_id = threadID) rpl_m.replied_at = MP.Postman.GetDateNoReply() rpl_m.save() return hret
def SendInvite(p_user, p_target, p_bodyMsg): # assume the target user exists at this point because the UI requires it # assume the target user is not a friend or ignored by the requesting user # check if there is already an invite msg_m = PM.Message.objects.filter(sender__username=p_user, recipient__username=p_target, subject="Friend Invite", recipient_deleted_at=None ) if msg_m: hret = CU.HttpReturn() hret.results = "Invite already sent." hret.status = 201 return hret # create invite message and insert it # uses dummy body to be replaced later by html message = MP.MessageData() message.sender = p_user message.recipients = p_target message.subject = "Friend Invite" message.body = "Please reload page." hret = MP.Postman.WriteMessageByData(message.__dict__) # get created message data msg_m = PM.Message.objects.filter(sender__username = p_user, recipient__username = p_target, subject = "Friend Invite" ).order_by('-sent_at')[0] msgID = msg_m.id # replace body with data for body's accept/reject links context = { 'body': p_bodyMsg, 'messageID': msgID, 'replied': False, } tnc = render_to_string("message_invite.html", context) msg_m.body = tnc msg_m.replied_at = MP.Postman.GetDateNoReply() msg_m.save() return hret
def SendRewardMsg(p_userMdl, p_season, p_round, p_values): msgAdmin_m = Reporter.GetMessageAdmin() userGrade = PU.Reporter_Ranks.GetUserGrade(p_season, p_round, p_userMdl) # try: # admin_m = AM.User.objects.get(username="******") # except Exception as ex: # admin_m = None # create message model with dummy body to be replaced later message = MP.MessageData() message.sender = msgAdmin_m message.recipients = p_userMdl message.subject = "Pishbini Ranking R{0}".format(p_round) message.body = "Not initialized." hret = MP.Postman.WriteMessageByData(message.__dict__) # get created message model and replace body with js-enabled html msg_m = MP.Message.objects.filter( sender=msgAdmin_m, recipient=p_userMdl, subject__contains="Pishbini Ranking").order_by('-sent_at').first() context = { 'values': p_values, 'userGrade': userGrade, 'messageID': msg_m.id, 'claimed': False, } tnc = render_to_string("message_puRankRewards.html", context) msg_m.body = tnc msg_m.replied_at = MP.Postman.GetDateNoReply( ) # message can't be replyed in contacts.html msg_m.save() return hret
def GetAdminInbox(): fReq = MP.Postman.GetFakeRequest(MM.MESSAGE_ADMIN) cData = PV.InboxView.as_view()(fReq).context_data rawMsgs = cData['pm_messages'] messages = [] for msg in rawMsgs: newMsg = MP.MessageData() newMsg.id = msg.id newMsg.thread_id = msg.thread_id newMsg.sender = msg.sender.username + (" (" + str(msg.count) + ")" if msg.count else "") newMsg.subject = msg.subject newMsg.sent_at = msg.sent_at.strftime( CU.FORMAT_DTSTR) if msg.sent_at else None newMsg.replied_at = msg.replied_at.strftime( CU.FORMAT_DTSTR) if msg.replied_at else None messages.append(newMsg.__dict__) return messages
def WriteAdminMessage(p_request): sender = p_request.user.username recipient = p_request.POST.get('recipients') subject = p_request.POST.get('subject') body = p_request.POST.get('body') if "Technical" in recipient: subject = "[TS] " + subject elif "Suggestion" in recipient: subject = "[SI] " + subject message = MP.MessageData() message.sender = sender message.recipients = MESSAGE_ADMIN message.subject = subject message.body = body fReq = MP.Postman.GetFakeRequest(sender, message.__dict__) return MP.Postman.WriteMessage(fReq)