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


Python UserData.from_json方法代码示例

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


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

示例1: get

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import from_json [as 别名]
    def get(self):
        if (
            not hasattr(secrets, "ka_api_consumer_key")
            or not hasattr(secrets, "ka_api_consumer_secret")
            or not hasattr(secrets_dev, "ka_api_token_key")
            or not hasattr(secrets_dev, "ka_api_token_secret")
        ):
            return self.redirect("/")

        self.setup_oauth()

        self.email = self.request_string("email")
        if not self.email:
            raise "Must supply email for user to import"

        params = copy.copy(self._default_kinds)
        params.update(self.request.params)

        # get proper user from addition 1 userexercise
        user_id_json = json.loads(self.api("/api/v1/user/exercises/addition_1"))
        user = users.User(user_id_json["user"])

        # UserData
        user_data_json_raw = self.api("/api/v1/user")
        user_data = UserData.from_json(json.loads(user_data_json_raw), user=user)
        self.output("user_data", user_data, user_data_json_raw)
        user_data.put()

        if "UserVideo" in params:
            user_videos_json = json.loads(self.api("/api/v1/user/videos"))
            user_videos = []
            for user_video_json in user_videos_json[: params["UserVideo"]]:
                user_video = UserVideo.from_json(user_video_json, user_data=user_data)
                user_videos.append(user_video)
                self.output("user_video", user_video, jsonify(user_video_json))

            video_logs = defaultdict(list)
            if "VideoLog" in params:
                for user_video in user_videos:
                    ytid = user_video.video.youtube_id
                    video_logs_json = json.loads(self.api("/api/v1/user/videos/%s/log" % ytid))
                    problem_log_limit = params["ProblemLog"]
                    for video_log_json in video_logs_json[:problem_log_limit]:
                        video_log = VideoLog.from_json(video_log_json, user_video.video, user)
                        video_logs[user_video].append(video_log)
                        self.output("video_log", video_log, jsonify(video_log_json))

                # delete old video logs
                query = VideoLog.all(keys_only=True)
                query.filter("user =", user)
                db.delete(query.fetch(10000))

            db.put(user_videos)
            for k, v in video_logs.iteritems():
                db.put(v)

        if "UserExercise" in params:
            user_exercises_json = json.loads(self.api("/api/v1/user/exercises"))
            user_exercises = []
            exercise_limit = params["UserExercise"]
            for user_exercise_json in user_exercises_json[:exercise_limit]:
                user_exercise = UserExercise.from_json(user_exercise_json, user_data)
                if user_exercise:
                    user_exercises.append(user_exercise)
                    self.output("user_exercise", user_exercise, jsonify(user_exercise_json))

            problem_logs = defaultdict(list)
            if "ProblemLog" in params:
                for user_exercise in user_exercises:
                    problem_logs_json = json.loads(self.api("/api/v1/user/exercises/%s/log" % user_exercise.exercise))
                    problem_log_limit = params["ProblemLog"]
                    problem_logs_json = problem_logs_json[:problem_log_limit]
                    for problem_log_json in problem_logs_json:
                        problem_log = ProblemLog.from_json(
                            problem_log_json, user_data=user_data, exercise=user_exercise.exercise_model
                        )
                        problem_logs[user_exercise].append(problem_log)
                        self.output("problem_log", problem_log, jsonify(problem_log_json))

            db.put(user_exercises)
            for k, v in problem_logs.iteritems():
                db.put(v)

        if "Goal" in params:
            with AutoNowDisabled(Goal):
                goals_json = json.loads(self.api("/api/v1/user/goals"))
                goals = []
                for goal_json in goals_json[: params["Goal"]]:
                    goal = Goal.from_json(goal_json, user_data=user_data)
                    goals.append(goal)
                    self.output("goal", goal, jsonify(goal_json))

                db.put(goals)

                # need to tell the userdata that it has goals
                user_data.has_current_goals = not all([g.completed for g in goals])
                user_data.put()
开发者ID:stefanojames,项目名称:KhanLatest,代码行数:99,代码来源:handlers.py


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