当前位置: 首页>>代码示例>>Python>>正文


Python Node.load方法代码示例

本文整理汇总了Python中website.project.model.Node.load方法的典型用法代码示例。如果您正苦于以下问题:Python Node.load方法的具体用法?Python Node.load怎么用?Python Node.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在website.project.model.Node的用法示例。


在下文中一共展示了Node.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_target

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
 def get_target(self, node_id, target_id):
     node = Node.load(target_id)
     if node and node_id != target_id:
         raise ValueError('Cannot post comment to another node.')
     elif target_id == node_id:
         return Node.load(node_id)
     else:
         comment = Comment.load(target_id)
         if comment:
             return comment
         else:
             raise ValueError
开发者ID:mauromsl,项目名称:osf.io,代码行数:14,代码来源:serializers.py

示例2: update

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
    def update(self, instance, validated_data):
        view_only_link = instance['self']
        nodes = instance['data']
        user = self.context['request'].user
        new_nodes = validated_data['data']

        add, remove = self.get_nodes_to_add_remove(
            nodes=nodes,
            new_nodes=new_nodes
        )

        for node in remove:
            if not node.has_permission(user, 'admin'):
                raise PermissionDenied
            view_only_link.nodes.remove(node)
        view_only_link.save()

        nodes = [Node.load(node) for node in view_only_link.nodes]
        eligible_nodes = self.get_eligible_nodes(nodes)

        for node in add:
            if not node.has_permission(user, 'admin'):
                raise PermissionDenied
            if node not in eligible_nodes:
                raise NonDescendantNodeError(node_id=node._id)
            view_only_link.nodes.append(node)
        view_only_link.save()

        return self.make_instance_obj(view_only_link)
开发者ID:alexschiller,项目名称:osf.io,代码行数:31,代码来源:serializers.py

示例3: menbib_oauth_finish

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
def menbib_oauth_finish(**kwargs):
    user = get_current_user()
    if not user:
        raise HTTPError(http.FORBIDDEN)
    node = Node.load(session.data.get('menbib_auth_nid'))
    result = finish_auth()

    user.add_addon('menbib')
    user.save()
    user_settings = user.get_addon('menbib')
    user_settings.owner = user
    user_settings.access_token = result.access_token
    user_settings.refresh_token = result.refresh_token
    user_settings.token_type = result.token_type
    user_settings.expires_in = result.expires_in
    user_settings.save()

    flash('Successfully authorized Mendeley', 'success')

    if node:
        del session.data['menbib_auth_nid']
        if node.has_addon('menbib'):
            node_addon = node.get_addon('menbib')
            node_addon.set_user_auth(user_settings)
            node_addon.save()
        return redirect(node.web_url_for('node_setting'))

    return redirect(web_url_for('user_addons'))
开发者ID:retroam,项目名称:menbib,代码行数:30,代码来源:auth.py

示例4: get_paginated_response

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
    def get_paginated_response(self, data):
        """Add number of unread comments to links.meta when viewing list of comments filtered by
        a target node, file or wiki page."""
        response = super(CommentPagination, self).get_paginated_response(data)
        response_dict = response.data
        kwargs = self.request.parser_context['kwargs'].copy()

        if self.request.query_params.get('related_counts', False):
            target_id = self.request.query_params.get('filter[target]', None)
            node_id = kwargs.get('node_id', None)
            node = Node.load(node_id)
            user = self.request.user
            if target_id and not user.is_anonymous() and node.is_contributor(user):
                root_target = Guid.load(target_id)
                if root_target:
                    page = getattr(root_target.referent, 'root_target_page', None)
                    if page:
                        if not len(data):
                            unread = 0
                        else:
                            unread = Comment.find_n_unread(user=user, node=node, page=page, root_id=target_id)
                        if self.request.version < '2.1':
                            response_dict['links']['meta']['unread'] = unread
                        else:
                            response_dict['meta']['unread'] = unread
        return Response(response_dict)
开发者ID:alexschiller,项目名称:osf.io,代码行数:28,代码来源:pagination.py

示例5: update_file_guid_referent

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
def update_file_guid_referent(self, node, event_type, payload, user=None):
    if event_type == 'addon_file_moved' or event_type == 'addon_file_renamed':
        source = payload['source']
        destination = payload['destination']
        source_node = Node.load(source['node']['_id'])
        destination_node = node
        file_guids = FileNode.resolve_class(source['provider'], FileNode.ANY).get_file_guids(
            materialized_path=source['materialized'] if source['provider'] != 'osfstorage' else source['path'],
            provider=source['provider'],
            node=source_node)

        if event_type == 'addon_file_renamed' and source['provider'] in settings.ADDONS_BASED_ON_IDS:
            return
        if event_type == 'addon_file_moved' and (source['provider'] == destination['provider'] and
                                                 source['provider'] in settings.ADDONS_BASED_ON_IDS) and source_node == destination_node:
            return

        for guid in file_guids:
            obj = Guid.load(guid)
            if source_node != destination_node and Comment.find(Q('root_target', 'eq', guid)).count() != 0:
                update_comment_node(guid, source_node, destination_node)

            if source['provider'] != destination['provider'] or source['provider'] != 'osfstorage':
                old_file = FileNode.load(obj.referent._id)
                obj.referent = create_new_file(obj, source, destination, destination_node)
                obj.save()
                if old_file and not TrashedFileNode.load(old_file._id):
                    old_file.delete()
开发者ID:caspinelli,项目名称:osf.io,代码行数:30,代码来源:comment.py

示例6: get_node_title

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
 def get_node_title(self, obj):
     user = self.context['request'].user
     node_title = obj['node']['title']
     node = Node.load(obj['node']['_id'])
     if node.has_permission(user, osf_permissions.READ):
         return node_title
     return 'Private Component'
开发者ID:chrisseto,项目名称:osf.io,代码行数:9,代码来源:serializers.py

示例7: fix_wiki_titles

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
def fix_wiki_titles(wiki_pages):
    for i, wiki in enumerate(wiki_pages):
        old_name = wiki["page_name"]
        new_name = wiki["page_name"].replace("/", "")

        # update wiki page name
        db.nodewikipage.update({"_id": wiki["_id"]}, {"$set": {"page_name": new_name}})
        logger.info("Updated wiki {} title to {}".format(wiki["_id"], new_name))

        node = Node.load(wiki["node"])
        if not node:
            logger.info("Invalid node {} for wiki {}".format(node, wiki["_id"]))
            continue

        # update node wiki page records
        if old_name in node.wiki_pages_versions:
            node.wiki_pages_versions[new_name] = node.wiki_pages_versions[old_name]
            del node.wiki_pages_versions[old_name]

        if old_name in node.wiki_pages_current:
            node.wiki_pages_current[new_name] = node.wiki_pages_current[old_name]
            del node.wiki_pages_current[old_name]

        if old_name in node.wiki_private_uuids:
            node.wiki_private_uuids[new_name] = node.wiki_private_uuids[old_name]
            del node.wiki_private_uuids[old_name]
        node.save()
开发者ID:kch8qx,项目名称:osf.io,代码行数:29,代码来源:remove_wiki_title_forward_slashes.py

示例8: archive_success

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
def archive_success(dst_pk, job_pk):
    """Archiver's final callback. For the time being the use case for this task
    is to rewrite references to files selected in a registration schema (the Prereg
    Challenge being the first to expose this feature). The created references point
    to files on the registered_from Node (needed for previewing schema data), and
    must be re-associated with the corresponding files in the newly created registration.

    :param str dst_pk: primary key of registration Node

    note:: At first glance this task makes redundant calls to utils.get_file_map (which
    returns a generator yielding  (<sha256>, <file_metadata>) pairs) on the dst Node. Two
    notes about utils.get_file_map: 1) this function memoizes previous results to reduce
    overhead and 2) this function returns a generator that lazily fetches the file metadata
    of child Nodes (it is possible for a selected file to belong to a child Node) using a
    non-recursive DFS. Combined this allows for a relatively effient implementation with
    seemingly redundant calls.
    """
    create_app_context()
    dst = Node.load(dst_pk)
    # The filePicker extension addded with the Prereg Challenge registration schema
    # allows users to select files in OSFStorage as their response to some schema
    # questions. These files are references to files on the unregistered Node, and
    # consequently we must migrate those file paths after archiver has run. Using
    # sha256 hashes is a convenient way to identify files post-archival.
    for schema in dst.registered_schema:
        if schema.has_files:
            utils.migrate_file_metadata(dst, schema)
    job = ArchiveJob.load(job_pk)
    if not job.sent:
        job.sent = True
        job.save()
        dst.sanction.ask(dst.get_active_contributors_recursive(unique_users=True))
开发者ID:MattVitting,项目名称:osf.io,代码行数:34,代码来源:tasks.py

示例9: get_nodes_with_oauth_grants

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
 def get_nodes_with_oauth_grants(self, external_account):
     # Generator of nodes which have grants for this external account
     return (
         Node.load(node_id)
         for node_id, grants in self.oauth_grants.iteritems()
         if external_account._id in grants.keys()
     )
开发者ID:huangginny,项目名称:osf.io,代码行数:9,代码来源:__init__.py

示例10: dropbox_oauth_finish

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
def dropbox_oauth_finish(auth, **kwargs):
    """View called when the Oauth flow is completed. Adds a new DropboxUserSettings
    record to the user and saves the user's access token and account info.
    """
    if not auth.logged_in:
        raise HTTPError(http.FORBIDDEN)
    user = auth.user

    node = Node.load(session.data.get('dropbox_auth_nid'))
    result = finish_auth(node)
    # If result is a redirect response, follow the redirect
    if isinstance(result, BaseResponse):
        return result
    # Make sure user has dropbox enabled
    user.add_addon('dropbox')
    user.save()
    user_settings = user.get_addon('dropbox')
    user_settings.owner = user
    user_settings.access_token = result.access_token
    user_settings.dropbox_id = result.dropbox_id
    client = get_client_from_user_settings(user_settings)
    user_settings.dropbox_info = client.account_info()
    user_settings.save()

    if node:
        del session.data['dropbox_auth_nid']
        # Automatically use newly-created auth
        if node.has_addon('dropbox'):
            node_addon = node.get_addon('dropbox')
            node_addon.set_user_auth(user_settings)
            node_addon.save()
        return redirect(node.web_url_for('node_setting'))
    return redirect(web_url_for('user_addons'))
开发者ID:Alpani,项目名称:osf.io,代码行数:35,代码来源:auth.py

示例11: on_delete

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
 def on_delete(self):
     super(AddonOAuthUserSettingsBase, self).on_delete()
     nodes = [Node.load(node_id) for node_id in self.oauth_grants.keys()]
     for node in nodes:
         node_addon = node.get_addon(self.oauth_provider.short_name)
         if node_addon and node_addon.user_settings == self:
             node_addon.clear_auth()
开发者ID:lbanner,项目名称:osf.io,代码行数:9,代码来源:__init__.py

示例12: on_delete

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
 def on_delete(self):
     """When the user deactivates the addon, clear auth for connected nodes.
     """
     super(AddonOAuthUserSettingsBase, self).on_delete()
     nodes = [Node.load(node_id) for node_id in self.oauth_grants.keys()]
     for node in nodes:
         node_addon = node.get_addon(self.oauth_provider.short_name)
         if node_addon and node_addon.user_settings == self:
             node_addon.clear_auth()
开发者ID:cslzchen,项目名称:osf.io,代码行数:11,代码来源:__init__.py

示例13: box_oauth_finish

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
def box_oauth_finish(auth, **kwargs):
    """View called when the Oauth flow is completed. Adds a new BoxUserSettings
    record to the user and saves the user's access token and account info.
    """
    user = auth.user
    node = Node.load(session.data.pop('box_auth_nid', None))

    # Handle request cancellations from Box's API
    if request.args.get('error'):
        flash('Box authorization request cancelled.')
        if node:
            return redirect(node.web_url_for('node_setting'))
        return redirect(web_url_for('user_addons'))

    result = finish_auth()

    # If result is a redirect response, follow the redirect
    if isinstance(result, BaseResponse):
        return result

    client = BoxClient(CredentialsV2(
        result['access_token'],
        result['refresh_token'],
        settings.BOX_KEY,
        settings.BOX_SECRET,
    ))

    about = client.get_user_info()
    oauth_settings = BoxOAuthSettings.load(about['id'])

    if not oauth_settings:
        oauth_settings = BoxOAuthSettings(user_id=about['id'], username=about['name'])
        oauth_settings.save()

    oauth_settings.refresh_token = result['refresh_token']
    oauth_settings.access_token = result['access_token']
    oauth_settings.expires_at = datetime.utcfromtimestamp(time.time() + 3600)

    # Make sure user has box enabled
    user.add_addon('box')
    user.save()

    user_settings = user.get_addon('box')
    user_settings.oauth_settings = oauth_settings

    user_settings.save()

    flash('Successfully authorized Box', 'success')

    if node:
        # Automatically use newly-created auth
        if node.has_addon('box'):
            node_addon = node.get_addon('box')
            node_addon.set_user_auth(user_settings)
            node_addon.save()
        return redirect(node.web_url_for('node_setting'))
    return redirect(web_url_for('user_addons'))
开发者ID:GageGaskins,项目名称:osf.io,代码行数:59,代码来源:auth.py

示例14: _rejection_url_context

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
    def _rejection_url_context(self, user_id):
        user_approval_state = self.approval_state.get(user_id, {})
        rejection_token = self.approval_state.get(user_id, {}).get("rejection_token")
        if rejection_token:
            from website.project.model import Node

            root_registration = self._get_registration()
            node_id = user_approval_state.get("node_id", root_registration._id)
            registration = Node.load(node_id)
            return {"node_id": registration.registered_from._id, "token": rejection_token}
开发者ID:kch8qx,项目名称:osf.io,代码行数:12,代码来源:sanctions.py

示例15: find_registration_file

# 需要导入模块: from website.project.model import Node [as 别名]
# 或者: from website.project.model.Node import load [as 别名]
def find_registration_file(value, node):
    orig_sha256 = value['extra']['sha256']
    orig_name = value['extra']['selectedFileName']
    orig_node = value['extra']['nodeId']
    file_map = utils.get_file_map(node)
    for sha256, value, node_id in file_map:
        registered_from_id = Node.load(node_id).registered_from._id
        if sha256 == orig_sha256 and registered_from_id == orig_node and orig_name == value['name']:
            return value, node_id
    return None, None
开发者ID:DanielSBrown,项目名称:osf.io,代码行数:12,代码来源:tasks.py


注:本文中的website.project.model.Node.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。