Example #1
0
def getFirstTaskConfirmationContext(student):
    """Sends notification to the GCI student, when he or she completes their
  first task.

  Args:
    student: the student who should receive the confirmation
  """
    to = student.contact.email

    subject = DEF_FIRST_TASK_CONFIRMATION_SUBJECT

    program_key = student.program

    kwargs = {
        'sponsor': profile_model.getSponsorId(student.key),
        'program': profile_model.getProgramId(student.key)
    }
    url = reverse('gci_student_form_upload', kwargs=kwargs)

    protocol = 'http'
    hostname = site.getHostname()

    context = {
        'student_forms_link': '%s://%s%s' % (protocol, hostname, url),
    }

    template = DEF_FIRST_TASK_CONFIRMATION_TEMPLATE
    body = loader.render_to_string(template, context)

    return mailer.getMailContext(to=to, subject=subject, html=body, bcc=[])
Example #2
0
def getFirstTaskConfirmationContext(student):
  """Sends notification to the GCI student, when he or she completes their
  first task.

  Args:
    student: the student who should receive the confirmation
  """
  to = student.contact.email

  subject = DEF_FIRST_TASK_CONFIRMATION_SUBJECT

  program_key = student.program

  kwargs = {
      'sponsor': profile_model.getSponsorId(student.key),
      'program': profile_model.getProgramId(student.key)
      }
  url = reverse('gci_student_form_upload', kwargs=kwargs)

  protocol = 'http'
  hostname = site.getHostname()

  context = {
      'student_forms_link': '%s://%s%s' % (protocol, hostname, url),
      }

  template = DEF_FIRST_TASK_CONFIRMATION_TEMPLATE
  body = loader.render_to_string(template, context)

  return mailer.getMailContext(to=to, subject=subject, html=body, bcc=[])
Example #3
0
def _getContextCommon(site, program, receivers, message_properties,
                      subject, body):
  """Sends out a notification to the specified user.

  Args:
    site: Site entity.
    program: Program entity to which the notification applies.
    receivers: Email addresses to which the notification should be sent.
    message_properties: Message properties.
    subject: Subject of notification email.
    body: Email body to be sent as notification.
  Returns:
    A dictionary containing the context for a message to be sent to one
    or more recipients.
  """
  message_properties['sender_name'] = 'The %s Team' % site.site_name
  message_properties['program_name'] = program.name

  # TODO(nathaniel): "to" can be a list of email addresses or a single
  # email address? Is that right? The documentation of mailer.getMailContext
  # affords no answer.
  if len(receivers) == 1:
    to = receivers[0]
    bcc = []
  else:
    to = []
    bcc = receivers

  return mailer.getMailContext(to, subject, body, bcc=bcc)
Example #4
0
def _getContextCommon(site, program, receivers, message_properties, subject,
                      body):
    """Sends out a notification to the specified user.

  Args:
    site: Site entity.
    program: Program entity to which the notification applies.
    receivers: Email addresses to which the notification should be sent.
    message_properties: Message properties.
    subject: Subject of notification email.
    body: Email body to be sent as notification.
  Returns:
    A dictionary containing the context for a message to be sent to one
    or more recipients.
  """
    message_properties['sender_name'] = 'The %s Team' % site.site_name
    message_properties['program_name'] = program.name

    # TODO(nathaniel): "to" can be a list of email addresses or a single
    # email address? Is that right? The documentation of mailer.getMailContext
    # affords no answer.
    if len(receivers) == 1:
        to = receivers[0]
        bcc = []
    else:
        to = []
        bcc = receivers

    return mailer.getMailContext(to, subject, body, bcc=bcc)
Example #5
0
def getFirstTaskConfirmationContext(student):
  """Sends notification to the GCI student, when he or she completes their
  first task.
  
  Args:
    student: the student who should receive the confirmation
  """

  user = student.parent()
  to = accounts.denormalizeAccount(user.account).email()

  subject = DEF_FIRST_TASK_CONFIRMATION_SUBJECT

  program = student.scope

  kwargs = {
      'sponsor': program.scope_path,
      'program': program.link_id
  }
  url = reverse('gci_student_form_upload', kwargs=kwargs)

  protocol = 'http'
  hostname = system.getHostname()

  context = {
      'student_forms_link': '%s://%s%s' % (protocol, hostname, url),
      }

  template = DEF_FIRST_TASK_CONFIRMATION_TEMPLATE
  body = loader.render_to_string(template, context)

  return mailer.getMailContext(to=to, subject=subject, html=body, bcc=[])
Example #6
0
def getTaskConversationMessageContext(message, to_emails, is_reply):
    """Sends out notifications to the conversation's participants.

  Args:
    message: Key (ndb) of GCIMessage to send.
    to_emails: List of recipients for the notification.
    is_reply: Whether this message is a reply to an existing conversation.

  Returns:
    Context dictionary for a mailer task.
  """
    message_ent = message.get()
    conversation_ent = message_ent.conversation.get()
    program_ent = db.get(ndb.Key.to_old_key(conversation_ent.program))
    author_ent = message_ent.author.get()

    url_kwargs = {
        'sponsor': program_logic.getSponsorKey(program_ent).name(),
        'program': program_ent.link_id,
        'id': conversation_ent.key.integer_id(),
    }

    conversation_url = 'http://%(host)s%(conversation)s' % {
        'host': site.getHostname(),
        'conversation': reverse(url_names.GCI_CONVERSATION, kwargs=url_kwargs)
    }

    message_url = 'http://%(host)s%(conversation)s#m%(message_id)s' % {
        'host': site.getHostname(),
        'conversation': reverse(url_names.GCI_CONVERSATION, kwargs=url_kwargs),
        'message_id': message.integer_id()
    }

    message_by = author_ent.user_id if author_ent else 'Melange'

    message_properties = {
        'author_name': message_by,
        'conversation_subject': conversation_ent.subject,
        'message_content': message_ent.content,
        'sender_name': 'The %s Team' % site.singleton().site_name,
        'conversation_url': conversation_url,
        'message_url': message_url,
        'program_name': program_ent.name,
        'is_reply': is_reply,
    }

    subject = ((DEF_NEW_MESSAGE_SUBJECT if is_reply else
                DEF_NEW_CONVERSATION_SUBJECT) % message_properties)

    template = (DEF_NEW_MESSAGE_NOTIFICATION_TEMPLATE
                if is_reply else DEF_NEW_CONVERSATION_NOTIFICATION_TEMPLATE)

    body = loader.render_to_string(template, dictionary=message_properties)

    return mailer.getMailContext(to=[],
                                 subject=subject,
                                 html=body,
                                 bcc=to_emails)
Example #7
0
def getTaskConversationMessageContext(message, to_emails, is_reply):
  """Sends out notifications to the conversation's participants.

  Args:
    message: Key (ndb) of GCIMessage to send.
    to_emails: List of recipients for the notification.
    is_reply: Whether this message is a reply to an existing conversation.

  Returns:
    Context dictionary for a mailer task.
  """
  message_ent = message.get()
  conversation_ent = message_ent.conversation.get()
  program_ent = db.get(ndb.Key.to_old_key(conversation_ent.program))
  author_ent = message_ent.author.get()

  url_kwargs = {
    'sponsor': program_logic.getSponsorKey(program_ent).name(),
    'program': program_ent.link_id,
    'id': conversation_ent.key.integer_id(),
  }

  conversation_url = 'http://%(host)s%(conversation)s' % {
      'host': site.getHostname(),
      'conversation': reverse(url_names.GCI_CONVERSATION, kwargs=url_kwargs)}

  message_url = 'http://%(host)s%(conversation)s#m%(message_id)s' % {
      'host': site.getHostname(),
      'conversation': reverse(url_names.GCI_CONVERSATION, kwargs=url_kwargs),
      'message_id': message.integer_id()}

  message_by = author_ent.user_id if author_ent else 'Melange'

  message_properties = {
      'author_name': message_by,
      'conversation_subject': conversation_ent.subject,
      'message_content': message_ent.content,
      'sender_name': 'The %s Team' % site.singleton().site_name,
      'conversation_url': conversation_url,
      'message_url': message_url,
      'program_name': program_ent.name,
      'is_reply': is_reply,
  }

  subject = ((
      DEF_NEW_MESSAGE_SUBJECT if is_reply else DEF_NEW_CONVERSATION_SUBJECT)
         % message_properties)

  template = (
      DEF_NEW_MESSAGE_NOTIFICATION_TEMPLATE if is_reply
      else DEF_NEW_CONVERSATION_NOTIFICATION_TEMPLATE)

  body = loader.render_to_string(template, dictionary=message_properties)

  return mailer.getMailContext(to=[], subject=subject, html=body, bcc=to_emails)
Example #8
0
def getTaskCommentContext(task, comment, to_emails):
    """Sends out notifications to the subscribers.

  Args:
    task: task entity that comment made on.
    comment: comment entity.
    to_emails: list of recepients for the notification.
  """
    url_kwargs = {
        'sponsor': program_logic.getSponsorKey(task.program).name(),
        'program': task.program.link_id,
        'id': task.key().id(),
    }

    task_url = 'http://%(host)s%(task)s' % {
        'host': site.getHostname(),
        'task': reverse('gci_view_task', kwargs=url_kwargs)
    }

    author_key = (
        comment_model.GCIComment.created_by.get_value_for_datastore(comment))
    author = ndb.Key.from_old_key(author_key).get() if author_key else None
    commented_by = author.user_id if author else 'Melange'

    message_properties = {
        'commented_by': commented_by,
        'comment_title': comment.title,
        'comment_content': comment.content,
        'group': task.org.name,
        'program_name': task.program.name,
        'sender_name': 'The %s Team' % site.singleton().site_name,
        'task_title': task.title,
        'task_url': task_url,
    }

    subject = DEF_NEW_TASK_COMMENT_SUBJECT % message_properties
    template = DEF_NEW_TASK_COMMENT_NOTIFICATION_TEMPLATE
    body = loader.render_to_string(template, dictionary=message_properties)

    return mailer.getMailContext(to=[],
                                 subject=subject,
                                 html=body,
                                 bcc=to_emails)
Example #9
0
def getTaskCommentContext(task, comment, to_emails):
  """Sends out notifications to the subscribers.

  Args:
    task: task entity that comment made on.
    comment: comment entity.
    to_emails: list of recepients for the notification.
  """
  url_kwargs = {
    'sponsor': program_logic.getSponsorKey(task.program).name(),
    'program': task.program.link_id,
    'id': task.key().id(),
  }

  task_url = 'http://%(host)s%(task)s' % {
      'host': site.getHostname(),
      'task': reverse('gci_view_task', kwargs=url_kwargs)}

  author_key = (
      comment_model.GCIComment.created_by
          .get_value_for_datastore(comment))
  author = ndb.Key.from_old_key(author_key).get() if author_key else None
  commented_by = author.user_id if author else 'Melange'

  message_properties = {
      'commented_by': commented_by,
      'comment_title': comment.title,
      'comment_content': comment.content,
      'group': task.org.name,
      'program_name': task.program.name,
      'sender_name': 'The %s Team' % site.singleton().site_name,
      'task_title': task.title,
      'task_url': task_url,
  }

  subject = DEF_NEW_TASK_COMMENT_SUBJECT % message_properties
  template = DEF_NEW_TASK_COMMENT_NOTIFICATION_TEMPLATE
  body = loader.render_to_string(template, dictionary=message_properties)

  return mailer.getMailContext(to=[], subject=subject, html=body, bcc=to_emails)
Example #10
0
def getContext(data, receivers, message_properties, subject, template):
  """Sends out a notification to the specified user.

  Args:
    receivers: email addresses to which the notification should be sent
    message_properties : message properties
    subject : subject of notification email
    template : template used for generating notification
  """
  message_properties['sender_name'] = 'The %s Team' % (data.site.site_name)
  message_properties['program_name'] = data.program.name

  body = loader.render_to_string(template, dictionary=message_properties)

  if len(receivers) == 1:
    to = receivers[0]
    bcc = []
  else:
    to = []
    bcc = receivers

  return mailer.getMailContext(to, subject, body, bcc=bcc)
Example #11
0
def getTaskCommentContext(task, comment, to_emails):
  """Sends out notifications to the subscribers.

  Args:
    task: task entity that comment made on.
    comment: comment entity.
    to_emails: list of recepients for the notification.
  """
  url_kwargs = {
    'sponsor': task.program.scope_path,
    'program': task.program.link_id,
    'id': task.key().id(),
  }

  task_url = 'http://%(host)s%(task)s' % {
      'host': system.getHostname(),
      'task': reverse('gci_view_task', kwargs=url_kwargs)}

  commented_by = comment.created_by.name if comment.created_by else "Melange"

  message_properties = {
      'commented_by': commented_by,
      'comment_title': comment.title,
      'comment_content': comment.content,
      'group': task.org.name,
      'program_name': task.program.name,
      'sender_name': 'The %s Team' % site.singleton().site_name,
      'task_title': task.title,
      'task_url': task_url,
  }

  subject = DEF_NEW_TASK_COMMENT_SUBJECT % message_properties
  template = DEF_NEW_TASK_COMMENT_NOTIFICATION_TEMPLATE
  body = loader.render_to_string(template, dictionary=message_properties)

  return mailer.getMailContext(to=[], subject=subject, html=body, bcc=to_emails)