Exemple #1
0
def view_project(auth, node, **kwargs):
    primary = "/api/v1" not in request.path
    ret = _view_project(node, auth, primary=primary)
    ret["addon_capabilities"] = settings.ADDON_CAPABILITIES
    # Collect the URIs to the static assets for addons that have widgets
    ret["addon_widget_js"] = list(collect_addon_js(node, filename="widget-cfg.js", config_entry="widget"))
    ret.update(rubeus.collect_addon_assets(node))
    return ret
Exemple #2
0
def view_project(auth, node, **kwargs):
    primary = '/api/v1' not in request.path
    ret = _view_project(node, auth, primary=primary)
    ret['addon_capabilities'] = settings.ADDON_CAPABILITIES
    # Collect the URIs to the static assets for addons that have widgets
    ret['addon_widget_js'] = list(
        collect_addon_js(node, filename='widget-cfg.js',
                         config_entry='widget'))
    ret.update(rubeus.collect_addon_assets(node))
    return ret
Exemple #3
0
 def test_collect_js_unique(self):
     self.project.get_addons.return_value[0].config.include_js = {
         'files': ['foo.js']
     }
     node = NodeFactory(project=self.project)
     mock_node_addon = mock.Mock()
     mock_node_addon.config.include_js = {'files': ['foo.js', 'baz.js']}
     node.get_addons = mock.Mock()
     node.get_addons.return_value = [mock_node_addon]
     assert_equal(rubeus.collect_addon_js(self.project),
                  {'foo.js', 'baz.js'})
Exemple #4
0
 def test_collect_js_unique(self):
     self.project.get_addons.return_value[0].config.include_js = {'files': ['foo.js']}
     node = NodeFactory(project=self.project)
     mock_node_addon = mock.Mock()
     mock_node_addon.config.include_js = {'files': ['foo.js', 'baz.js']}
     node.get_addons = mock.Mock()
     node.get_addons.return_value = [mock_node_addon]
     assert_equal(
         rubeus.collect_addon_js(self.project),
         {'foo.js', 'baz.js'}
     )
Exemple #5
0
 def test_collect_js_unique(self):
     self.project.get_addons.return_value[0].config.include_js = {'files': ['foo.js']}
     self.project.get_addons.return_value[0].config.short_name = 'dropbox'
     node = NodeFactory(parent=self.project)
     mock_node_addon = mock.Mock()
     mock_node_addon.config.include_js = {'files': ['foo.js', 'baz.js']}
     mock_node_addon.config.short_name = 'dropbox'
     node.get_addons = mock.Mock()
     node.get_addons.return_value = [mock_node_addon]
     result = rubeus.collect_addon_js(self.project)
     assert_in('foo.js', result)
     assert_in('baz.js', result)
Exemple #6
0
 def test_collect_js_unique(self):
     self.project.get_addons.return_value[0].config.include_js = {'files': ['foo.js']}
     self.project.get_addons.return_value[0].config.short_name = 'dropbox'
     node = NodeFactory(parent=self.project)
     mock_node_addon = mock.Mock()
     mock_node_addon.config.include_js = {'files': ['foo.js', 'baz.js']}
     mock_node_addon.config.short_name = 'dropbox'
     node.get_addons = mock.Mock()
     node.get_addons.return_value = [mock_node_addon]
     result = rubeus.collect_addon_js(self.project)
     assert_in('foo.js', result)
     assert_in('baz.js', result)
Exemple #7
0
 def test_collect_js_unique(self):
     self.project.get_addons.return_value[0].config.include_js = {"files": ["foo.js"]}
     self.project.get_addons.return_value[0].config.short_name = "dropbox"
     node = NodeFactory(parent=self.project)
     mock_node_addon = mock.Mock()
     mock_node_addon.config.include_js = {"files": ["foo.js", "baz.js"]}
     mock_node_addon.config.short_name = "dropbox"
     node.get_addons = mock.Mock()
     node.get_addons.return_value = [mock_node_addon]
     result = rubeus.collect_addon_js(self.project)
     assert_in("foo.js", result)
     assert_in("baz.js", result)
Exemple #8
0
def view_project(**kwargs):
    auth = kwargs['auth']
    node = kwargs['node'] or kwargs['project']
    primary = '/api/v1' not in request.path
    ret = _view_project(node, auth, primary=primary)
    ret['addon_capabilities'] = settings.ADDON_CAPABILITIES
    # Collect the URIs to the static assets for addons that have widgets
    ret['addon_widget_js'] = list(collect_addon_js(
        node,
        filename='widget-cfg.js',
        config_entry='widget'
    ))
    ret.update(rubeus.collect_addon_assets(node))
    return ret
Exemple #9
0
def view_project(auth, node, **kwargs):
    primary = '/api/v1' not in request.path
    ret = _view_project(node,
                        auth,
                        primary=primary,
                        embed_contributors=True,
                        embed_descendants=True)

    ret['addon_capabilities'] = settings.ADDON_CAPABILITIES
    # Collect the URIs to the static assets for addons that have widgets
    ret['addon_widget_js'] = list(
        collect_addon_js(node, filename='widget-cfg.js',
                         config_entry='widget'))
    ret.update(rubeus.collect_addon_assets(node))

    access_request = node.requests.filter(creator=auth.user).exclude(
        machine_state='accepted')
    ret['user']['access_request_state'] = access_request.get(
    ).machine_state if access_request else None

    addons_widget_data = {
        'wiki': None,
        'mendeley': None,
        'zotero': None,
        'forward': None,
        'dataverse': None
    }

    if 'wiki' in ret['addons']:
        addons_widget_data['wiki'] = serialize_wiki_widget(node)

    if 'dataverse' in ret['addons']:
        addons_widget_data['dataverse'] = serialize_dataverse_widget(node)

    if 'forward' in ret['addons']:
        addons_widget_data['forward'] = serialize_forward_widget(node)

    if 'zotero' in ret['addons']:
        node_addon = node.get_addon('zotero')
        zotero_widget_data = ZoteroCitationsProvider().widget(node_addon)
        addons_widget_data['zotero'] = zotero_widget_data

    if 'mendeley' in ret['addons']:
        node_addon = node.get_addon('mendeley')
        mendeley_widget_data = MendeleyCitationsProvider().widget(node_addon)
        addons_widget_data['mendeley'] = mendeley_widget_data

    ret.update({'addons_widget_data': addons_widget_data})
    return ret
Exemple #10
0
def view_project(auth, node, **kwargs):
    primary = '/api/v1' not in request.path
    ret = _view_project(node, auth,
                        primary=primary,
                        embed_contributors=True,
                        embed_descendants=True
                        )

    ret['addon_capabilities'] = settings.ADDON_CAPABILITIES
    # Collect the URIs to the static assets for addons that have widgets
    ret['addon_widget_js'] = list(collect_addon_js(
        node,
        filename='widget-cfg.js',
        config_entry='widget'
    ))
    ret.update(rubeus.collect_addon_assets(node))

    access_request = node.requests.filter(creator=auth.user).exclude(machine_state='accepted')
    ret['user']['access_request_state'] = access_request.get().machine_state if access_request else None

    addons_widget_data = {
        'wiki': None,
        'mendeley': None,
        'zotero': None,
        'forward': None,
        'dataverse': None
    }

    if 'wiki' in ret['addons']:
        addons_widget_data['wiki'] = serialize_wiki_widget(node)

    if 'dataverse' in ret['addons']:
        addons_widget_data['dataverse'] = serialize_dataverse_widget(node)

    if 'forward' in ret['addons']:
        addons_widget_data['forward'] = serialize_forward_widget(node)

    if 'zotero' in ret['addons']:
        node_addon = node.get_addon('zotero')
        zotero_widget_data = ZoteroCitationsProvider().widget(node_addon)
        addons_widget_data['zotero'] = zotero_widget_data

    if 'mendeley' in ret['addons']:
        node_addon = node.get_addon('mendeley')
        mendeley_widget_data = MendeleyCitationsProvider().widget(node_addon)
        addons_widget_data['mendeley'] = mendeley_widget_data

    ret.update({'addons_widget_data': addons_widget_data})
    return ret
Exemple #11
0
def view_project(auth, node, **kwargs):
    primary = '/api/v1' not in request.path
    ret = _view_project(node, auth,
                        primary=primary,
                        embed_contributors=True,
                        embed_descendants=True
                        )

    ret['addon_capabilities'] = settings.ADDON_CAPABILITIES
    # Collect the URIs to the static assets for addons that have widgets
    ret['addon_widget_js'] = list(collect_addon_js(
        node,
        filename='widget-cfg.js',
        config_entry='widget'
    ))
    ret.update(rubeus.collect_addon_assets(node))
    return ret
Exemple #12
0
def view_project(auth, node, **kwargs):
    primary = '/api/v1' not in request.path
    ret = _view_project(node, auth,
                        primary=primary,
                        embed_contributors=True,
                        embed_descendants=True
                        )

    ret['addon_capabilities'] = settings.ADDON_CAPABILITIES
    # Collect the URIs to the static assets for addons that have widgets
    ret['addon_widget_js'] = list(collect_addon_js(
        node,
        filename='widget-cfg.js',
        config_entry='widget'
    ))
    ret.update(rubeus.collect_addon_assets(node))

    addons_widget_data = {
        'wiki': None,
        'mendeley': None,
        'zotero': None,
        'forward': None,
        'dataverse': None
    }

    if 'wiki' in ret['addons']:
        wiki = node.get_addon('wiki')
        wiki_page = node.get_wiki_page('home')

        # Show "Read more" link if there are multiple pages or has > 400 characters
        more = len(node.wiki_pages_current.keys()) >= 2
        MAX_DISPLAY_LENGTH = 400
        rendered_before_update = False
        if wiki_page and wiki_page.html(node):
            wiki_html = wiki_page.html(node)
            if len(wiki_html) > MAX_DISPLAY_LENGTH:
                wiki_html = BeautifulSoup(wiki_html[:MAX_DISPLAY_LENGTH] + '...', 'html.parser')
                more = True
            else:
                wiki_html = BeautifulSoup(wiki_html)
            rendered_before_update = wiki_page.rendered_before_update
        else:
            wiki_html = None

        wiki_widget_data = {
            'complete': True,
            'wiki_content': unicode(wiki_html) if wiki_html else None,
            'wiki_content_url': node.api_url_for('wiki_page_content', wname='home'),
            'rendered_before_update': rendered_before_update,
            'more': more,
            'include': False,
        }
        wiki_widget_data.update(wiki.config.to_json())
        addons_widget_data['wiki'] = wiki_widget_data

    if 'dataverse' in ret['addons']:
        node_addon = node.get_addon('dataverse')
        widget_url = node.api_url_for('dataverse_get_widget_contents')

        dataverse_widget_data = {
            'complete': node_addon.complete,
            'widget_url': widget_url,
        }
        dataverse_widget_data.update(node_addon.config.to_json())
        addons_widget_data['dataverse'] = dataverse_widget_data

    if 'forward' in ret['addons']:
        node_addon = node.get_addon('forward')
        forward_widget_data = serialize_settings(node_addon)
        forward_widget_data['complete'] = settings_complete(node_addon)
        forward_widget_data.update(node_addon.config.to_json())
        addons_widget_data['forward'] = forward_widget_data

    if 'zotero' in ret['addons']:
        node_addon = node.get_addon('zotero')
        zotero_widget_data = node_addon.config.to_json()
        zotero_widget_data.update({
            'complete': node_addon.complete,
            'list_id': node_addon.list_id,
        })
        addons_widget_data['zotero'] = zotero_widget_data

    if 'mendeley' in ret['addons']:
        node_addon = node.get_addon('mendeley')
        mendeley_widget_data = node_addon.config.to_json()
        mendeley_widget_data.update({
            'complete': node_addon.complete,
            'list_id': node_addon.list_id,
        })
        addons_widget_data['mendeley'] = mendeley_widget_data

    ret.update({'addons_widget_data': addons_widget_data})
    return ret