Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project_path() to return full, nested project paths #367

Open
alextanski opened this issue Jul 17, 2019 · 1 comment
Open

Add project_path() to return full, nested project paths #367

alextanski opened this issue Jul 17, 2019 · 1 comment
Milestone

Comments

@alextanski
Copy link

It would be handy to have a method that returns the current location of a dataset, showing its potentially nested project path. Here is a solution that I hacked together for this:

def project_path(dataset):
    """
    Return the (potentially) nested project path of the current dataset.
    """
    
    def _find_projects(project_id, folders):
        cat = session.get(project_id).payload.catalogs.project
        if cat.endswith('/projects/'):
            return folders
        else:
            pname = session.get(cat).payload.body.name
            folders = [pname] + folders
            return _find_projects(cat, folders)
    
    session = dataset.resource.session
    pr_id = dataset.resource.body.owner
    pr_name = dataset.resource.body.owner_name
    
    return '|'.join(_find_projects(pr_id, []) + [pr_name])

Example:

uid = '47e3e24ce2ba429fb92577be94a6b58f'

p = project_path(dataset)
p

would be: Germany|Custom Research|Vaillant Group

The above solution is missing a catch for the case of the Personal Project, but I reckon this should be easy to include.

@alextanski alextanski added this to the Wishlist milestone Jul 17, 2019
@alextanski
Copy link
Author

FWIW: The method could simply return Personal if pr_id.split('/')[-3] == 'users' for the Personal Project and step out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant