def email_notify(cls, user, sujeito, assunto, message="", link="", sendToMyself=False): # user -> quem deve ser avisado # sujeito -> quem realizou a ação # sendToMyself=True indica que a mensagem deve ser enviada para mim, mesmo que eu tenha realizado a ação. Ex: troca de senha. if (sendToMyself or user!=sujeito) and isAUser(sujeito): if isAUser(user): # usuário a ser avisado to_user_data = model._EMPTYMEMBER() to_user_data.update(database.REGISTRY[user]) email = to_user_data["email"] notify = to_user_data["notify"] nome_destinatario = to_user_data["name"] # usuário que realizou a ação from_user_data = database.REGISTRY[sujeito] nome_completo = from_user_data["name"] + " " + from_user_data["lastname"] assunto = sendToMyself and assunto or nome_completo + " " + assunto if notify == "2": # envia e-mail imediatamente if not Notify.enviaEmail (email, assunto, nome_destinatario, message, link): # erro no envio do e-mail: guarda mensagem em NOTIFICATIONERROR notify_data = _EMPTYNOTIFICATIONERROR() if user in log.database.NOTIFICATIONERROR: notify_data.update(log.database.NOTIFICATIONERROR[user]) reg = dict( sujeito= sujeito, subject= assunto, message= message, data_inclusao= str(datetime.now()) ) notify_data["registros"].append(reg) log.database.NOTIFICATIONERROR[user] = notify_data #print "Erro no envio do email. Msg salva em NOTIFICATIONERROR" else: #print "Email enviado com sucesso para "+email pass elif notify == "1": # guarda mensagem no banco para depois enviar resumo semanal notify_data = _EMPTYNOTIFICATION() if user in log.database.NOTIFICATION: notify_data.update(log.database.NOTIFICATION[user]) reg = dict( sujeito= sujeito, subject= assunto, message= message, data_inclusao= str(datetime.now()) ) notify_data["registros"].append(reg) log.database.NOTIFICATION[user] = notify_data #print "Email salvo em NOTIFICATION" else: #print "Usuário não deseja ser notificado" pass elif isACommunity(user): for participante in database.REGISTRY[user]["participantes"]: Notify.email_notify(participante, sujeito, assunto, message, link)
def email_notify_old(cls, user, sujeito, assunto, message="", link=""): if user!=sujeito and isAUser(user) and isAUser(sujeito): # usuário a ser avisado to_user_data = model._EMPTYMEMBER() to_user_data.update(database.REGISTRY[user]) email = to_user_data["email"] notify = to_user_data["notify"] nome_destinatario = to_user_data["name"] # usuário que realizou a ação from_user_data = database.REGISTRY[sujeito] nome_completo = from_user_data["name"] + " " + from_user_data["lastname"] assunto = nome_completo + " " + assunto if notify == "2": # envia e-mail imediatamente if not Notify.enviaEmail (email, assunto, nome_destinatario, message, link): # erro no envio do e-mail: guarda mensagem em NOTIFICATIONERROR notify_data = _EMPTYNOTIFICATIONERROR() if user in log.database.NOTIFICATIONERROR: notify_data.update(log.database.NOTIFICATIONERROR[user]) reg = dict( sujeito= sujeito, subject= assunto, message= message, data_inclusao= str(datetime.now()) ) notify_data["registros"].append(reg) log.database.NOTIFICATIONERROR[user] = notify_data #print "Erro no envio do email. Msg salva em NOTIFICATIONERROR" else: #print "Email enviado com sucesso para "+email pass elif notify == "1": # guarda mensagem no banco para depois enviar resumo semanal notify_data = _EMPTYNOTIFICATION() if user in log.database.NOTIFICATION: notify_data.update(log.database.NOTIFICATION[user]) reg = dict( sujeito= sujeito, subject= assunto, message= message, data_inclusao= str(datetime.now()) ) notify_data["registros"].append(reg) log.database.NOTIFICATION[user] = notify_data #print "Email salvo em NOTIFICATION" else: #print "Usuário não deseja ser notificado" pass