Beispiel #1
0
def update_userstories_order_in_bulk(bulk_data: list, field: str,
                                     project: object,
                                     status: object = None,
                                     milestone: object = None):
    """
    Updates the order of the userstories specified adding the extra updates
    needed to keep consistency.
    `bulk_data` should be a list of dicts with the following format:
    `field` is the order field used

    [{'us_id': <value>, 'order': <value>}, ...]
    """
    user_stories = project.user_stories.all()
    if status is not None:
        user_stories = user_stories.filter(status=status)
    if milestone is not None:
        user_stories = user_stories.filter(milestone=milestone)

    us_orders = {us.id: getattr(us, field) for us in user_stories}
    new_us_orders = {e["us_id"]: e["order"] for e in bulk_data}
    apply_order_updates(us_orders, new_us_orders, remove_equal_original=True)

    user_story_ids = us_orders.keys()
    events.emit_event_for_ids(ids=user_story_ids,
                              content_type="userstories.userstory",
                              projectid=project.pk)
    db.update_attr_in_bulk_for_ids(us_orders, field, models.UserStory)
    return us_orders
Beispiel #2
0
def update_tasks_milestone_in_bulk(bulk_data: list, milestone: object):
    """
    Update the milestone and the milestone order of some tasks adding
    the extra orders needed to keep consistency.
    `bulk_data` should be a list of dicts with the following format:
    [{'task_id': <value>, 'order': <value>}, ...]
    """
    tasks = milestone.tasks.all()
    task_orders = {task.id: getattr(task, "taskboard_order") for task in tasks}
    new_task_orders = {}
    for e in bulk_data:
        new_task_orders[e["task_id"]] = e["order"]
        # The base orders where we apply the new orders must containg all
        # the values
        task_orders[e["task_id"]] = e["order"]

    apply_order_updates(task_orders, new_task_orders)

    task_milestones = {e["task_id"]: milestone.id for e in bulk_data}
    task_ids = task_milestones.keys()

    events.emit_event_for_ids(ids=task_ids,
                              content_type="tasks.task",
                              projectid=milestone.project.pk)

    db.update_attr_in_bulk_for_ids(task_milestones, "milestone_id",
                                   model=models.Task)

    db.update_attr_in_bulk_for_ids(task_orders, "taskboard_order", models.Task)

    return task_milestones
Beispiel #3
0
def update_tasks_order_in_bulk(bulk_data: list,
                               field: str,
                               project: object,
                               user_story: object = None,
                               status: object = None,
                               milestone: object = None):
    """
    Updates the order of the tasks specified adding the extra updates needed
    to keep consistency.

    [{'task_id': <value>, 'order': <value>}, ...]
    """
    tasks = project.tasks.all()
    if user_story is not None:
        tasks = tasks.filter(user_story=user_story)
    if status is not None:
        tasks = tasks.filter(status=status)
    if milestone is not None:
        tasks = tasks.filter(milestone=milestone)

    task_orders = {task.id: getattr(task, field) for task in tasks}
    new_task_orders = {e["task_id"]: e["order"] for e in bulk_data}
    apply_order_updates(task_orders, new_task_orders)

    task_ids = task_orders.keys()
    events.emit_event_for_ids(ids=task_ids,
                              content_type="tasks.task",
                              projectid=project.pk)

    db.update_attr_in_bulk_for_ids(task_orders, field, models.Task)
    return task_orders
Beispiel #4
0
def update_tasks_milestone_in_bulk(bulk_data: list, milestone: object):
    """
    Update the milestone and the milestone order of some tasks adding
    the extra orders needed to keep consistency.
    `bulk_data` should be a list of dicts with the following format:
    [{'task_id': <value>, 'order': <value>}, ...]
    """
    tasks = milestone.tasks.all()
    task_orders = {task.id: getattr(task, "taskboard_order") for task in tasks}
    new_task_orders = {}
    for e in bulk_data:
        new_task_orders[e["task_id"]] = e["order"]
        # The base orders where we apply the new orders must containg all
        # the values
        task_orders[e["task_id"]] = e["order"]

    apply_order_updates(task_orders, new_task_orders)

    task_milestones = {e["task_id"]: milestone.id for e in bulk_data}
    task_ids = task_milestones.keys()

    events.emit_event_for_ids(ids=task_ids,
                              content_type="tasks.task",
                              projectid=milestone.project.pk)

    db.update_attr_in_bulk_for_ids(task_milestones,
                                   "milestone_id",
                                   model=models.Task)

    db.update_attr_in_bulk_for_ids(task_orders, "taskboard_order", models.Task)

    return task_milestones
Beispiel #5
0
def update_epic_related_userstories_order_in_bulk(bulk_data: list,
                                                  epic: object):
    """
    Updates the order of the related userstories of an specific epic.
    `bulk_data` should be a list of dicts with the following format:
    `epic` is the epic with related stories.

    [{'us_id': <value>, 'order': <value>}, ...]
    """
    related_user_stories = epic.relateduserstory_set.all()
    # select_related
    rus_orders = {rus.id: rus.order for rus in related_user_stories}

    rus_conversion = {
        rus.user_story_id: rus.id
        for rus in related_user_stories
    }
    new_rus_orders = {
        rus_conversion[e["us_id"]]: e["order"]
        for e in bulk_data if e["us_id"] in rus_conversion
    }

    apply_order_updates(rus_orders, new_rus_orders)

    if rus_orders:
        related_user_story_ids = rus_orders.keys()
        events.emit_event_for_ids(ids=related_user_story_ids,
                                  content_type="epics.relateduserstory",
                                  projectid=epic.project_id)

        db.update_attr_in_bulk_for_ids(rus_orders, "order",
                                       models.RelatedUserStory)

    return rus_orders
Beispiel #6
0
def update_userstories_order_in_bulk(bulk_data: list,
                                     field: str,
                                     project: object,
                                     status: object = None,
                                     milestone: object = None):
    """
    Updates the order of the userstories specified adding the extra updates
    needed to keep consistency.
    `bulk_data` should be a list of dicts with the following format:
    `field` is the order field used

    [{'us_id': <value>, 'order': <value>}, ...]
    """
    user_stories = project.user_stories.all()
    if status is not None:
        user_stories = user_stories.filter(status=status)
    if milestone is not None:
        user_stories = user_stories.filter(milestone=milestone)

    us_orders = {us.id: getattr(us, field) for us in user_stories}
    new_us_orders = {e["us_id"]: e["order"] for e in bulk_data}
    apply_order_updates(us_orders, new_us_orders, remove_equal_original=True)

    user_story_ids = us_orders.keys()
    events.emit_event_for_ids(ids=user_story_ids,
                              content_type="userstories.userstory",
                              projectid=project.pk)
    db.update_attr_in_bulk_for_ids(us_orders, field, models.UserStory)
    return us_orders
Beispiel #7
0
def update_userstories_milestone_in_bulk(bulk_data: list, milestone: object):
    """
    Update the milestone and the milestone order of some user stories adding
    the extra orders needed to keep consistency.
    `bulk_data` should be a list of dicts with the following format:
    [{'us_id': <value>, 'order': <value>}, ...]
    """
    user_stories = milestone.user_stories.all()
    us_orders = {us.id: getattr(us, "sprint_order") for us in user_stories}
    new_us_orders = {}
    for e in bulk_data:
        new_us_orders[e["us_id"]] = e["order"]
        # The base orders where we apply the new orders must containg all
        # the values
        us_orders[e["us_id"]] = e["order"]

    apply_order_updates(us_orders, new_us_orders)

    us_milestones = {e["us_id"]: milestone.id for e in bulk_data}
    user_story_ids = us_milestones.keys()

    events.emit_event_for_ids(ids=user_story_ids,
                              content_type="userstories.userstory",
                              projectid=milestone.project.pk)

    db.update_attr_in_bulk_for_ids(us_milestones, "milestone_id",
                                   model=models.UserStory)
    db.update_attr_in_bulk_for_ids(us_orders, "sprint_order", models.UserStory)

    # Updating the milestone for the tasks
    Task.objects.filter(
        user_story_id__in=[e["us_id"] for e in bulk_data]).update(
        milestone=milestone)

    return us_orders
Beispiel #8
0
def update_epic_related_userstories_order_in_bulk(bulk_data: list, epic: object):
    """
    Updates the order of the related userstories of an specific epic.
    `bulk_data` should be a list of dicts with the following format:
    `epic` is the epic with related stories.

    [{'us_id': <value>, 'order': <value>}, ...]
    """
    related_user_stories = epic.relateduserstory_set.all()
    # select_related
    rus_orders = {rus.id: rus.order for rus in related_user_stories}

    rus_conversion = {rus.user_story_id: rus.id for rus in related_user_stories}
    new_rus_orders = {rus_conversion[e["us_id"]]: e["order"] for e in bulk_data
                      if e["us_id"] in rus_conversion}

    apply_order_updates(rus_orders, new_rus_orders)

    if rus_orders:
        related_user_story_ids = rus_orders.keys()
        events.emit_event_for_ids(ids=related_user_story_ids,
                                  content_type="epics.relateduserstory",
                                  projectid=epic.project_id)

        db.update_attr_in_bulk_for_ids(rus_orders, "order", models.RelatedUserStory)

    return rus_orders
Beispiel #9
0
def update_userstories_milestone_in_bulk(bulk_data: list, milestone: object):
    """
    Update the milestone and the milestone order of some user stories adding
    the extra orders needed to keep consistency.
    `bulk_data` should be a list of dicts with the following format:
    [{'us_id': <value>, 'order': <value>}, ...]
    """
    user_stories = milestone.user_stories.all()
    us_orders = {us.id: getattr(us, "sprint_order") for us in user_stories}
    new_us_orders = {}
    for e in bulk_data:
        new_us_orders[e["us_id"]] = e["order"]
        # The base orders where we apply the new orders must containg all
        # the values
        us_orders[e["us_id"]] = e["order"]

    apply_order_updates(us_orders, new_us_orders)

    us_milestones = {e["us_id"]: milestone.id for e in bulk_data}
    user_story_ids = us_milestones.keys()

    events.emit_event_for_ids(ids=user_story_ids,
                              content_type="userstories.userstory",
                              projectid=milestone.project.pk)

    db.update_attr_in_bulk_for_ids(us_milestones, "milestone_id",
                                   model=models.UserStory)
    db.update_attr_in_bulk_for_ids(us_orders, "sprint_order", models.UserStory)

    # Updating the milestone for the tasks
    Task.objects.filter(
        user_story_id__in=[e["us_id"] for e in bulk_data]).update(
        milestone=milestone)

    return us_orders
Beispiel #10
0
def update_tasks_order_in_bulk(bulk_data: list, field: str, project: object,
                               user_story: object=None, status: object=None, milestone: object=None):
    """
    Updates the order of the tasks specified adding the extra updates needed
    to keep consistency.

    [{'task_id': <value>, 'order': <value>}, ...]
    """
    tasks = project.tasks.all()
    if user_story is not None:
        tasks = tasks.filter(user_story=user_story)
    if status is not None:
        tasks = tasks.filter(status=status)
    if milestone is not None:
        tasks = tasks.filter(milestone=milestone)

    task_orders = {task.id: getattr(task, field) for task in tasks}
    new_task_orders = {e["task_id"]: e["order"] for e in bulk_data}
    apply_order_updates(task_orders, new_task_orders)

    task_ids = task_orders.keys()
    events.emit_event_for_ids(ids=task_ids,
                              content_type="tasks.task",
                              projectid=project.pk)

    db.update_attr_in_bulk_for_ids(task_orders, field, models.Task)
    return task_orders
def test_apply_order_updates_two_elements():
    orders = {
        "a": 0,
        "b": 1,
    }
    new_orders = {"b": 0}
    apply_order_updates(orders, new_orders)
    assert orders == {"b": 0, "a": 1}
Beispiel #12
0
def test_apply_order_not_include_noop():
    orders = {
        "a": 1,
    }
    new_orders = {
        "a": 1,
    }
    apply_order_updates(orders, new_orders, remove_equal_original=True)
    assert orders == {}
def test_apply_order_updates_two_elements():
    orders = {
        "a": 0,
        "b": 1,
    }
    new_orders = {
        "b": 0
    }
    apply_order_updates(orders, new_orders)
    assert orders == {
        "b": 0,
        "a": 1
    }
Beispiel #14
0
def test_apply_order_does_no_generate_holes():
    orders = {
        "a": 0,
        "b": 2,
        "c": 1,
        "z": 99,
    }
    new_orders = {
        "c": 1,
        "z": 99,
    }
    apply_order_updates(orders, new_orders, remove_equal_original=True)
    assert orders == {}
Beispiel #15
0
def test_apply_order_maintain_new_values():
    orders = {
        "a": 1,
        "b": 2,
        "c": 3,
        "d": 4,
        "e": 7,
        "f": 6,
        "g": 7,
    }
    new_orders = {
        "e": 7,
        "g": 8,
    }
    expected = {"g": 8}
    apply_order_updates(orders, new_orders, remove_equal_original=True)
    assert expected == orders
Beispiel #16
0
def test_apply_order_put_it_first():
    orders = {
        "a": 0,
        "b": 1,
        "c": 2,
        "z": 99,
    }
    new_orders = {
        "z": 0,
    }
    apply_order_updates(orders, new_orders, remove_equal_original=True)
    assert orders == {
        "z": 0,
        "a": 1,
        "b": 2,
        "c": 3,
    }
Beispiel #17
0
def test_apply_order_updates_one_element_backward():
    orders = {
        "a": 1,
        "b": 2,
        "c": 3,
        "d": 4,
        "e": 5,
        "f": 6
    }
    new_orders = {
        "d": 2
    }
    apply_order_updates(orders, new_orders)
    assert orders == {
        "d": 2,
        "b": 3,
        "c": 4
    }
Beispiel #18
0
def update_epics_order_in_bulk(bulk_data: list, field: str, project: object):
    """
    Update the order of some epics.
    `bulk_data` should be a list of tuples with the following format:

    [{'epic_id': <value>, 'order': <value>}, ...]
    """
    epics = project.epics.all()

    epic_orders = {e.id: getattr(e, field) for e in epics}
    new_epic_orders = {d["epic_id"]: d["order"] for d in bulk_data}
    apply_order_updates(epic_orders, new_epic_orders)

    epic_ids = epic_orders.keys()
    events.emit_event_for_ids(ids=epic_ids,
                              content_type="epics.epic",
                              projectid=project.pk)

    db.update_attr_in_bulk_for_ids(epic_orders, field, models.Epic)
    return epic_orders
Beispiel #19
0
def test_apply_order_updates_duplicated_orders():
    orders = {
        "a": 1,
        "b": 2,
        "c": 3,
        "d": 3,
        "e": 3,
        "f": 4
    }
    new_orders = {
        "a": 3
    }
    apply_order_updates(orders, new_orders)
    assert orders == {
        "a": 3,
        "c": 4,
        "d": 4,
        "e": 4,
        "f": 5
    }
Beispiel #20
0
def update_epics_order_in_bulk(bulk_data: list, field: str, project: object):
    """
    Update the order of some epics.
    `bulk_data` should be a list of tuples with the following format:

    [{'epic_id': <value>, 'order': <value>}, ...]
    """
    epics = project.epics.all()

    epic_orders = {e.id: getattr(e, field) for e in epics}
    new_epic_orders = {d["epic_id"]: d["order"] for d in bulk_data}
    apply_order_updates(epic_orders, new_epic_orders)

    epic_ids = epic_orders.keys()
    events.emit_event_for_ids(ids=epic_ids,
                              content_type="epics.epic",
                              projectid=project.pk)

    db.update_attr_in_bulk_for_ids(epic_orders, field, models.Epic)
    return epic_orders
Beispiel #21
0
def test_apply_order_refresh():
    orders = {
        "a": 0,
        "b": 0,
        "c": 0,
        "d": 1,
        "w": 99,
        "z": 0,
    }
    new_orders = {
        "z": 0,
    }
    apply_order_updates(orders, new_orders, remove_equal_original=True)
    assert orders == {
        "a": 1,
        "b": 1,
        "c": 1,
        "d": 2,
        "w": 100,
    }
Beispiel #22
0
def test_apply_order_updates_multiple_elements_forward():
    orders = {
        "a": 1,
        "b": 2,
        "c": 3,
        "d": 4,
        "e": 5,
        "f": 6
    }
    new_orders = {
        "a": 4,
        "b": 5
    }
    apply_order_updates(orders, new_orders)
    assert orders == {
        "a": 4,
        "b": 5,
        "d": 6,
        "e": 7,
        "f": 8
    }
Beispiel #23
0
def test_apply_order_updates_multiple_elements_duplicated_orders():
    orders = {
        "a": 1,
        "b": 2,
        "c": 3,
        "d": 3,
        "e": 3,
        "f": 4
    }
    new_orders = {
        "c": 3,
        "d": 3,
        "a": 4
    }
    apply_order_updates(orders, new_orders)
    assert orders == {
        "c": 3,
        "d": 3,
        "a": 4,
        "e": 5,
        "f": 6
    }
Beispiel #24
0
def test_apply_order_invalid_new_order():
    orders = {
        "a": 1,
        "b": 2,
        "c": 3,
        "d": 3,
        "e": 3,
        "f": 4
    }
    new_orders = {
        "c": 3,
        "d": 3,
        "x": 3,
        "a": 4
    }
    apply_order_updates(orders, new_orders)
    assert orders == {
        "c": 3,
        "d": 3,
        "a": 4,
        "e": 5,
        "f": 6
    }