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


Python UserData.pre_phantom方法代码示例

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


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

示例1: get

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import pre_phantom [as 别名]
    def get(self):
        student = UserData.current() or UserData.pre_phantom()

        user_override = self.request_student_user_data(legacy=True)
        if user_override and user_override.key_email != student.key_email:
            if not user_override.is_visible_to(student):
                # If current user isn't an admin or student's coach, they can't
                # look at anything other than their own profile.
                self.redirect("/profile")
                return
            else:
                # Allow access to this student's profile
                student = user_override
        user_badges = util_badges.get_user_badges(student)
        selected_graph_type = (self.request_string("selected_graph_type") or
                               ActivityGraph.GRAPH_TYPE)

        # TODO: deal with this one-off hackery. Some graphs use the API
        # to fetch data, instead of the /profile/graph methods.
        if selected_graph_type == "exerciseprogress":
            initial_graph_url = ("/api/v1/user/exercises?email=%s" %
                                 urllib.quote(student.email))
        elif selected_graph_type == "goals":
            initial_graph_url = ("/api/v1/user/goals?email=%s" %
                                 urllib.quote(student.email))
        else:
            initial_graph_url = "/profile/graph/%s?student_email=%s&%s" % (
                    selected_graph_type,
                    urllib.quote(student.email),
                    urllib.unquote(self.request_string("graph_query_params",
                                                       default="")))
        tz_offset = self.request_int("tz_offset", default=0)

        template_values = {
            'student_email': student.email,
            'student_nickname': student.nickname,
            'selected_graph_type': selected_graph_type,
            'initial_graph_url': initial_graph_url,
            'tz_offset': tz_offset,
            'student_points': student.points,
            'count_videos': models.Setting.count_videos(),
            'count_videos_completed': student.get_videos_completed(),
            'count_exercises': models.Exercise.get_count(),
            'count_exercises_proficient': len(student.all_proficient_exercises),
            'badge_collections': user_badges['badge_collections'],
            'user_badges_bronze': user_badges['bronze_badges'],
            'user_badges_silver': user_badges['silver_badges'],
            'user_badges_gold': user_badges['gold_badges'],
            'user_badges_platinum': user_badges['platinum_badges'],
            'user_badges_diamond': user_badges['diamond_badges'],
            'user_badges_master': user_badges['user_badges_master'],
            'user_badges': [user_badges['bronze_badges'], user_badges['silver_badges'], user_badges['gold_badges'], user_badges['platinum_badges'], user_badges['diamond_badges'],user_badges['user_badges_master']],
            'user_data_student': student,
            "show_badge_frequencies": self.request_bool("show_badge_frequencies", default=False),
            "view": self.request_string("view", default=""),
        }

        self.render_jinja2_template('viewprofile.html', template_values)
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:60,代码来源:util_profile.py

示例2: get

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import pre_phantom [as 别名]
    def get(self):
        student = UserData.current() or UserData.pre_phantom()

        user_override = self.request_user_data("student_email")
        if user_override and user_override.key_email != student.key_email:
            if not user_override.is_visible_to(student):
                # If current user isn't an admin or student's coach, they can't look at anything other than their own profile.
                self.redirect("/profile?k")
                return
            else:
                # Allow access to this student's profile
                student = user_override
        user_badges = util_badges.get_user_badges(student)
        selected_graph_type = self.request_string("selected_graph_type") or ActivityGraph.GRAPH_TYPE
        initial_graph_url = "/profile/graph/%s?student_email=%s&%s" % (
            selected_graph_type,
            urllib.quote(student.email),
            urllib.unquote(self.request_string("graph_query_params", default="")),
        )
        tz_offset = self.request_int("tz_offset", default=0)

        template_values = {
            "student_nickname": student.nickname,
            "selected_graph_type": selected_graph_type,
            "initial_graph_url": initial_graph_url,
            "tz_offset": tz_offset,
            "student_points": student.points,
            "count_videos": models.Setting.count_videos(),
            "count_videos_completed": student.get_videos_completed(),
            "count_exercises": models.Exercise.get_count(),
            "count_exercises_proficient": len(student.all_proficient_exercises),
            "badge_collections": user_badges["badge_collections"],
            "user_badges_bronze": user_badges["bronze_badges"],
            "user_badges_silver": user_badges["silver_badges"],
            "user_badges_gold": user_badges["gold_badges"],
            "user_badges_platinum": user_badges["platinum_badges"],
            "user_badges_diamond": user_badges["diamond_badges"],
            "user_badges_master": user_badges["user_badges_master"],
            "user_badges": [
                user_badges["bronze_badges"],
                user_badges["silver_badges"],
                user_badges["gold_badges"],
                user_badges["platinum_badges"],
                user_badges["diamond_badges"],
                user_badges["user_badges_master"],
            ],
            "user_data_student": student,
            "show_badge_frequencies": self.request_bool("show_badge_frequencies", default=False),
            "view": self.request_string("view", default=""),
        }

        self.render_jinja2_template("viewprofile.html", template_values)
开发者ID:avh4,项目名称:khan-academy,代码行数:54,代码来源:util_profile.py

示例3: get_profile_target_user_data

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import pre_phantom [as 别名]
    def get_profile_target_user_data(self):
        student = UserData.current() or UserData.pre_phantom()

        if student:
            user_override = self.request_user_data("student_email")
            if user_override and user_override.key_email != student.key_email:
                if not user_override.is_visible_to(student):
                    # If current user isn't an admin or student's coach, they can't look at anything other than their own profile.
                    student = None
                else:
                    # Allow access to this student's profile
                    student = user_override

        return student
开发者ID:avh4,项目名称:khan-academy,代码行数:16,代码来源:util_profile.py

示例4: get

# 需要导入模块: from models import UserData [as 别名]
# 或者: from 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 (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:
            bingo([
                'suggested_activity_visit_profile',
            ])

            promo_record = models.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
                models.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': models.Setting.count_videos(),
            'count_exercises': 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:johnfelipe,项目名称:server,代码行数:83,代码来源:util_profile.py


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