<commit_before># Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module to manage assessments"""

__author__ = '<NAME> (<EMAIL>)'

import datetime
import logging
import os
import urllib

import appengine_config
from controllers import utils
from models import courses
from models import custom_modules
from models import models
from models import review as models_review
from models import student_work
from models import transforms
from models import utils as models_utils
from models.models import Student
from models.models import StudentAnswersEntity
from modules.embed import embed
from modules.review import domain
from tools import verify

from google.appengine.ext import db

_BASE_DIR = os.path.join(appengine_config.BUNDLE_ROOT, 'modules', 'assessments')
_TEMPLATES_DIR = os.path.join(_BASE_DIR, 'templates')
_EMBEDDED_ASSESSMENT_KEY = 'assessment'

custom_module = None


def create_readonly_assessment_params(content, answers):
    """Creates parameters for a readonly assessment in the view templates."""
    assessment_params = {
        'preamble': content['assessment']['preamble'],
        'questionsList': content['assessment']['questionsList'],
        'answers': answers,
    }
    return assessment_params


class AssignmentsModuleMixin(object):
    def get_template(self, template_file, additional_dirs=None, prefs=None):
        return super(AssignmentsModuleMixin, self).get_template(
            template_file,
            additional_dirs=[_TEMPLATES_DIR] + (additional_dirs or []),
            prefs=prefs)


class AssessmentHandler(AssignmentsModuleMixin, utils.BaseHandler):
    """Handler for generating assessment page."""

    # pylint: disable=too-many-statements
    def get(self):
        """Handles GET requests."""
        embedded = bool(self.request.get('embedded'))

        student = self.personalize_page_and_get_enrolled(
            supports_transient_student=True)
        if not student:
            return

        # Extract incoming args, binding to self if needed.
        assessment_name = self.request.get('name')
        self.unit_id = assessment_name
        course = self.get_course()
        unit = course.find_unit_by_id(self.unit_id)
        if not unit:
            self.error(404)
            return

        # If assessment is used as a pre/post within a unit, go see that view.
        parent_unit = course.get_parent_unit(self.unit_id)
        if parent_unit:
            self.redirect('/unit?unit=%s&assessment=%s' %
                          (parent_unit.unit_id, self.unit_id))
            return

        # If the assessment is not currently available, and the user does not
        # have the permission to see drafts redirect to the main page.
        if (not course.is_unit_available(unit) and
            not custom_modules.can_see_drafts(self.app_context)):
            self.redirect('/')
            return

        self.template_value['main_content'] = self.get_assessment_content(
            student, course, unit, as_lesson=False, embedded=embedded)
        self.template_value['assessment_name'] = assessment_name
        self.template_value['unit_id'] = self.unit_id
        self.template_value['navbar'] = {'course': True}
        if embedded:
            self.template_value['embed_child_js_url'] = embed.EMBED_CHILD_JS_URL
            self.template_value['gcb_html_element_class'] = 'hide-controls'

        self.render('assessment_page.html')

    def get_assessment_content(
            self, student, course, unit, as_lesson, embedded=False):
        if embedded and course.needs_human_grader(unit):
            # I18N: This is an error message to an author of an online course.
            # The problem is that course assignments that are to be graded
            # by other students (peers) cannot be configured to be added
            # as content to external web pages. (I.e., some external site wants
            # to use this assignment as part of a page's content, but this
            # is not permitted)
            return self.app_context.gettext(
                'Peer-review assignments cannot be embedded in external pages.')

        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_readonly_view = self.configure_readonly_view_1_4
            configure_active_view = self.configure_active_view_1_4
            get_review_received = self.get_review_received_1_4
        elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5:
            configure_readonly_view = self.configure_readonly_view_1_5
            configure_active_view = self.configure_active_view_1_5
            get_review_received = self.get_review_received_1_5
        else:
            raise ValueError('Bad assessment model version: %s' % model_version)<commit_msg>Don't redirect people to embedded assessments 	Change on 2015/11/10 by nretallack <<EMAIL>> ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=107546926<commit_after># Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module to manage assessments"""

__author__ = '<NAME> (<EMAIL>)'

import datetime
import logging
import os
import urllib

import appengine_config
from controllers import utils
from models import courses
from models import custom_modules
from models import models
from models import review as models_review
from models import student_work
from models import transforms
from models import utils as models_utils
from models.models import Student
from models.models import StudentAnswersEntity
from modules.embed import embed
from modules.review import domain
from tools import verify

from google.appengine.ext import db

_BASE_DIR = os.path.join(appengine_config.BUNDLE_ROOT, 'modules', 'assessments')
_TEMPLATES_DIR = os.path.join(_BASE_DIR, 'templates')
_EMBEDDED_ASSESSMENT_KEY = 'assessment'

custom_module = None


def create_readonly_assessment_params(content, answers):
    """Creates parameters for a readonly assessment in the view templates."""
    assessment_params = {
        'preamble': content['assessment']['preamble'],
        'questionsList': content['assessment']['questionsList'],
        'answers': answers,
    }
    return assessment_params


class AssignmentsModuleMixin(object):
    def get_template(self, template_file, additional_dirs=None, prefs=None):
        return super(AssignmentsModuleMixin, self).get_template(
            template_file,
            additional_dirs=[_TEMPLATES_DIR] + (additional_dirs or []),
            prefs=prefs)


class AssessmentHandler(AssignmentsModuleMixin, utils.BaseHandler):
    """Handler for generating assessment page."""

    # pylint: disable=too-many-statements
    def get(self):
        """Handles GET requests."""
        embedded = bool(self.request.get('embedded'))

        student = self.personalize_page_and_get_enrolled(
            supports_transient_student=True)
        if not student:
            return

        # Extract incoming args, binding to self if needed.
        assessment_name = self.request.get('name')
        self.unit_id = assessment_name
        course = self.get_course()
        unit = course.find_unit_by_id(self.unit_id)
        if not unit:
            self.error(404)
            return

        # If assessment is used as a pre/post within a unit, go see that view.
        parent_unit = course.get_parent_unit(self.unit_id)
        if parent_unit:
            self.redirect('/unit?unit=%s&assessment=%s' %
                          (parent_unit.unit_id, self.unit_id))
            return

        # If the assessment is not currently available, and the user does not
        # have the permission to see drafts redirect to the main page.
        if (not course.is_unit_available(unit) and
            not custom_modules.can_see_drafts(self.app_context)):
            self.redirect('/')
            return

        self.template_value['main_content'] = self.get_assessment_content(
            student, course, unit, as_lesson=False, embedded=embedded)
        self.template_value['assessment_name'] = assessment_name
        self.template_value['unit_id'] = self.unit_id
        self.template_value['navbar'] = {'course': True}
        if embedded:
            self.template_value['embed_child_js_url'] = embed.EMBED_CHILD_JS_URL
            self.template_value['gcb_html_element_class'] = 'hide-controls'

        self.render('assessment_page.html', save_location=not embedded)

    def get_assessment_content(
            self, student, course, unit, as_lesson, embedded=False):
        if embedded and course.needs_human_grader(unit):
            # I18N: This is an error message to an author of an online course.
            # The problem is that course assignments that are to be graded
            # by other students (peers) cannot be configured to be added
            # as content to external web pages. (I.e., some external site wants
            # to use this assignment as part of a page's content, but this
            # is not permitted)
            return self.app_context.gettext(
                'Peer-review assignments cannot be embedded in external pages.')

        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_readonly_view = self.configure_readonly_view_1_4
            configure_active_view = self.configure_active_view_1_4
            get_review_received = self.get_review_received_1_4
        elif model_version == courses.ASSESSMENT_MODEL_VERSION_1_5:
            configure_readonly_view = self.configure_readonly_view_1_5
            configure_active_view = self.configure_active_view_1_5
            get_review_received = self.get_review_received_1_5
        else:
            raise ValueError('Bad assessment model version: %s' % model_version)
{'fraction_non_alphanumeric': 0.07617691554685414, 'fraction_numerical': 0.006674379282726706, 'mean_word_length': 3.1854748603351957, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6073915', 'n_tokens_mistral': 3118, 'n_tokens_neox': 3008, 'n_words': 911}