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 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
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
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
def update_issues_milestone_in_bulk(bulk_data: list, milestone: object): """ Update the milestone some issues adding `bulk_data` should be a list of dicts with the following format: [{'task_id': <value>}, ...] """ issue_milestones = {e["issue_id"]: milestone.id for e in bulk_data} issue_ids = issue_milestones.keys() events.emit_event_for_ids(ids=issue_ids, content_type="issues.issues", projectid=milestone.project.pk) db.update_attr_in_bulk_for_ids(issue_milestones, "milestone_id", model=models.Issue) return issue_milestones
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
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) us_instance_list = [] us_values = [] for us_id in user_story_ids: us = UserStory.objects.get(pk=us_id) us_instance_list.append(us) us_values.append({'milestone_id': milestone.id}) db.update_in_bulk(us_instance_list, us_values) db.update_attr_in_bulk_for_ids(us_orders, "sprint_order", 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
def update_issues_milestone_in_bulk(bulk_data: list, milestone: object): """ Update the milestone some issues adding `bulk_data` should be a list of dicts with the following format: [{'task_id': <value>}, ...] """ issue_milestones = {e["issue_id"]: milestone.id for e in bulk_data} issue_ids = issue_milestones.keys() events.emit_event_for_ids(ids=issue_ids, content_type="issues.issues", projectid=milestone.project.pk) issues_instance_list = [] issues_values = [] for issue_id in issue_ids: issue = Issue.objects.get(pk=issue_id) issues_instance_list.append(issue) issues_values.append({'milestone_id': milestone.id}) db.update_in_bulk(issues_instance_list, issues_values) return issue_milestones