def dispatchOrgMemberWelcomeEmail( profile, program, program_messages, site, parent=None): """Dispatches a task to send organization member welcome email for the program to the specified profile. Args: profile: profile_model.Profile entity to which the email should be sent. program: program_model.Program entity. program_messages: program_model.ProgramMessages entity. site: site_model.Site entity. parent: Optional entity to use as the parent of the entity which is created during the process. If not specified, the specified profile entity is used. """ if program_messages.mentor_welcome_msg: sender_name, sender = mail_dispatcher.getDefaultMailSender(site=site) parent = parent or profile context = { 'to': profile.contact.email, 'sender': sender, 'sender_name': sender_name, 'subject': _DEF_ORG_MEMBER_WELCOME_MAIL_SUBJECT, 'program_name': program.name, 'to_name': profile.public_name, } mail_dispatcher.getSendMailFromTemplateStringTxn( program_messages.mentor_welcome_msg, context, parent=parent)()
def getSendMailFromTemplateStringTxn(self, to, subject, template_string, context): """Returns the transaction for sending the email Args: to: Email address to which the test messages must be sent. subject: Subject for the mail. template_string: Template string to be used to construct mail body. context: Context variables to render the mail body from template string. Returns: A function object for sending email in the background using task queue. """ sender_name, sender = mail_dispatcher.getDefaultMailSender() common_context = { 'to': to, 'sender': sender, 'sender_name': sender_name, 'program_name': self.request_data.program.name, 'subject': subject, } context.update(common_context) return mail_dispatcher.getSendMailFromTemplateStringTxn( template_string, context, parent=self.request_data.ndb_user, transactional=True)
def getSendMailFromTemplateStringTxn( self, to, subject, template_string, context): """Returns the transaction for sending the email Args: to: Email address to which the test messages must be sent. subject: Subject for the mail. template_string: Template string to be used to construct mail body. context: Context variables to render the mail body from template string. Returns: A function object for sending email in the background using task queue. """ sender_name, sender = mail_dispatcher.getDefaultMailSender() common_context = { 'to': to, 'sender': sender, 'sender_name': sender_name, 'program_name': self.request_data.program.name, 'subject': subject, } context.update(common_context) return mail_dispatcher.getSendMailFromTemplateStringTxn( template_string, context, parent=self.request_data.ndb_user, transactional=True)
def getRejectProposalMailTxn(self, proposal): """Returns the function to sent an rejectance mail for the specified proposal. """ sender_name, sender = mail_dispatcher.getDefaultMailSender() student_entity = ndb.Key.from_old_key(proposal.parent_key()).get() org_key = GSoCProposal.org.get_value_for_datastore(proposal) org = ndb.Key.from_old_key(org_key).get() program_entity = proposal.program context = { 'to': student_entity.contact.email, 'to_name': student_entity.first_name, 'sender': sender, 'sender_name': sender_name, 'proposal_title': proposal.title, 'program_name': program_entity.name, 'subject': 'Thank you for applying to %s' % (program_entity.name), 'org_entity': org, } messages = program_entity.getProgramMessages() template_string = messages.rejected_students_msg return mail_dispatcher.getSendMailFromTemplateStringTxn( template_string, context, parent=student_entity)
def txn(): record = db.get(record_key) record.status = new_status record.put() if context: template_string = context['template_string'] sub_txn = mail_dispatcher.getSendMailFromTemplateStringTxn( template_string, context, parent=record, transactional=True) sub_txn()
def getWelcomeMailTxn(self, proposal, transactional=True): """Returns the function to sent an welcome email for an accepted proposal. """ sender_name, sender = mail_dispatcher.getDefaultMailSender() student_entity = ndb.Key.from_old_key(proposal.parent_key()).get() program_entity = proposal.program context = { 'to': student_entity.contact.email, 'to_name': student_entity.first_name, 'sender': sender, 'sender_name': sender_name, 'program_name': program_entity.name, 'subject': 'Welcome to %s' % program_entity.name, } messages = program_entity.getProgramMessages() template_string = messages.accepted_students_welcome_msg return mail_dispatcher.getSendMailFromTemplateStringTxn( template_string, context, parent=student_entity, transactional=transactional)