def construct_wavelet_json_for_http_response(wavelet_data, wave_id, wavelet_id, email, b64Encode=False): ''' Constructs the json that will be sent back through the http request from various elements @param wavelet_data: the dict with the wavelet and wavelet json @param wave_id: the id of the wave @param wavelet_id: the id of the wavelet @param email: the email of the user waiting for the response @param b64Encode=False: set to true if you want the response base64 encoded @return the json to be sent to the webpage ''' #Fetch the required data from the datastore session = sessionTools.get(wave_id, wavelet_id, email) settings = settingsTools.get(session) waveMeta = waveTools.get(wave_id, wavelet_id) if waveMeta: participant_profiles = waveMeta.participant_profiles or {} else: participant_profiles = {} #Construct the outgoing json wavelet_json = { 'wavelet' : wavelet_data.get("json"), 'readblips' : settings.read_blips or [], 'profiles' : participant_profiles, 'isPublic' : sessionTools.isPublic(session), 'rwPermission' : settings.rw_permission } if b64Encode: return base64.b64encode(simplejson.dumps(wavelet_json)) else: return simplejson.dumps(wavelet_json)
def sendFirstNotificationEmail(url, wave_id, wavelet_id, send_to, who_modified, wave_title, message=""): ''' Sends the first notification email to the user @param url: this users unique url @param wave_id: the id of the wave that the email is about @param wavelet_id: the id of the wavelet that the email is about @param send_to: the email receipient to sent the email to @param who_modified: who modified the wave and triggered the email @param wave_title: the title of the wave @param message="": the personalized message that was sent by the adder ''' if _isEmailValid(send_to): logging.info("Sending first notification email to " + send_to) #Fetch the meta wave object metaWave = waveTools.get(wave_id, wavelet_id) #Sort the message content variables for sending wave_title = wave_title or "Untitled" message = message or "No message was left" display_name = _getDisplayName(metaWave, who_modified) invitor = display_name + " (" + who_modified + ")" text_variables = { 'title' : wave_title, 'invitor' : invitor, 'message' : message, 'url' : url, 'time' : datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S'), 'robot_web' : config.ROBOT_WEB} #Generate the address and subject sender_address = config.ROBOT_EMAIL_SENDER_NAME + " <" + config.ROBOT_EMAIL_SEND_NOTIFICATION + ">" subject = "Invitation to join: " + wave_title #Send! mail.send_mail( sender_address, send_to, subject, FIRST_NOTIFICATION_PLAIN % text_variables, html=FIRST_NOTIFICATION_HTML % text_variables) logging.info("Mail sent successfully to " + send_to)
def sendNotificationEmail(url, wave_id, wavelet_id, send_to, who_modified, wave_title, who_modified_display=None): ''' Sends a notification email to the user @param url: this users unique url @param wave_id: the id of the wave that the email is about @param wavelet_id: the id of the wavelet that the email is about @param send_to: the email receipient to sent the email to @param who_modified: who modified the wave and triggered the email @param wave_title: the title of the wave @param who_modified_display=None: a friendly name of who modified the wave. If None then a friendly name is retrieved from wave meta ''' if _isEmailValid(send_to): logging.info("Sending notification email to " + send_to) #Fetch the meta wave object metaWave = waveTools.get(wave_id, wavelet_id) #Sort the message content variables for sending wave_title = wave_title or "Untitled" display_name = who_modified_display or _getDisplayName(metaWave, who_modified) invitor = display_name + " (" + who_modified + ")" text_variables = { 'title' : wave_title, 'modifier' : invitor, 'url' : url, 'time' : datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S'), 'robot_web' : config.ROBOT_WEB} #Generate the address and subject sender_address = config.ROBOT_EMAIL_SENDER_NAME + " <" + config.ROBOT_EMAIL_SEND_NOTIFICATION + ">" subject = "Update: " + wave_title mail.send_mail( sender_address, send_to, subject, REPLY_NOTIFICATION_PLAIN % text_variables, html=REPLY_NOTIFICATION_HTML % text_variables) logging.info("Mail sent successfully to " + send_to)