예제 #1
0
def _ensure_project(company: str, user: str, name: str) -> Optional[Project]:
    """
    Makes sure that the project with the given name exists
    If needed auto-create the project and all the missing projects in the path to it
    Return the project
    """
    name = name.strip(name_separator)
    if not name:
        return None

    project = _get_writable_project_from_name(company, name)
    if project:
        return project

    now = datetime.utcnow()
    name, location = _validate_project_name(name)
    project = Project(
        id=database.utils.id(),
        user=user,
        company=company,
        created=now,
        last_update=now,
        name=name,
        description="",
    )
    parent = _ensure_project(company, user, location)
    _save_under_parent(project=project, parent=parent)
    if parent:
        parent.update(last_update=now)

    return project
예제 #2
0
 def create(
     cls,
     user: str,
     company: str,
     name: str,
     description: str,
     tags: Sequence[str] = None,
     system_tags: Sequence[str] = None,
     default_output_destination: str = None,
 ) -> str:
     """
     Create a new project.
     Returns project ID
     """
     now = datetime.utcnow()
     project = Project(
         id=database.utils.id(),
         user=user,
         company=company,
         name=name,
         description=description,
         tags=tags,
         system_tags=system_tags,
         default_output_destination=default_output_destination,
         created=now,
         last_update=now,
     )
     project.save()
     return project.id
예제 #3
0
    def create(
        cls,
        user: str,
        company: str,
        name: str,
        description: str = "",
        tags: Sequence[str] = None,
        system_tags: Sequence[str] = None,
        default_output_destination: str = None,
        parent_creation_params: dict = None,
    ) -> str:
        """
        Create a new project.
        Returns project ID
        """
        if _get_project_depth(name) > max_depth:
            raise errors.bad_request.ProjectPathExceedsMax(max_depth=max_depth)

        name, location = _validate_project_name(name)
        now = datetime.utcnow()
        project = Project(
            id=database.utils.id(),
            user=user,
            company=company,
            name=name,
            description=description,
            tags=tags,
            system_tags=system_tags,
            default_output_destination=default_output_destination,
            created=now,
            last_update=now,
        )
        parent = _ensure_project(
            company=company,
            user=user,
            name=location,
            creation_params=parent_creation_params,
        )
        _save_under_parent(project=project, parent=parent)
        if parent:
            parent.update(last_update=now)

        return project.id