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


Python UserData.current方法代码示例

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


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

示例1: get

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

        user_override = self.request_user_data("coach_email")
        if user_override and user_override.are_students_visible_to(coach):
            # Only allow looking at a student list other than your own
            # if you are a dev, admin, or coworker.
            coach = user_override

        student_lists = StudentList.get_for_coach(coach.key())

        student_lists_list = [{
            'key': 'allstudents',
            'name': 'All students',
        }];
        for student_list in student_lists:
            student_lists_list.append({
                'key': str(student_list.key()),
                'name': student_list.name,
            })

        list_id, _ = get_last_student_list(self, student_lists, coach==UserData.current())
        current_list = None
        for student_list in student_lists_list:
            if student_list['key'] == list_id:
                current_list = student_list

        selected_graph_type = self.request_string("selected_graph_type") or ClassProgressReportGraph.GRAPH_TYPE
        if selected_graph_type == 'progressreport' or selected_graph_type == 'goals': # TomY This is temporary until all the graphs are API calls
            initial_graph_url = "/api/v1/user/students/%s?coach_email=%s&%s" % (selected_graph_type, urllib.quote(coach.email), urllib.unquote(self.request_string("graph_query_params", default="")))
        else:
            initial_graph_url = "/profile/graph/%s?coach_email=%s&%s" % (selected_graph_type, urllib.quote(coach.email), urllib.unquote(self.request_string("graph_query_params", default="")))
        initial_graph_url += 'list_id=%s' % list_id

        template_values = {
                'user_data_coach': coach,
                'coach_email': coach.email,
                'list_id': list_id,
                'student_list': current_list,
                'student_lists': student_lists_list,
                'student_lists_json': json.dumps(student_lists_list),
                'coach_nickname': coach.nickname,
                'selected_graph_type': selected_graph_type,
                'initial_graph_url': initial_graph_url,
                'exercises': exercise_models.Exercise.get_all_use_cache(),
                'is_profile_empty': not coach.has_students(),
                'selected_nav_link': 'coach',
                "view": self.request_string("view", default=""),
                'stats_charts_class': 'coach-view',
                }
        self.render_jinja2_template('viewclassprofile.html', template_values)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:53,代码来源:util_profile.py

示例2: test_request_video

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
 def test_request_video(self):
     exs = exercise_models.Exercise.all().fetch(1000)
     user = UserData.current()
     self.assertFalse(exs[0].video_requested)
     exs[0].request_video()
     self.assertTrue(exs[0].video_requested)
     self.assertEqual(exs[0].video_requests_count, 1)
开发者ID:PaulWagener,项目名称:KhanLatest,代码行数:9,代码来源:exercise_models_test.py

示例3: delete_scratchpad

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
def delete_scratchpad(scratchpad_id):
    """Mark a pre-existing Scratchpad as deleted.

    An empty request body is expected."""

    if not gandalf.bridge.gandalf("scratchpads"):
        return api_forbidden_response(
            "Forbidden: You don't have permission to do this")

    user = UserData.current()
    scratchpad = scratchpad_models.Scratchpad.get_by_id(scratchpad_id)

    if not scratchpad or scratchpad.deleted:
        return api_not_found_response(
            "No scratchpad with id %s" % scratchpad_id)

    # Users can only delete scratchpad they created
    # EXCEPTION: Developres can delete any scratchpad
    if not user.developer and scratchpad.user_id != user.user_id:
        return api_forbidden_response(
            "Forbidden: Scratchpad owned by different user")

    scratchpad.deleted = True
    scratchpad.put()

    return api_success_no_content_response()
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:28,代码来源:handlers.py

示例4: create_scratchpad

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
def create_scratchpad():
    """Create a new Scratchpad and associated ScratchpadRevision.

    The POST data should be a JSON-encoded dict, which is passed verbatim to
    Scratchpad.create as keyword arguments.
    """
    if not gandalf.bridge.gandalf("scratchpads"):
        return api_forbidden_response(
            "Forbidden: You don't have permission to do this")

    if not request.json:
        return api_invalid_param_response("Bad data supplied: Not JSON")

    # TODO(jlfwong): Support phantom users
    user = UserData.current()

    if not (user and user.developer):
        # Certain fields are only modifiable by developers
        for field in scratchpad_models.Scratchpad._developer_only_fields:
            if request.json.get(field):
                return api_forbidden_response(
                    "Forbidden: Only developers can change the %s" % field)

    try:
        # Convert unicode encoded JSON keys to strings
        create_args = dict_keys_to_strings(request.json)
        if user:
            create_args['user_id'] = user.user_id
        return scratchpad_models.Scratchpad.create(**create_args)
    except (db.BadValueError, db.BadKeyError), e:
        return api_invalid_param_response("Bad data supplied: " + e.message)
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:33,代码来源:handlers.py

示例5: post

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
    def post(self):
        template_values = {}
        user_data = UserData.current()

        status_file = StringIO.StringIO(self.request_string('status_file'))
        reader = csv.reader(status_file)
        student_list = []
        for line in reader:
            student_email = line[0]
            student_status = line[1]
            student_comment = line[2]

            student = SummerStudent.all().filter('email =', student_email).get()
            if student is None:
                logging.error("Student %s not found" % student_email)
                continue

            student.application_status = student_status
            student.comment = student_comment
            if student_status == "Accepted":
                student.accepted = True

            student_list.append(student)

        db.put(student_list)

        self.response.out.write("OK")
        self.response.set_status(200)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:30,代码来源:__init__.py

示例6: post

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
    def post(self):
        user_data = UserData.current()
        if not user_data:
            return

        if user_data.is_child_account():
            self.render_json({"error": "Je kan nog niet stemmen."})
            return

        vote_type = self.request_int(
            "vote_type", default=discussion_models.FeedbackVote.ABSTAIN)

        if (vote_type == discussion_models.FeedbackVote.UP and
            not Privileges.can_up_vote(user_data)):
            self.render_json({
                "error": Privileges.need_points_desc(
                    Privileges.UP_VOTE_THRESHOLD, "up vote")
            })
            return
        elif (vote_type == discussion_models.FeedbackVote.DOWN and
              not Privileges.can_down_vote(user_data)):
            self.render_json({
                "error": Privileges.need_points_desc(
                    Privileges.DOWN_VOTE_THRESHOLD, "down vote")
            })
            return

        entity_key = self.request_string("entity_key", default="")
        if entity_key:
            entity = db.get(entity_key)
            if entity and entity.authored_by(user_data):
                self.render_json({
                    "error": "Je kan niet op je eigen opmerking stemmen."
                })
                return

        if vote_type != discussion_models.FeedbackVote.ABSTAIN:
            limiter = VoteRateLimiter(user_data)
            if not limiter.increment():
                self.render_json({"error": limiter.denied_desc()})
                return

        # We kick off a taskqueue item to perform the actual vote insertion
        # so we don't have to worry about fast writes to the entity group
        # causing contention problems for the HR datastore, because
        # the taskqueue will just retry w/ exponential backoff.
        # TODO(marcia): user_data.email may change. user_id is preferred
        taskqueue.add(
            url='/admin/discussion/finishvoteentity',
            queue_name='voting-queue',
            params={
                "email": user_data.email,
                "vote_type": self.request_int(
                    "vote_type",
                    default=discussion_models.FeedbackVote.ABSTAIN),
                "entity_key": entity_key
            }
        )
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:60,代码来源:voting.py

示例7: get

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
    def get(self):
        user_data = UserData.current()
        user_data_override = self.request_user_data("coach_email")
        if user_util.is_current_user_developer() and user_data_override:
            user_data = user_data_override

        invalid_student = self.request_bool("invalid_student", default=False)

        coach_requests = [req.student_requested_identifier
                          for req in CoachRequest.get_for_coach(user_data)
                          if req.student_requested_data]

        student_lists_models = StudentList.get_for_coach(user_data.key())
        student_lists_list = []
        for student_list in student_lists_models:
            student_lists_list.append({
                'key': str(student_list.key()),
                'name': student_list.name,
            })
        student_lists_dict = dict((g['key'], g) for g in student_lists_list)

        def student_to_dict(s):
            """Convert the UserData s to a dictionary for rendering."""
            return {
                'key': str(s.key()),
                'email': s.email,
                'username': s.username,
                # Note that child users don't have an email.
                'identifier': s.username or s.email,
                'nickname': s.nickname,
                'profile_root': s.profile_root,
                'can_modify_coaches': s.can_modify_coaches(),
                'studentLists':
                        [l for l in [student_lists_dict.get(str(list_id))
                           for list_id in s.student_lists] if l],
            }

        students_data = user_data.get_students_data()
        students = map(student_to_dict, students_data)
        students.sort(key=lambda s: s['nickname'])

        child_accounts = map(student_to_dict, user_data.get_child_users())
        template_values = {
            'students': students,
            'child_accounts': child_accounts,
            'child_account_keyset': set([c['key'] for c in child_accounts]),
            'students_json': json.dumps(students),
            'student_lists': student_lists_list,
            'student_lists_json': json.dumps(student_lists_list),
            'invalid_student': invalid_student,
            'coach_requests': coach_requests,
            'coach_requests_json': json.dumps(coach_requests),
            'selected_nav_link': 'coach',
            'email': user_data.email,
        }
        self.render_jinja2_template('viewstudentlists.html', template_values)
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:58,代码来源:coaches.py

示例8: get

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
    def get(self):
        user_data = UserData.current()
        user_video_css = video_models.UserVideoCss.get_for_user_data(user_data)
        self.response.headers['Content-Type'] = 'text/css'

        if user_video_css.version == user_data.uservideocss_version:
            # Don't cache if there's a version mismatch and update isn't finished
            self.response.headers['Cache-Control'] = 'public,max-age=1000000'

        self.response.out.write(user_video_css.video_css)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:12,代码来源:main.py

示例9: do_request

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
    def do_request(self, student, coach, redirect_to):
        if not UserData.current():
            self.redirect(util.create_login_url(self.request.uri))
            return

        if student and coach:
            self.remove_student_from_coach(student, coach)

        if not self.is_ajax_request():
            self.redirect(redirect_to)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:12,代码来源:coaches.py

示例10: get

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

        self.render_jinja2_template('coach_resources/view_demo.html', {
            "selected_id": "demo",
            "base_url": "/toolkit",
            "not_in_toolkit_format": 1,
            "is_logged_in": json.dumps(not coach.is_phantom if coach
                                       else False),
        })
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:12,代码来源:util_coach.py

示例11: get_profile_target_user_data

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

        if coach:
            user_override = self.request_user_data("coach_email")
            if user_override and user_override.are_students_visible_to(coach):
                # Only allow looking at a student list other than your own
                # if you are a dev, admin, or coworker.
                coach = user_override

        return coach
开发者ID:PerceptumNL,项目名称:khan-multilingual,代码行数:13,代码来源:handlers.py

示例12: get

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
    def get(self):
        template_values = {}
        user_data = UserData.current()

        if user_data is not None:
            return self.authenticated_response()

        else:
            template_values = {
                "authenticated" : False,
            }

        self.add_global_template_values(template_values)
        self.render_jinja2_template('summer/summer_process.html', template_values)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:16,代码来源:__init__.py

示例13: post

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
    def post(self):
        user_data = UserData.current()

        user_data_student = self.request_student_user_data()
        if user_data_student:
            if not user_data_student.is_coached_by(user_data):
                coach_request = CoachRequest.get_or_insert_for(user_data, user_data_student)
                if coach_request:
                    if not self.is_ajax_request():
                        self.redirect("/students")
                    return

        if self.is_ajax_request():
            self.response.set_status(404)
        else:
            self.redirect("/students?invalid_student=1")
开发者ID:PaulWagener,项目名称:khan-website,代码行数:18,代码来源:coaches.py

示例14: get

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
    def get(self):
        user_data = UserData.current()
        sort = self.request_int("sort",
                                default=VotingSortOrder.HighestPointsFirst)

        if user_data:
            user_data.question_sort_order = sort
            user_data.put()

        readable_id = self.request_string("readable_id", default="")
        topic_title = self.request_string("topic_title", default="")

        if readable_id and topic_title:
            self.redirect("/video/%s?topic=%s&sort=%s" % (
                urllib.quote(readable_id), urllib.quote(topic_title), sort))
        else:
            self.redirect("/")
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:19,代码来源:voting.py

示例15: update_scratchpad

# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import current [as 别名]
def update_scratchpad(scratchpad_id):
    """Update a pre-existing Scratchpad and create a new ScratchpadRevision.

    The POST data should be a JSON-encoded dict, which is passsed verbatim to
    Scratchpad.update as keyword arguments.
    """
    if not gandalf.bridge.gandalf("scratchpads"):
        return api_forbidden_response(
            "Forbidden: You don't have permission to do this")

    if not request.json:
        return api_invalid_param_response("Bad data supplied: Not JSON")

    user = UserData.current()
    scratchpad = scratchpad_models.Scratchpad.get_by_id(scratchpad_id)

    if not scratchpad or scratchpad.deleted:
        return api_not_found_response(
            "No scratchpad with id %s" % scratchpad_id)

    if not user.developer:
        # Certain fields are only modifiable by developers
        for field in scratchpad_models.Scratchpad._developer_only_fields:
            if request.json.get(field):
                return api_forbidden_response(
                    "Forbidden: Only developers can change the %s" % field)

    # The user can update the scratchpad if any of the following are true:
    #  1. The scratchpad is tutorial/official and the user is a developer
    #  2. The scratchpad was created by the user
    if scratchpad.category in ("tutorial", "official") and user.developer:
        pass
    elif scratchpad.user_id != user.user_id:
        # Only the creator of a scratchpad can update it
        return api_forbidden_response(
            "Forbidden: Scratchpad owned by different user")

    try:
        # Convert unicode encoded JSON keys to strings
        update_args = dict_keys_to_strings(request.json)
        if 'id' in update_args:
            # Backbone passes the id in update calls - ignore it
            del update_args['id']
        return scratchpad.update(**update_args)
    except (db.BadValueError, db.BadKeyError), e:
        return api_invalid_param_response("Bad data supplied: " + e.message)
开发者ID:Hao-Hsuan,项目名称:KhanLatest,代码行数:48,代码来源:handlers.py


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