Exemplo n.º 1
0
def buildWorkspaceFromTemplate(template, user, allow_renaming=False, new_name=None, new_title=None, searchable=True, public=False):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise TypeError('Unsupported resource type: %s' % template.get_resource_type())

    if (new_name is None or new_name.strip() == '') and (new_title is None or new_title.strip() == ''):
        processed_info = template.get_resource_processed_info(process_urls=False)
        new_name = processed_info['name']
        new_title = processed_info['title']
    elif new_title is None or new_title.strip() == '':
        new_title = new_name
    elif new_name is None or new_name.strip() == '':
        new_name = URLify(new_title)

    # Workspace creation
    workspace = Workspace(title=new_title, name=new_name, creator=user, searchable=searchable, public=public)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user, workspace=workspace)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)
Exemplo n.º 2
0
def buildWorkspaceFromTemplate(template,
                               user,
                               allow_renaming=False,
                               new_name=None):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise TypeError('Unsupported resource type: %s' %
                        template.get_resource_type())

    if new_name is not None:
        name = new_name
    else:
        name = template.get_resource_processed_info(
            process_urls=False)['title']

    # Workspace creation
    workspace = Workspace(name=name, creator=user)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user,
                                   workspace=workspace,
                                   active=False)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)
Exemplo n.º 3
0
def buildWorkspaceFromTemplate(template, user, allow_renaming=False, new_name=None):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise Exception()

    if new_name is not None:
        name = new_name
    else:
        name = template.get_resource_name()

    # Workspace creation
    workspace = Workspace(name=name, creator=user)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user, workspace=workspace, active=False)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)
def buildWorkspaceFromTemplate(template, user, allow_renaming=False, new_name=None):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise TypeError('Unsupported resource type: %s' % template.get_resource_type())

    if new_name is not None:
        name = new_name
    else:
        name = template.get_resource_processed_info(process_urls=False)['title']

    # Workspace creation
    workspace = Workspace(name=name, creator=user)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user, workspace=workspace, active=False)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)
Exemplo n.º 5
0
def buildWorkspaceFromTemplate(template, user, allow_renaming=False, new_name=None, new_title=None, searchable=True, public=False):

    if not isinstance(template, TemplateParser):
        template = TemplateParser(template)

    if template.get_resource_type() != 'mashup':
        raise TypeError('Unsupported resource type: %s' % template.get_resource_type())

    if (new_name is None or new_name.strip() == '') and (new_title is None or new_title.strip() == ''):
        processed_info = template.get_resource_processed_info(process_urls=False)
        new_name = processed_info['name']
        new_title = processed_info['title']
    elif new_title is None or new_title.strip() == '':
        new_title = new_name
    elif new_name is None or new_name.strip() == '':
        new_name = URLify(new_title)

    # Workspace creation
    workspace = Workspace(title=new_title, name=new_name, creator=user, searchable=searchable, public=public)
    if allow_renaming:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()

    # Adding user reference to workspace in the many to many relationship
    user_workspace = UserWorkspace(user=user, workspace=workspace)
    user_workspace.save()

    fillWorkspaceUsingTemplate(workspace, template)

    return (workspace, user_workspace)