def build_cycle(cycle, current_user=None, base_date=None): """Build a cycle with it's child objects""" if not base_date: base_date = date.today() # Determine the relevant Workflow workflow = cycle.workflow # Use WorkflowOwner role when this is called via the cron job. if not current_user: for user_role in workflow.context.user_roles: if user_role.role.name == "WorkflowOwner": current_user = user_role.person break # Populate the top-level Cycle object cycle.context = workflow.context cycle.title = workflow.title cycle.description = workflow.description cycle.status = 'Assigned' # Populate CycleTaskGroups based on Workflow's TaskGroups for task_group in workflow.task_groups: cycle_task_group = models.CycleTaskGroup( context=cycle.context, cycle=cycle, task_group=task_group, title=task_group.title, description=task_group.description, end_date=cycle.end_date, modified_by=current_user, contact=task_group.contact, status="Assigned", sort_index=task_group.sort_index, ) # preserve the old cycle creation for old workflows, so each object # gets its own cycle task if workflow.is_old_workflow: create_old_style_cycle(cycle, task_group, cycle_task_group, current_user, base_date) else: for task_group_task in task_group.task_group_tasks: cycle_task_group_object_task = _create_cycle_task( task_group_task, cycle, cycle_task_group, current_user, base_date) for task_group_object in task_group.task_group_objects: object_ = task_group_object.object db.session.add( Relationship(source=cycle_task_group_object_task, destination=object_)) update_cycle_dates(cycle) Signals.workflow_cycle_start.send(cycle.__class__, obj=cycle, new_status=cycle.status, old_status=None)
def build_cycle(workflow, cycle=None, current_user=None): """Build a cycle with it's child objects""" if not workflow.tasks: logger.error("Starting a cycle has failed on Workflow with " "slug == '%s' and id == '%s'", workflow.slug, workflow.id) pusher.update_or_create_notifications(workflow, date.today(), "cycle_start_failed") return # Determine the relevant Workflow cycle = cycle or models.Cycle() # Use Admin role when this is called via the cron job. if not current_user: current_user = workflow.get_persons_for_rolename("Admin")[0] # Populate the top-level Cycle object cycle.workflow = workflow cycle.is_current = True cycle.context = workflow.context cycle.title = workflow.title cycle.description = workflow.description cycle.is_verification_needed = workflow.is_verification_needed cycle.status = models.Cycle.ASSIGNED # Populate CycleTaskGroups based on Workflow's TaskGroups for task_group in workflow.task_groups: cycle_task_group = models.CycleTaskGroup( context=cycle.context, cycle=cycle, task_group=task_group, title=task_group.title, description=task_group.description, end_date=cycle.end_date, modified_by=current_user, contact=task_group.contact, status=models.CycleTaskGroup.ASSIGNED, sort_index=task_group.sort_index, ) # preserve the old cycle creation for old workflows, so each object # gets its own cycle task if workflow.is_old_workflow: create_old_style_cycle(cycle, task_group, cycle_task_group, current_user) else: for task_group_task in task_group.task_group_tasks: cycle_task_group_object_task = _create_cycle_task( task_group_task, cycle, cycle_task_group, current_user) for task_group_object in task_group.task_group_objects: object_ = task_group_object.object Relationship(source=cycle_task_group_object_task, destination=object_) update_cycle_dates(cycle) workflow.repeat_multiplier += 1 workflow.next_cycle_start_date = workflow.calc_next_adjusted_date( workflow.min_task_start_date) return cycle
def build_cycle(workflow, cycle=None, current_user=None): """Build a cycle with it's child objects""" build_failed = False if not workflow.tasks: logger.error("Starting a cycle has failed on Workflow with " "slug == '%s' and id == '%s', due to empty setup", workflow.slug, workflow.id) build_failed = True # Use Admin role when this is called via the cron job. if not current_user: admins = workflow.get_persons_for_rolename("Admin") if admins: current_user = admins[0] else: logger.error("Cannot start cycle on Workflow with slug == '%s' and " "id == '%s', cause it doesn't have Admins", workflow.slug, workflow.id) build_failed = True if build_failed: pusher.update_or_create_notifications(workflow, date.today(), "cycle_start_failed") return # Determine the relevant Workflow cycle = cycle or models.Cycle() # Populate the top-level Cycle object cycle.workflow = workflow cycle.is_current = True cycle.context = workflow.context cycle.title = workflow.title cycle.description = workflow.description cycle.is_verification_needed = workflow.is_verification_needed cycle.status = models.Cycle.ASSIGNED # Populate CycleTaskGroups based on Workflow's TaskGroups for task_group in workflow.task_groups: cycle_task_group = models.CycleTaskGroup( context=cycle.context, cycle=cycle, task_group=task_group, title=task_group.title, description=task_group.description, end_date=cycle.end_date, modified_by=current_user, contact=task_group.contact, status=models.CycleTaskGroup.ASSIGNED, ) # preserve the old cycle creation for old workflows, so each object # gets its own cycle task if workflow.is_old_workflow: create_old_style_cycle(cycle, task_group, cycle_task_group, current_user) else: for task_group_task in task_group.task_group_tasks: cycle_task_group_object_task = _create_cycle_task( task_group_task, cycle, cycle_task_group, current_user) related_objs = [obj for obj in task_group.related_objects() if not isinstance(obj, ( all_models.TaskGroupTask, all_models.Workflow ))] for obj in related_objs: Relationship(source=cycle_task_group_object_task, destination=obj) update_cycle_dates(cycle) workflow.repeat_multiplier += 1 workflow.next_cycle_start_date = workflow.calc_next_adjusted_date( workflow.min_task_start_date) return cycle