Exemplo n.º 1
0
def duplicate_project(project, new_title, duplicate_tasks, owner=None):
    """ Duplicate (clone) project with new title and old tasks if need
    """
    # remember source project
    project_src = Project.objects.get(pk=project.pk)

    # duplicate project and add active connection
    old_pk = project.pk
    project.pk = None
    project.title = new_title
    project.is_published = False
    project.model_version = ''
    project.created_by = owner if owner is not None else project.created_by
    project.token = create_hash()
    project.save()

    # duplicate onboarding
    for step in ProjectOnboardingSteps.objects.all():
        project.onboarding_step_finished(step.code)

    # duplicate tasks
    if duplicate_tasks:
        tasks = Task.objects.filter(project__pk=old_pk)
        for task in tasks:
            task.project = project
            task.pk = None
            task.reset_updates()
        Task.objects.bulk_create(tasks)

    logger.info(f'Project "{project_src.title}" with owner = {project_src.created_by} duplicated to '
                f'"{new_title}" with duplicate tasks = {duplicate_tasks}, '
                f'and new owner = {owner}')
    return project
Exemplo n.º 2
0
 def reset_token(self):
     self.token = create_hash()
     self.save()