Ejemplo n.º 1
0
def storeAndNotifyTxn(comment, task=None):
    """Returns a method to be run in a transaction to notify subscribers.

  Args:
    comment: A GCIComment instance
    task: optional GCITask instance that is the parent of the specified comment
  """
    if not task:
        task = comment.parent()
    elif task.key() != comment.parent_key():
        raise ValueError(
            "The specified task must be the parent of the comment")

    if comment_model.GCIComment.created_by.get_value_for_datastore(comment):
        author_key = ndb.Key.from_old_key(
            comment_model.GCIComment.created_by.get_value_for_datastore(
                comment))
    else:
        author_key = None

    to_emails = []
    profiles = ndb.get_multi(map(ndb.Key.from_old_key, task.subscribers))
    for profile in profiles:
        if profile and ((not author_key)
                        or profile.key.parent() != author_key):
            to_emails.append(profile.contact.email)

    # Send out an email to an entire organization when set.
    org = task.org
    if org.notification_mailing_list:
        to_emails.append(org.notification_mailing_list)

    context = notifications.getTaskCommentContext(task, comment, to_emails)
    sub_txn = mailer.getSpawnMailTaskTxn(context, parent=task)

    def txn():
        sub_txn()
        comment.put()

    return txn
Ejemplo n.º 2
0
def storeAndNotifyTxn(comment, task=None):
  """Returns a method to be run in a transaction to notify subscribers.

  Args:
    comment: A GCIComment instance
    task: optional GCITask instance that is the parent of the specified comment
  """
  if not task:
    task = comment.parent()
  elif task.key() != comment.parent_key():
    raise ValueError("The specified task must be the parent of the comment")

  if comment_model.GCIComment.created_by.get_value_for_datastore(comment):
    author_key = ndb.Key.from_old_key(
        comment_model.GCIComment.created_by.get_value_for_datastore(comment))
  else:
    author_key = None

  to_emails = []
  profiles = ndb.get_multi(map(ndb.Key.from_old_key, task.subscribers))
  for profile in profiles:
    if profile and ((not author_key) or profile.key.parent() != author_key):
      to_emails.append(profile.contact.email)

  # Send out an email to an entire organization when set.
  org = task.org
  if org.notification_mailing_list:
    to_emails.append(org.notification_mailing_list)

  context = notifications.getTaskCommentContext(task, comment, to_emails)
  sub_txn = mailer.getSpawnMailTaskTxn(context, parent=task)
  def txn():
    sub_txn()
    comment.put()

  return txn