Exemple #1
0
def _get_assignable_dict(people, notif):
  """Get dict data for assignable object in notification.

  Args:
    people (List[Person]): List o people objects who should receive the
      notification.
    notif (Notification): Notification that should be sent.
  Returns:
    dict: dictionary containing notification data for all people in the given
      list.
  """
  obj = get_notification_object(notif)
  data = {}
  for person in people:
    # Requests have "requested_on" field instead of "start_date" and we should
    # default to today() if no appropriate field is found on the object.
    start_date = getattr(obj, "start_date",
                         getattr(obj, "requested_on",
                                 datetime.date.today()))
    data[person.email] = {
        "user": get_person_dict(person),
        notif.notification_type.name: {
            obj.id: {
                "title": obj.title,
                "fuzzy_start_date": utils.get_fuzzy_date(start_date),
                "url": get_object_url(obj),
            }
        }
    }
  return data
Exemple #2
0
def get_cycle_start_failed_data(notification, workflow):
  if workflow.status != "Active":
    return {}
  if (not workflow.next_cycle_start_date or
          workflow.next_cycle_start_date >= date.today()):
    return {}  # this can only be if the cycle has successfully started

  result = {}
  workflow_owners = get_workflow_owners_dict(workflow.context_id)
  force = workflow.notify_on_change

  for wf_owner in workflow_owners.itervalues():
    result[wf_owner["email"]] = {
        "user": wf_owner,
        "force_notifications": {
            notification.id: force
        },
        "cycle_start_failed": {
            workflow.id: {
                "workflow_owners": workflow_owners,
                "workflow_url": get_workflow_url(workflow),
                "start_date": workflow.next_cycle_start_date,
                "fuzzy_start_date": utils.get_fuzzy_date(
                    workflow.next_cycle_start_date),
                "custom_message": workflow.notify_custom_message,
                "title": workflow.title,
            }
        }
    }
  return result
Exemple #3
0
def get_workflow_starts_in_data(notification, workflow):
  if workflow.status != "Active":
    return {}
  if (not workflow.next_cycle_start_date or
          workflow.next_cycle_start_date < date.today()):
    return {}  # this can only be if the cycle has successfully started
  result = {}

  workflow_owners = get_workflow_owners_dict(workflow.context_id)
  force = workflow.notify_on_change

  for wf_person in workflow.workflow_people:
    result[wf_person.person.email] = {
        "user": data_handlers.get_person_dict(wf_person.person),
        "force_notifications": {
            notification.id: force
        },
        "cycle_starts_in": {
            workflow.id: {
                "workflow_owners": workflow_owners,
                "workflow_url": get_workflow_url(workflow),
                "start_date": workflow.next_cycle_start_date,
                "fuzzy_start_date": utils.get_fuzzy_date(
                    workflow.next_cycle_start_date),
                "custom_message": workflow.notify_custom_message,
                "title": workflow.title,
            }
        }
    }
  return result
Exemple #4
0
def get_cycle_task_dict(cycle_task):

  object_titles = []
  # every object should have a title or at least a name like person object
  for related_object in cycle_task.related_objects:
    object_titles.append(getattr(related_object, "title", "") or
                         getattr(related_object, "name", "") or
                         u"Untitled object")
  # related objects might have been deleted or unmapped,
  # check the revision history
  deleted_relationships_sources = db.session.query(Revision).filter(
      Revision.resource_type == "Relationship",
      Revision.action == "deleted",
      Revision.source_type == "CycleTaskGroupObjectTask",
      Revision.source_id == cycle_task.id
  )
  deleted_relationships_destinations = db.session.query(Revision).filter(
      Revision.resource_type == "Relationship",
      Revision.action == "deleted",
      Revision.destination_type == "CycleTaskGroupObjectTask",
      Revision.destination_id == cycle_task.id
  )
  deleted_relationships = deleted_relationships_sources.union(
      deleted_relationships_destinations).all()
  for deleted_relationship in deleted_relationships:
    removed_object_type, removed_object_id = _get_object_info_from_revision(
        deleted_relationship, "CycleTaskGroupObjectTask")
    object_data = db.session.query(Revision).filter(
        Revision.resource_type == removed_object_type,
        Revision.resource_id == removed_object_id,
    ).order_by(Revision.id.desc()).first()

    object_titles.append(
        u"{} [removed from task]".format(object_data.content["display_name"])
    )

  # the filter expression to be included in the cycle task's URL and
  # automatically applied when user visits it
  filter_exp = u"id=" + unicode(cycle_task.cycle_id)

  return {
      "title": cycle_task.title,
      "related_objects": object_titles,
      "end_date": cycle_task.end_date.strftime("%m/%d/%Y"),
      "fuzzy_due_in": utils.get_fuzzy_date(cycle_task.end_date),
      "cycle_task_url": get_cycle_task_url(cycle_task, filter_exp=filter_exp),
  }