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


Python UserData.pre_phantom方法代码示例

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


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

示例1: test_url_segment_generation

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import pre_phantom [as 别名]
    def test_url_segment_generation(self):
        # Pre-phantom users can't have profile URL's
        prephantom = UserData.pre_phantom()
        self.assertTrue(self.from_url(self.to_url(prephantom)) is None)

        # Phantom users can't have profile URL's
        phantom = self.create_phantom()
        self.assertTrue(self.from_url(self.to_url(phantom)) is None)

        # Normal users are cool, though.
        bob = UserData.insert_for(
                "http://googleid.khanacademy.org/1234",
                "[email protected]")
        bob.put()
        self.assertEqual(
                self.from_url(self.to_url(bob)).user_id,
                bob.user_id)

        sally = UserData.insert_for(
                "http://facebookid.khanacademy.org/1234",
                "http://facebookid.khanacademy.org/1234")
        sally.put()
        self.assertEqual(
                self.from_url(self.to_url(sally)).user_id,
                sally.user_id)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:27,代码来源:user_models_test.py

示例2: get_user_scratchpads

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import pre_phantom [as 别名]
def get_user_scratchpads():
    if not gandalf.bridge.gandalf("scratchpads"):
        return api_forbidden_response(
            "Forbidden: You don't have permission to do this")

    user_data = (get_visible_user_data_from_request() or
                 UserData.pre_phantom())
    return list(scratchpad_models.Scratchpad
        .get_for_user_data(user_data)
        .run(batch_size=1000))
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:12,代码来源:handlers.py

示例3: get

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import pre_phantom [as 别名]
    def get(self, username=None, subpath=None):

        """Render a student profile.

        Keyword arguments:
        email_or_username -- matches the first grouping in /profile/(.+?)/(.*)
        subpath -- matches the second grouping, and is ignored server-side,
        but is used to route client-side

        """
        current_user_data = UserData.current() or UserData.pre_phantom()

        if current_user_data.is_pre_phantom and username is None:
            # Pre-phantom users don't have any profiles - just redirect them
            # to the homepage if they try to view their own.
            self.redirect(url_util.create_login_url(self.request.uri))
            return

        if not current_user_data.is_phantom and username == 'nouser':
            # If anybody has bookmarked, or gets redirected to, or otherwise
            # finds their way to /profile/nouser while they're logged in, just
            # redirect them to their actual profile.
            #
            # /profile/nouser is only sensible for phantom users and is never
            # used to look at another user's profile.
            self.redirect(current_user_data.profile_root)
            return

        if not username:
            user_data = current_user_data
        elif username == 'nouser' and current_user_data.is_phantom:
            user_data = current_user_data
        else:
            user_data = UserData.get_from_url_segment(username)
            if (user_models.UniqueUsername.is_valid_username(username)
                    and user_data
                    and user_data.username
                    and user_data.username != username):
                # The path segment is a username and resolved to the user,
                # but is not actually their canonical name. Redirect to the
                # canonical version.
                if subpath:
                    self.redirect("/profile/%s/%s" % (user_data.username,
                                                      subpath))
                else:
                    self.redirect("/profile/%s" % user_data.username)
                return

        profile = util_profile.UserProfile.from_user(user_data,
                current_user_data)

        if profile is None:
            self.render_jinja2_template('noprofile.html', {})
            return

        is_self = user_data.user_id == current_user_data.user_id
        show_intro = False
        show_discussion_intro = False

        if is_self:
            promo_record = promo_record_model.PromoRecord.get_for_values(
                    "New Profile Promo", user_data.user_id)

            if promo_record is None:
                # The user has never seen the new profile page! Show a tour.
                if subpath:
                    # But if they're not on the root profile page, force them.
                    self.redirect("/profile")
                    return

                show_intro = True
                promo_record_model.PromoRecord.record_promo(
                    "New Profile Promo", user_data.user_id, skip_check=True)
                # We also mark the "new discussion promo" as having been seen,
                # because it is a sub-set of the full tour, and new users don't
                # need to see it twice.
                promo_record_model.PromoRecord.record_promo(
                    "New Discussion Promo", user_data.user_id, skip_check=True)
            else:
                # The user has already seen the original profile page tour, but
                # not necessarily the "new discussion tab" tour.
                discussion_promo_record = (
                    promo_record_model.PromoRecord.get_for_values(
                        "New Discussion Promo", user_data.user_id))

                if discussion_promo_record is None:
                    # The user hasn't seen the new discussion promo.
                    show_discussion_intro = True
                    promo_record_model.PromoRecord.record_promo(
                        "New Discussion Promo", user_data.user_id,
                            skip_check=True)

        # This is the main capability bit - it indicates whether or not the
        # actor can view exercise, video, and goals data on the site for the
        # current profile.
        is_activity_visible = user_data.is_visible_to(current_user_data)

        # Resolve any other miscellaneous capabilities. This may need to be
        # changed if ACLing gets signicantly more complicated.
        if is_self:
#.........这里部分代码省略.........
开发者ID:PerceptumNL,项目名称:khan-multilingual,代码行数:103,代码来源:handlers.py

示例4: get

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import pre_phantom [as 别名]
    def get(self, email_or_username=None, subpath=None):

        """Render a student profile.

        Keyword arguments:
        email_or_username -- matches the first grouping in /profile/(.+?)/(.*)
        subpath -- matches the second grouping, and is ignored server-side,
        but is used to route client-side

        """
        current_user_data = UserData.current() or UserData.pre_phantom()

        if current_user_data.is_pre_phantom and email_or_username is None:
            # Pre-phantom users don't have any profiles - just redirect them
            # to the homepage if they try to view their own.
            self.redirect(util.create_login_url(self.request.uri))
            return

        if not email_or_username:
            user_data = current_user_data
        elif email_or_username == 'nouser' and current_user_data.is_phantom:
            user_data = current_user_data
        else:
            user_data = UserData.get_from_url_segment(email_or_username)
            if (user_models.UniqueUsername.is_valid_username(email_or_username)
                    and user_data
                    and user_data.username
                    and user_data.username != email_or_username):
                # The path segment is a username and resolved to the user,
                # but is not actually their canonical name. Redirect to the
                # canonical version.
                if subpath:
                    self.redirect("/profile/%s/%s" % (user_data.username,
                                                      subpath))
                else:
                    self.redirect("/profile/%s" % user_data.username)
                return


        profile = UserProfile.from_user(user_data, current_user_data)

        if profile is None:
            self.render_jinja2_template('noprofile.html', {})
            return

        is_self = user_data.user_id == current_user_data.user_id
        show_intro = False

        if is_self:
            promo_record = promo_record_model.PromoRecord.get_for_values(
                    "New Profile Promo", user_data.user_id)

            if promo_record is None:
                # The user has never seen the new profile page! Show a tour.
                if subpath:
                    # But if they're not on the root profile page, force them.
                    self.redirect("/profile")
                    return

                show_intro = True
                promo_record_model.PromoRecord.record_promo("New Profile Promo",
                                                user_data.user_id,
                                                skip_check=True)

        has_full_access = is_self or user_data.is_visible_to(current_user_data)
        tz_offset = self.request_int("tz_offset", default=0)

        template_values = {
            'show_intro': show_intro,
            'profile': profile,
            'tz_offset': tz_offset,
            'count_videos': setting_model.Setting.count_videos(),
            'count_exercises': exercise_models.Exercise.get_count(),
            'user_data_student': user_data if has_full_access else None,
            'profile_root': user_data.profile_root,
            "view": self.request_string("view", default=""),
        }
        self.render_jinja2_template('viewprofile.html', template_values)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:80,代码来源:util_profile.py


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