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


Python utils.serialize_user函数代码示例

本文整理汇总了Python中website.profile.utils.serialize_user函数的典型用法代码示例。如果您正苦于以下问题:Python serialize_user函数的具体用法?Python serialize_user怎么用?Python serialize_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _profile_view

def _profile_view(profile, is_profile):
    # TODO: Fix circular import
    from website.addons.badges.util import get_sorted_user_badges

    if profile and profile.is_disabled:
        raise HTTPError(http.GONE)

    if 'badges' in settings.ADDONS_REQUESTED:
        badge_assertions = get_sorted_user_badges(profile),
        badges = _get_user_created_badges(profile)
    else:
        # NOTE: While badges, are unused, 'assertions' and 'badges' can be
        # empty lists.
        badge_assertions = []
        badges = []

    if profile:
        profile_user_data = profile_utils.serialize_user(profile, full=True)
        return {
            'profile': profile_user_data,
            'assertions': badge_assertions,
            'badges': badges,
            'user': {
                'is_profile': is_profile,
                'can_edit': None,  # necessary for rendering nodes
                'permissions': [],  # necessary for rendering nodes
            },
        }

    raise HTTPError(http.NOT_FOUND)
开发者ID:lbanner,项目名称:osf.io,代码行数:30,代码来源:views.py

示例2: serialize_draft_registration

def serialize_draft_registration(draft, auth=None):
    
    import sys
    sys.path.insert(0, submodule_path('utils.py'))
    from website.profile.utils import serialize_user  # noqa

    node = draft.branched_from
    
    return {
        'pk': draft._id,
        'branched_from': serialize_node(draft.branched_from, auth),
        'initiator': serialize_user(draft.initiator, full=True),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': str(draft.datetime_initiated),
        'updated': str(draft.datetime_updated),
        'flags': draft.flags,
        'requires_approval': draft.requires_approval,
        #'is_pending_approval': draft.is_pending_review,
        #'is_approved': draft.is_approved,
        'approval': serialize_draft_registration_approval(draft.approval)
        # 'urls': {
        #     'edit': node.web_url_for('edit_draft_registration_page', draft_id=draft._id),
        #     'before_register': node.api_url_for('project_before_register'),
        #     'register': node.api_url_for('register_draft_registration', draft_id=draft._id),
        #     'register_page': node.web_url_for('draft_before_register_page', draft_id=draft._id),
        #     'registrations': node.web_url_for('node_registrations')
        # }
    }
开发者ID:Ghalko,项目名称:COS-Admin-Interface,代码行数:29,代码来源:utils.py

示例3: _profile_view

def _profile_view(profile, is_profile=False, embed_nodes=False, include_node_counts=False):
    if profile and profile.is_disabled:
        raise HTTPError(http.GONE)
    # NOTE: While badges, are unused, 'assertions' and 'badges' can be
    # empty lists.
    badge_assertions = []
    badges = []

    if profile:
        profile_user_data = profile_utils.serialize_user(profile, full=True, is_profile=is_profile, include_node_counts=include_node_counts)
        ret = {
            'profile': profile_user_data,
            'assertions': badge_assertions,
            'badges': badges,
            'user': {
                '_id': profile._id,
                'is_profile': is_profile,
                'can_edit': None,  # necessary for rendering nodes
                'permissions': [],  # necessary for rendering nodes
            },
        }
        if embed_nodes:
            ret.update({
                'public_projects': get_public_projects(user=profile),
                'public_components': get_public_components(user=profile),
            })
        return ret
    raise HTTPError(http.NOT_FOUND)
开发者ID:adlius,项目名称:osf.io,代码行数:28,代码来源:views.py

示例4: serialize_draft_registration

def serialize_draft_registration(draft, auth=None):
    from website.profile.utils import serialize_user  # noqa
    from website.project.utils import serialize_node  # noqa

    node = draft.branched_from

    return {
        'pk': draft._id,
        'branched_from': serialize_node(node, auth),
        'initiator': serialize_user(draft.initiator, full=True),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': utils.iso8601format(draft.datetime_initiated),
        'updated': utils.iso8601format(draft.datetime_updated),
        'flags': draft.flags,
        'urls': {
            'edit': node.web_url_for('edit_draft_registration_page', draft_id=draft._id),
            'submit': node.api_url_for('submit_draft_for_review', draft_id=draft._id),
            'before_register': node.api_url_for('project_before_register'),
            'register': node.api_url_for('register_draft_registration', draft_id=draft._id),
            'register_page': node.web_url_for('draft_before_register_page', draft_id=draft._id),
            'registrations': node.web_url_for('node_registrations')
        },
        'requires_approval': draft.requires_approval,
        'is_pending_approval': draft.is_pending_review,
        'is_approved': draft.is_approved,
    }
开发者ID:Alpani,项目名称:osf.io,代码行数:27,代码来源:utils.py

示例5: test_serialize_user_full

 def test_serialize_user_full(self):
     user = UserFactory()
     ProjectFactory(creator=user, is_public=False)
     NodeFactory(creator=user)
     ProjectFactory(creator=user, is_public=True)
     CollectionFactory(creator=user)
     d = utils.serialize_user(user, full=True, include_node_counts=True)
     profile_image_url = filters.profile_image_url(settings.PROFILE_IMAGE_PROVIDER,
                                               user,
                                               use_ssl=True,
                                               size=settings.PROFILE_IMAGE_LARGE)
     assert_equal(d['id'], user._primary_key)
     assert_equal(d['url'], user.url)
     assert_equal(d.get('username'), None)
     assert_equal(d['fullname'], user.fullname)
     assert_equal(d['registered'], user.is_registered)
     assert_equal(d['profile_image_url'], profile_image_url)
     assert_equal(d['absolute_url'], user.absolute_url)
     assert_equal(d['date_registered'], user.date_registered.strftime('%Y-%m-%d'))
     projects = [
         node
         for node in user.contributed
         if node.category == 'project'
         and not node.is_registration
         and not node.is_deleted
     ]
     public_projects = [p for p in projects if p.is_public]
     assert_equal(d['number_projects'], len(projects))
     assert_equal(d['number_public_projects'], len(public_projects))
开发者ID:leb2dg,项目名称:osf.io,代码行数:29,代码来源:test_serializers.py

示例6: _profile_view

def _profile_view(profile, is_profile=False):
    # TODO: Fix circular import
    from website.addons.badges.util import get_sorted_user_badges

    if profile and profile.is_disabled:
        raise HTTPError(http.GONE)

    if "badges" in settings.ADDONS_REQUESTED:
        badge_assertions = (get_sorted_user_badges(profile),)
        badges = _get_user_created_badges(profile)
    else:
        # NOTE: While badges, are unused, 'assertions' and 'badges' can be
        # empty lists.
        badge_assertions = []
        badges = []

    if profile:
        profile_user_data = profile_utils.serialize_user(profile, full=True, is_profile=is_profile)
        return {
            "profile": profile_user_data,
            "assertions": badge_assertions,
            "badges": badges,
            "user": {
                "is_profile": is_profile,
                "can_edit": None,  # necessary for rendering nodes
                "permissions": [],  # necessary for rendering nodes
            },
        }

    raise HTTPError(http.NOT_FOUND)
开发者ID:cwisecarver,项目名称:osf.io,代码行数:30,代码来源:views.py

示例7: serialize_draft_registration

def serialize_draft_registration(draft, auth=None):
    
    import sys
    sys.path.insert(0, submodule_path('utils.py'))
    from website.profile.utils import serialize_user  # noqa
    #import ipdb; ipdb.set_trace()
    node = draft.branched_from
    
    return {
        'pk': draft._id,
        'branched_from': serialize_node(draft.branched_from, auth),
        'initiator': serialize_user(draft.initiator, full=True),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': str(draft.datetime_initiated),
        'updated': str(draft.datetime_updated),
        'config': draft.config or {},
        'flags': draft.flags,
        # 'urls': {
        #     'edit': node.web_url_for('edit_draft_registration_page', draft_id=draft._id),
        #     'before_register': node.api_url_for('project_before_register'),
        #     'register': node.api_url_for('register_draft_registration', draft_id=draft._id),
        #     'register_page': node.web_url_for('draft_before_register_page', draft_id=draft._id),
        #     'registrations': node.web_url_for('node_registrations')
        # }
    }
开发者ID:samchrisinger,项目名称:COS-Admin-Interface,代码行数:26,代码来源:utils.py

示例8: test_serialize_user_merged

 def test_serialize_user_merged(self):
     master = UserFactory()
     user = UserFactory()
     master.merge_user(user)
     d = utils.serialize_user(user, full=True)
     assert_true(d['is_merged'])
     assert_equal(d['merged_by']['url'], user.merged_by.url)
     assert_equal(d['merged_by']['absolute_url'], user.merged_by.absolute_url)
开发者ID:leb2dg,项目名称:osf.io,代码行数:8,代码来源:test_serializers.py

示例9: test_serialize_user_full_includes_email_if_is_profile

 def test_serialize_user_full_includes_email_if_is_profile(self):
     serialized = utils.serialize_user(
         self.project.creator,
         self.project,
         full=True,
         is_profile=True
     )
     assert_in('emails', serialized)
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:8,代码来源:test_contributors_views.py

示例10: claim_user_registered

def claim_user_registered(auth, node, **kwargs):
    """View that prompts user to enter their password in order to claim
    contributorship on a project.

    A user must be logged in.
    """
    current_user = auth.user

    sign_out_url = web_url_for('auth_login', logout=True, next=request.url)
    if not current_user:
        return redirect(sign_out_url)
    # Logged in user should not be a contributor the project
    if node.is_contributor(current_user):
        logout_url = web_url_for('auth_logout', redirect_url=request.url)
        data = {
            'message_short': 'Already a contributor',
            'message_long': ('The logged-in user is already a contributor to this '
                'project. Would you like to <a href="{}">log out</a>?').format(logout_url)
        }
        raise HTTPError(http.BAD_REQUEST, data=data)
    uid, pid, token = kwargs['uid'], kwargs['pid'], kwargs['token']
    unreg_user = User.load(uid)
    if not verify_claim_token(unreg_user, token, pid=node._primary_key):
        raise HTTPError(http.BAD_REQUEST)

    # Store the unreg_user data on the session in case the user registers
    # a new account
    session.data['unreg_user'] = {
        'uid': uid, 'pid': pid, 'token': token
    }

    form = PasswordForm(request.form)
    if request.method == 'POST':
        if form.validate():
            if current_user.check_password(form.password.data):
                node.replace_contributor(old=unreg_user, new=current_user)
                node.save()
                status.push_status_message(
                    'You are now a contributor to this project.',
                    kind='success',
                    trust=False
                )
                return redirect(node.url)
            else:
                status.push_status_message(language.LOGIN_FAILED, kind='warning', trust=False)
        else:
            forms.push_errors_to_status(form.errors)
    if is_json_request():
        form_ret = forms.utils.jsonify(form)
        user_ret = profile_utils.serialize_user(current_user, full=False)
    else:
        form_ret = form
        user_ret = current_user
    return {
        'form': form_ret,
        'user': user_ret,
        'signOutUrl': sign_out_url
    }
开发者ID:fredtoh,项目名称:osf.io,代码行数:58,代码来源:contributor.py

示例11: claim_user_registered

def claim_user_registered(auth, node, **kwargs):
    """
    View that prompts user to enter their password in order to claim being a contributor on a project.
    A user must be logged in.
    """

    current_user = auth.user

    sign_out_url = web_url_for("auth_register", logout=True, next=request.url)
    if not current_user:
        return redirect(sign_out_url)

    # Logged in user should not be a contributor the project
    if node.is_contributor(current_user):
        logout_url = web_url_for("auth_logout", redirect_url=request.url)
        data = {
            "message_short": "Already a contributor",
            "message_long": (
                "The logged-in user is already a contributor to this "
                'project. Would you like to <a href="{}">log out</a>?'
            ).format(logout_url),
        }
        raise HTTPError(http.BAD_REQUEST, data=data)

    uid, pid, token = kwargs["uid"], kwargs["pid"], kwargs["token"]
    unreg_user = User.load(uid)
    if not verify_claim_token(unreg_user, token, pid=node._primary_key):
        error_data = {
            "message_short": "Invalid url.",
            "message_long": "The token in the URL is invalid or has expired.",
        }
        raise HTTPError(http.BAD_REQUEST, data=error_data)

    # Store the unreg_user data on the session in case the user registers
    # a new account
    session.data["unreg_user"] = {"uid": uid, "pid": pid, "token": token}

    form = PasswordForm(request.form)
    if request.method == "POST":
        if form.validate():
            if current_user.check_password(form.password.data):
                node.replace_contributor(old=unreg_user, new=current_user)
                node.save()
                status.push_status_message("You are now a contributor to this project.", kind="success", trust=False)
                return redirect(node.url)
            else:
                status.push_status_message(language.LOGIN_FAILED, kind="warning", trust=False)
        else:
            forms.push_errors_to_status(form.errors)
    if is_json_request():
        form_ret = forms.utils.jsonify(form)
        user_ret = profile_utils.serialize_user(current_user, full=False)
    else:
        form_ret = form
        user_ret = current_user
    return {"form": form_ret, "user": user_ret, "signOutUrl": sign_out_url}
开发者ID:cslzchen,项目名称:osf.io,代码行数:56,代码来源:contributor.py

示例12: test_serialize_user

 def test_serialize_user(self):
     master = UserFactory()
     user = UserFactory()
     master.merge_user(user)
     d = utils.serialize_user(user)
     assert_equal(d['id'], user._primary_key)
     assert_equal(d['url'], user.url)
     assert_equal(d.get('username', None), None)
     assert_equal(d['fullname'], user.fullname)
     assert_equal(d['registered'], user.is_registered)
     assert_equal(d['absolute_url'], user.absolute_url)
     assert_equal(d['date_registered'], user.date_registered.strftime('%Y-%m-%d'))
     assert_equal(d['active'], user.is_active)
开发者ID:leb2dg,项目名称:osf.io,代码行数:13,代码来源:test_serializers.py

示例13: test_serialize_access_requests

    def test_serialize_access_requests(self):
        new_user = AuthUserFactory()
        node_request = NodeRequestFactory(
            creator=new_user,
            target=self.project,
            request_type=workflows.RequestTypes.ACCESS.value,
            machine_state=workflows.DefaultStates.INITIAL.value
        )
        node_request.run_submit(new_user)
        res = utils.serialize_access_requests(self.project)

        assert len(res) == 1
        assert res[0]['comment'] == node_request.comment
        assert res[0]['id'] == node_request._id
        assert res[0]['user'] == utils.serialize_user(new_user)
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:15,代码来源:test_contributors_views.py

示例14: _profile_view

def _profile_view(profile, is_profile=False, include_node_counts=False):
    if profile and profile.is_disabled:
        raise HTTPError(http.GONE)

    if profile:
        profile_quickfilesnode = QuickFilesNode.objects.get_for_user(profile)
        profile_user_data = profile_utils.serialize_user(profile, full=True, is_profile=is_profile, include_node_counts=include_node_counts)
        ret = {
            'profile': profile_user_data,
            'user': {
                '_id': profile._id,
                'is_profile': is_profile,
                'can_edit': None,  # necessary for rendering nodes
                'permissions': [],  # necessary for rendering nodes
                'has_quickfiles': profile_quickfilesnode.files.filter(type='osf.osfstoragefile').exists()
            },
        }
        return ret
    raise HTTPError(http.NOT_FOUND)
开发者ID:mfraezz,项目名称:osf.io,代码行数:19,代码来源:views.py

示例15: test_serialize_user_full_does_not_include_emails_by_default

 def test_serialize_user_full_does_not_include_emails_by_default(self):
     serialized = utils.serialize_user(self.project.creator, self.project, full=True)
     assert_not_in('emails', serialized)
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:3,代码来源:test_contributors_views.py


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