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


Python XsrfTokenManager.create_xsrf_token方法代码示例

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


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

示例1: _populate_template

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def _populate_template(self, course, unit, review_steps):
        """Adds variables to the template for the review dashboard."""
        self.template_value['assessment_name'] = unit.title
        self.template_value['unit_id'] = unit.unit_id

        parent_unit = course.get_parent_unit(unit.unit_id)

        if parent_unit is not None:
            self.template_value['back_link'] = 'unit?unit=%s&assessment=%s' % (
                parent_unit.unit_id, unit.unit_id)
        else:
            self.template_value['back_link'] = (
                'assessment?name=%s' % unit.unit_id)

        self.template_value['event_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('event-post'))
        self.template_value['review_dashboard_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('review-dashboard-post'))

        self.template_value['REVIEW_STATE_COMPLETED'] = (
            domain.REVIEW_STATE_COMPLETED)

        self.template_value['review_steps'] = review_steps
        self.template_value['review_min_count'] = (
            unit.workflow.get_review_min_count())

        review_due_date = unit.workflow.get_review_due_date()
        if review_due_date:
            self.template_value['review_due_date'] = review_due_date.strftime(
                HUMAN_READABLE_DATETIME_FORMAT)

        time_now = datetime.datetime.now()
        self.template_value['due_date_exceeded'] = (time_now > review_due_date)
开发者ID:danieldalonzo,项目名称:coursebuilder-core,代码行数:35,代码来源:lessons.py

示例2: get

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles GET requests."""
        if not self.personalize_page_and_get_enrolled():
            return

        # Extract incoming args
        unit_id, lesson_id = extract_unit_and_lesson_id(self)
        self.template_value['unit_id'] = unit_id
        self.template_value['lesson_id'] = lesson_id

        # Set template values for a unit and its lesson entities
        for unit in self.get_units():
            if unit.unit_id == str(unit_id):
                self.template_value['units'] = unit

        lessons = self.get_lessons(unit_id)
        self.template_value['lessons'] = lessons

        # Set template values for nav bar
        self.template_value['navbar'] = {'course': True}

        # Set template values for back and next nav buttons
        self.template_value['back_button_url'] = (
            'unit?unit=%s&lesson=%s' % (unit_id, lesson_id))
        if lesson_id == len(lessons):
            self.template_value['next_button_url'] = ''
        else:
            self.template_value['next_button_url'] = (
                'unit?unit=%s&lesson=%s' % (unit_id, lesson_id + 1))

        self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value
        self.template_value['event_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('event-post'))

        self.render('activity.html')
开发者ID:Letractively,项目名称:cb4oru,代码行数:37,代码来源:lessons.py

示例3: get

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles GET requests."""
        models.MemcacheManager.begin_readonly()
        try:
            user = self.personalize_page_and_get_user()
            if user is None:
                student = TRANSIENT_STUDENT
            else:
                student = Student.get_enrolled_student_by_user(user)
                profile = StudentProfileDAO.get_profile_by_user(user)
                self.template_value['has_global_profile'] = profile is not None
                if not student:
                    student = TRANSIENT_STUDENT

            if (student.is_transient and
                not self.app_context.get_environ()['course']['browsable']):
                self.redirect('/preview')
                return

            # If we are on this page due to visiting the course base URL
            # (and not base url plus "/course"), redirect registered students
            # to the last page they were looking at.
            last_location = self.get_redirect_location(student)
            if last_location:
                self.redirect(last_location)
                return

            tracker = self.get_progress_tracker()
            units = self.get_track_matching_student(student)
            units = filter_assessments_used_within_units(units)
            self.template_value['units'] = units
            self.template_value['show_registration_page'] = True

            if student and not student.is_transient:
                augment_assessment_units(self.get_course(), student)
                self.template_value['course_progress'] = (
                    tracker.get_course_progress(student))
            elif user:
                profile = StudentProfileDAO.get_profile_by_user_id(
                    user.user_id())
                additional_registration_fields = self.app_context.get_environ(
                    )['reg_form']['additional_registration_fields']
                if profile is not None and not additional_registration_fields:
                    self.template_value['show_registration_page'] = False
                    self.template_value['register_xsrf_token'] = (
                        XsrfTokenManager.create_xsrf_token('register-post'))

            self.template_value['transient_student'] = student.is_transient
            self.template_value['progress'] = tracker.get_unit_progress(student)
            course = self.app_context.get_environ()['course']
            set_image_or_video_exists(self.template_value, course)

            self.template_value['is_progress_recorded'] = is_progress_recorded(
                self, student)
            self.template_value['navbar'] = {'course': True}
        finally:
            models.MemcacheManager.end_readonly()
        self.render('course.html')
开发者ID:danieldalonzo,项目名称:coursebuilder-core,代码行数:60,代码来源:lessons.py

示例4: get

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles GET requests."""
        if not self.personalize_page_and_get_enrolled():
            return

        # Extract incoming args
        unit_id = self.request.get('name')
        self.template_value['navbar'] = {'course': True}
        self.template_value['assessment_script_src'] = (
            self.get_course().get_assessment_filename(unit_id))
        self.template_value['unit_id'] = unit_id
        self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value
        self.template_value['assessment_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('assessment-post'))
        self.template_value['event_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('event-post'))

        self.render('assessment.html')
开发者ID:henrymp,项目名称:coursebuilder,代码行数:20,代码来源:lessons.py

示例5: get

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles GET requests."""
        if not self.personalize_page_and_get_enrolled():
            return

        # Extract incoming args
        n = self.request.get('name')
        if not n:
            n = 'Pre'
        self.template_value['name'] = n
        self.template_value['navbar'] = {'course': True}
        self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value
        self.template_value['assessment_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('assessment-post'))
        self.template_value['event_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('event-post'))

        self.render('assessment.html')
开发者ID:supunkamburugamuve,项目名称:mooc2,代码行数:20,代码来源:lessons.py

示例6: populate_template

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def populate_template(self, unit, review_steps):
        """Adds variables to the template for the review dashboard."""
        self.template_value["assessment_name"] = unit.title
        self.template_value["unit_id"] = unit.unit_id
        self.template_value["event_xsrf_token"] = XsrfTokenManager.create_xsrf_token("event-post")
        self.template_value["review_dashboard_xsrf_token"] = XsrfTokenManager.create_xsrf_token("review-dashboard-post")

        self.template_value["REVIEW_STATE_COMPLETED"] = domain.REVIEW_STATE_COMPLETED

        self.template_value["review_steps"] = review_steps
        self.template_value["review_min_count"] = unit.workflow.get_review_min_count()

        review_due_date = unit.workflow.get_review_due_date()
        if review_due_date:
            self.template_value["review_due_date"] = review_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT)

        time_now = datetime.datetime.now()
        self.template_value["due_date_exceeded"] = time_now > review_due_date
开发者ID:johnfelipe,项目名称:cb-energietransitie,代码行数:20,代码来源:lessons.py

示例7: populate_template

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def populate_template(self, unit, review_steps):
        """Adds variables to the template for the review dashboard."""
        self.template_value['assessment_name'] = unit.title
        self.template_value['unit_id'] = unit.unit_id
        self.template_value['event_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('event-post'))
        self.template_value['review_dashboard_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('review-dashboard-post'))

        self.template_value['REVIEW_STATE_COMPLETED'] = (
            domain.REVIEW_STATE_COMPLETED)

        self.template_value['review_steps'] = review_steps
        self.template_value['review_min_count'] = (
            unit.workflow.get_review_min_count())

        review_due_date = unit.workflow.get_review_due_date()
        if review_due_date:
            self.template_value['review_due_date'] = review_due_date.strftime(
                HUMAN_READABLE_DATETIME_FORMAT)

        time_now = datetime.datetime.now()
        self.template_value['due_date_exceeded'] = (time_now > review_due_date)
开发者ID:graemian,项目名称:ami-mooc-pilot,代码行数:25,代码来源:lessons.py

示例8: get

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles GET requests."""
        user = self.personalize_page_and_get_user()
        if user is None:
            student = TRANSIENT_STUDENT
        else:
            student = Student.get_enrolled_student_by_email(user.email())
            profile = StudentProfileDAO.get_profile_by_user_id(user.user_id())
            self.template_value["has_global_profile"] = profile is not None
            if not student:
                student = TRANSIENT_STUDENT

        if student.is_transient and not self.app_context.get_environ()["course"]["browsable"]:
            self.redirect("/preview")
            return

        self.template_value["units"] = self.get_units()
        self.template_value["show_registration_page"] = True

        if student and not student.is_transient:
            self.augment_assessment_units(student)
        elif user:
            profile = StudentProfileDAO.get_profile_by_user_id(user.user_id())
            additional_registration_fields = self.app_context.get_environ()["reg_form"][
                "additional_registration_fields"
            ]
            if profile is not None and not additional_registration_fields:
                self.template_value["show_registration_page"] = False
                self.template_value["register_xsrf_token"] = XsrfTokenManager.create_xsrf_token("register-post")

        self.template_value["transient_student"] = student.is_transient
        self.template_value["progress"] = self.get_progress_tracker().get_unit_progress(student)

        course = self.app_context.get_environ()["course"]
        self.template_value["video_exists"] = bool(
            "main_video" in course and "url" in course["main_video"] and course["main_video"]["url"]
        )
        self.template_value["image_exists"] = bool(
            "main_image" in course and "url" in course["main_image"] and course["main_image"]["url"]
        )

        self.template_value["is_progress_recorded"] = CAN_PERSIST_ACTIVITY_EVENTS.value
        self.template_value["navbar"] = {"course": True}
        self.render("course.html")
开发者ID:johnfelipe,项目名称:cb-energietransitie,代码行数:46,代码来源:lessons.py

示例9: get

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles GET requests."""
        student = self.personalize_page_and_get_enrolled()
        if not student:
            return

        course = self.get_course()
        rp = course.get_reviews_processor()
        unit, unused_lesson = extract_unit_and_lesson(self)

        if not course.needs_human_grader(unit):
            self.error(404)
            return

        review_step_key = self.request.get('key')
        if not unit or not review_step_key:
            self.error(404)
            return

        try:
            review_step_key = db.Key(encoded=review_step_key)
            review_step = rp.get_review_steps_by_keys(
                unit.unit_id, [review_step_key])[0]
        except Exception:  # pylint: disable-msg=broad-except
            self.error(404)
            return

        if not review_step:
            self.error(404)
            return

        # Check that the student is allowed to review this submission.
        if not student.has_same_key_as(review_step.reviewer_key):
            self.error(404)
            return

        model_version = course.get_assessment_model_version(unit)
        assert model_version in courses.SUPPORTED_ASSESSMENT_MODEL_VERSIONS
        self.template_value['model_version'] = model_version

        if model_version == courses.ASSESSMENT_MODEL_VERSION_1_4:
            configure_assessment_view = self.configure_assessment_view_1_4
            configure_readonly_review = self.configure_readonly_review_1_4
            configure_active_review = self.configure_active_review_1_4
        elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5:
            configure_assessment_view = self.configure_assessment_view_1_5
            configure_readonly_review = self.configure_readonly_review_1_5
            configure_active_review = self.configure_active_review_1_5
        else:
            raise ValueError('Bad assessment model version: %s' % model_version)

        self.template_value['navbar'] = {'course': True}
        self.template_value['unit_id'] = unit.unit_id
        self.template_value['key'] = review_step_key

        submission_key = review_step.submission_key
        submission_contents = student_work.Submission.get_contents_by_key(
            submission_key)

        configure_assessment_view(unit, submission_contents)

        review_due_date = unit.workflow.get_review_due_date()
        if review_due_date:
            self.template_value['review_due_date'] = review_due_date.strftime(
                HUMAN_READABLE_DATETIME_FORMAT)

        review_key = review_step.review_key
        rev = rp.get_reviews_by_keys(
            unit.unit_id, [review_key])[0] if review_key else None

        time_now = datetime.datetime.now()
        show_readonly_review = (
            review_step.state == domain.REVIEW_STATE_COMPLETED or
            time_now > review_due_date)

        self.template_value['due_date_exceeded'] = (time_now > review_due_date)

        if show_readonly_review:
            configure_readonly_review(unit, rev)
        else:
            # Populate the review form,
            configure_active_review(unit, rev)

        self.template_value['assessment_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('review-post'))
        self.template_value['event_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('event-post'))

        # CGL-MOOC-Builder starts:
        # Set template value for students progress bar that shows on the top navigation(header.html)
        total_progress = (self.get_progress_tracker().get_overall_progress_score(student))
        self.template_value['progress_value'] = total_progress.get('progress_score', 0)
        self.template_value['complete_value'] = total_progress.get('completed_score', 0)
        self.template_value['percentage'] = total_progress.get('percentage', '')
        # CGL-MOOC-Builder ends

        self.render('review.html')
开发者ID:cglmoocs,项目名称:cgl-mooc-builder,代码行数:99,代码来源:lessons.py

示例10: get

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles GET requests."""
        student = self.personalize_page_and_get_enrolled()
        if not student:
            return

        # Extract incoming args
        unit, lesson = extract_unit_and_lesson(self)
        unit_id = unit.unit_id

        # If the unit is not currently available, and the user is not an admin,
        # redirect to the main page.
        if (not unit.now_available and
            not Roles.is_course_admin(self.app_context)):
            self.redirect('/')
            return

        # Set template values for nav bar and page type.
        self.template_value['navbar'] = {'course': True}
        self.template_value['page_type'] = ACTIVITY_PAGE_TYPE

        lessons = self.get_lessons(unit_id)

        # Set template values for a unit and its lesson entities
        self.template_value['unit'] = unit
        self.template_value['unit_id'] = unit_id
        self.template_value['lesson'] = lesson
        self.template_value['lessons'] = lessons

        # If this unit contains no lessons, return.
        if not lesson:
            self.render('activity.html')
            return

        lesson_id = lesson.lesson_id
        self.template_value['lesson_id'] = lesson_id
        self.template_value['activity_script_src'] = (
            self.get_course().get_activity_filename(unit_id, lesson_id))

        index = lesson.index - 1  # indexes are 1-based

        # Format back button.
        self.template_value['back_button_url'] = (
            'unit?unit=%s&lesson=%s' % (unit_id, lesson_id))

        # Format next button.
        if index >= len(lessons) - 1:
            self.template_value['next_button_url'] = ''
        else:
            next_lesson = lessons[index + 1]
            self.template_value['next_button_url'] = (
                'unit?unit=%s&lesson=%s' % (
                    unit_id, next_lesson.lesson_id))

        # Set template value for event recording
        self.template_value['record_events'] = CAN_PERSIST_ACTIVITY_EVENTS.value

        # Set template values for student progress
        self.template_value['is_progress_recorded'] = (
            CAN_PERSIST_ACTIVITY_EVENTS.value)
        if CAN_PERSIST_ACTIVITY_EVENTS.value:
            self.template_value['progress'] = (
                self.get_progress_tracker().get_lesson_progress(
                    student, unit_id))

        self.template_value['event_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('event-post'))

        # Mark this page as accessed. This is done after setting the student
        # progress template value, so that the mark only shows up after the
        # student visits the page for the first time.
        self.get_course().get_progress_tracker().put_activity_accessed(
            student, unit_id, lesson_id)

        self.render('activity.html')
开发者ID:graemian,项目名称:ami-mooc-pilot,代码行数:77,代码来源:lessons.py

示例11: get_start

# 需要导入模块: from utils import XsrfTokenManager [as 别名]
# 或者: from utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get_start(self):
        """Handles GET requests."""
        student = self.personalize_page_and_get_enrolled()
        if not student:
            return
        if not self.assert_participant_or_fail(student):
            return

        # Extract incoming args
        unit_id = self.request.get("name")
        course = self.get_course()
        unit = course.find_unit_by_id(unit_id)
        if not unit:
            self.error(404)
            return

        self.template_value["navbar"] = {"course": True}

        try:
            AssessmentTracker.try_start_test(student, unit_id)
        except ValueError as e:
            self.template_value["error"] = e.message
            self.render("assessment_denied.html")
            return

        self.template_value["unit_id"] = unit_id
        self.template_value["record_events"] = CAN_PERSIST_ACTIVITY_EVENTS.value
        self.template_value["assessment_xsrf_token"] = XsrfTokenManager.create_xsrf_token("assessment-post")
        self.template_value["event_xsrf_token"] = XsrfTokenManager.create_xsrf_token("event-post")

        self.template_value["grader"] = unit.workflow.get_grader()

        readonly_view = False
        due_date_exceeded = False

        submission_due_date = unit.workflow.get_submission_due_date()
        if submission_due_date:
            self.template_value["submission_due_date"] = submission_due_date.strftime(HUMAN_READABLE_DATETIME_FORMAT)

            time_now = datetime.datetime.now()
            if time_now > submission_due_date:
                readonly_view = True
                due_date_exceeded = True
                self.template_value["due_date_exceeded"] = True

        if course.needs_human_grader(unit):
            self.template_value["matcher"] = unit.workflow.get_matcher()

            rp = course.get_reviews_processor()
            review_steps_by = rp.get_review_steps_by(unit.unit_id, student.get_key())

            # Determine if the student can see others' reviews of his/her work.
            if ReviewUtils.has_completed_enough_reviews(review_steps_by, unit.workflow.get_review_min_count()):
                submission_and_review_steps = rp.get_submission_and_review_steps(unit.unit_id, student.get_key())

                submission_contents = submission_and_review_steps[0]
                review_steps_for = submission_and_review_steps[1]

                review_keys_for_student = []
                for review_step in review_steps_for:
                    can_show_review = (
                        review_step.state == domain.REVIEW_STATE_COMPLETED
                        and not review_step.removed
                        and review_step.review_key
                    )

                    if can_show_review:
                        review_keys_for_student.append(review_step.review_key)

                reviews_for_student = rp.get_reviews_by_keys(unit.unit_id, review_keys_for_student)

                self.template_value["reviews_received"] = [
                    create_readonly_assessment_params(
                        course.get_review_form_content(unit), StudentWorkUtils.get_answer_list(review)
                    )
                    for review in reviews_for_student
                ]
            else:
                submission_contents = student_work.Submission.get_contents(unit.unit_id, student.get_key())

            # Determine whether to show the assessment in readonly mode.
            if submission_contents or due_date_exceeded:
                readonly_view = True
                self.template_value["readonly_student_assessment"] = create_readonly_assessment_params(
                    course.get_assessment_content(unit), StudentWorkUtils.get_answer_list(submission_contents)
                )

        if not readonly_view:
            self.template_value["assessment_script_src"] = self.get_course().get_assessment_filename(unit_id)

            # If a previous submission exists, reinstate it.
            submission_contents = student_work.Submission.get_contents(unit.unit_id, student.get_key())
            saved_answers = StudentWorkUtils.get_answer_list(submission_contents) if submission_contents else []
            self.template_value["saved_answers"] = transforms.dumps(saved_answers)

        self.render("assessment.html")
开发者ID:twiffy,项目名称:eabooc,代码行数:98,代码来源:lessons.py


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