示例#1
0
def createTab(title, workspace, allow_renaming=False, name=None):

    if name is None or name.strip() == '':
        name = URLify(title)

    visible = False
    tabs = Tab.objects.filter(workspace=workspace, visible=True)
    if tabs.count() == 0:
        visible = True

    # It's always the last tab
    position = Tab.objects.filter(workspace=workspace).count()

    # Creating tab
    tab = Tab(name=name,
              title=title,
              visible=visible,
              position=position,
              workspace=workspace)
    if allow_renaming:
        save_alternative(Tab, 'name', tab)
    else:
        tab.save()

    return tab
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)
示例#3
0
def createEmptyWorkspace(title, user, allow_renaming=False, name=None):
    if name is None or name == '':
        name = URLify(title)

    workspace = Workspace(title=title, name=name, creator=user, wiringStatus=get_wiring_skeleton())
    if allow_renaming is True:
        save_alternative(Workspace, 'name', workspace)
    else:
        workspace.save()
    UserWorkspace.objects.create(user=user, workspace=workspace)

    # Tab creation
    createTab(_('Tab'), workspace)

    return workspace