Beispiel #1
0
    def init_template_values(self, environ, prefs=None):
        """Initializes template variables with common values."""
        self.template_value[COURSE_INFO_KEY] = environ
        self.template_value[
            'page_locale'] = self.app_context.get_current_locale()
        self.template_value['html_hooks'] = HtmlHooks(
            self.get_course(), prefs=prefs)
        self.template_value['is_course_admin'] = Roles.is_course_admin(
            self.app_context)
        self.template_value['can_see_drafts'] = (
            courses_module.courses.can_see_drafts(self.app_context))
        self.template_value[
            'is_read_write_course'] = self.app_context.fs.is_read_write()
        self.template_value['is_super_admin'] = Roles.is_super_admin()
        self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
        self.template_value['left_links'] = []
        for func in self.LEFT_LINKS:
            self.template_value['left_links'].extend(func(self.app_context))
        self.template_value['right_links'] = []
        for func in self.RIGHT_LINKS:
            self.template_value['right_links'].extend(func(self.app_context))

        if not prefs:
            prefs = models.StudentPreferencesDAO.load_or_create()
        self.template_value['student_preferences'] = prefs

        if (Roles.is_course_admin(self.app_context) and
            not appengine_config.PRODUCTION_MODE and
            prefs and prefs.show_jinja_context):

            @jinja2.contextfunction
            def get_context(context):
                return context
            self.template_value['context'] = get_context

        if CAN_PUT_DEBUG_INFO_INTO_PAGES.value:
            self.template_value['debug_info'] = self.debug_info()

        self.template_value[
            'extra_global_css_urls'] = self.EXTRA_GLOBAL_CSS_URLS
        self.template_value[
            'extra_global_js_urls'] = self.EXTRA_GLOBAL_JS_URLS

        # Common template information for the locale picker (only shown for
        # user in session)
        can_student_change_locale = (
            self.get_course().get_course_setting('can_student_change_locale')
            or self.get_course().app_context.can_pick_all_locales())
        if can_student_change_locale:
            self.template_value['available_locales'] = [
                {
                    'name': locales.get_locale_display_name(loc),
                    'value': loc
                } for loc in self.app_context.get_allowed_locales()]
            self.template_value['locale_xsrf_token'] = (
                XsrfTokenManager.create_xsrf_token(
                    StudentLocaleRESTHandler.XSRF_TOKEN_NAME))
            self.template_value['selected_locale'] = self.get_locale_for(
                self.request, self.app_context, prefs=prefs)
 def get_public_courses(self):
     """Get all the public courses."""
     public_courses = []
     for course in sites.get_all_courses():
         if ((course.now_available and Roles.is_user_whitelisted(course))
             or Roles.is_course_admin(course)):
             public_courses.append(course)
     return public_courses
Beispiel #3
0
 def get_template(self, template_file, additional_dirs=None):
     """Computes location of template files for the current namespace."""
     self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
     self.template_value["is_course_admin"] = Roles.is_course_admin(self.app_context)
     self.template_value["is_super_admin"] = Roles.is_super_admin()
     self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
     return self.app_context.get_template_environ(
         self.template_value[COURSE_INFO_KEY]["course"]["locale"], additional_dirs
     ).get_template(template_file)
Beispiel #4
0
 def get_template(self, template_file, additional_dirs=None):
     """Computes location of template files for the current namespace."""
     self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
     self.template_value["is_course_admin"] = Roles.is_course_admin(self.app_context)
     self.template_value["is_read_write_course"] = self.app_context.fs.is_read_write()
     self.template_value["is_super_admin"] = Roles.is_super_admin()
     self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
     template_environ = self.app_context.get_template_environ(
         self.template_value[COURSE_INFO_KEY]["course"]["locale"], additional_dirs
     )
     template_environ.filters["gcb_tags"] = jinja_utils.get_gcb_tags_filter(self)
     return template_environ.get_template(template_file)
Beispiel #5
0
    def insert(self, name):
        # Do we want page markup to permit course admins to edit hooks?
        show_admin_content = False
        if (self.prefs and self.prefs.show_hooks and
            Roles.is_course_admin(self.course.app_context)):
            show_admin_content = True
        if self.course.version == courses.CourseModel12.VERSION:
            show_admin_content = False

        # Look up desired content chunk in course.yaml dict/sub-dict.
        content = ''
        environ = self.course.app_context.get_environ()
        for part in name.split(':'):
            if part in environ:
                item = environ[part]
                if type(item) == str:
                    content = item
                else:
                    environ = item
        if show_admin_content and not self._has_visible_content(content):
            content += name

        # Add the content to the page in response to the hook call.
        hook_div = safe_dom.Element('div', className='gcb-html-hook',
                                    id=re.sub('[^a-zA-Z-]', '-', name))
        hook_div.add_child(tags.html_to_safe_dom(content, self))

        # Mark up content to enable edit controls
        if show_admin_content:
            hook_div.add_attribute(onclick='gcb_edit_hook_point("%s")' % name)
            hook_div.add_attribute(className='gcb-html-hook-edit')
        return jinja2.Markup(hook_div.sanitized)
Beispiel #6
0
    def get(self):
        if not Roles.is_course_admin(self.app_context):
            self.error(403)
            self.response.write("NO")
            return

        nav = self._get_nav()
        if not nav:
            self.render_choices_page()
            return

        query_class = analytics_queries.get(nav['query'], None)
        if not query_class:
            logging.warn("Unrecognized query")
            self.abort(404, "I couldn't find the query that you requested.")

        try:
            query = query_class(self)
        except ValueError as e:
            self.render_choices_page(error=e.message)
            return

        if nav['view'] == 'csv':
            self.render_as_csv(query.fields, query.run())
        elif nav['view'] == 'debug':
            i = query.run()
            for x in i:
                pass
        else:
            iterator = query.run()
            if hasattr(query_class, 'htmlize_row'):
                iterator = [query.htmlize_row(r) for r in iterator]
            self.render_as_table(query.fields, iterator)
    def get_schema(cls):
        """Return the InputEx schema for the roles editor."""
        schema = schema_fields.FieldRegistry(
            'Role', description='role')

        schema.add_property(schema_fields.SchemaField(
            'version', '', 'string', optional=True, hidden=True))
        schema.add_property(schema_fields.SchemaField(
            'name', 'Name', 'string', optional=False,
            description=messages.ROLE_NAME_DESCRIPTION))
        schema.add_property(schema_fields.SchemaField(
            'description', 'Description', 'text', optional=True,
            description=messages.ROLE_DESCRIPTION_DESCRIPTION))
        # TODO(gdejonghe) Use user.id instead of user.email
        schema.add_property(schema_fields.SchemaField(
            'users', 'User Emails', 'text',
            description=messages.ROLE_USER_EMAILS_DESCRIPTION))

        subschema = schema.add_sub_registry('modules', 'Permission Modules')

        for module in Roles.get_modules():
            cls._add_module_permissions_schema(subschema, module.name)
        cls._add_module_permissions_schema(subschema, cls.INACTIVE_MODULES)

        return schema
Beispiel #8
0
    def get(self):
        """Handles GET requests."""
        if not Roles.is_course_admin(self.app_context):
            self.redirect('/preview')
            return

        student = self.personalize_page_and_get_enrolled(
            supports_transient_student=True)
        if not student:
            return
        else:
            # Set template value for 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', '')

        # Set template value for Google Community ID
        self.set_google_community_template_value()

        all_students = self.get_students()
        i = 0
        for s in all_students:
            i = i + 1
        self.template_value['navbar'] = {'students': True}
        self.template_value['total_students'] = i
        self.template_value['students_data'] = all_students
        self.render('students.html')
    def get(self):
        param_map = {}
        for k in self.request.arguments():
            param_map[k] = self.request.get(k)
        client_id = param_map.get('client_id', 0)

        logging.debug("vanilla request: " + str(param_map))

        user = users.get_current_user()
        if Roles.is_course_admin(self.app_context):
            role= "administrator"
        else:
            role="member"

        logging.debug(str(user))

        if user:
            student = Student.get_enrolled_student_by_email(user.email())
            user = {
                "name": student.name,
                "email": user.email(),
                "uniqueid": user.user_id(),
                "photourl": "",
            }
        course = self.app_context.get_environ()['course']

        client_id = course['VANILLA_CLIENT_ID']
        secret_key = course['VANILLA_SECRET_KEY']

        jsconn_str = get_jsconnect_string(user, param_map, client_id, secret_key)

        logging.debug("mooc-ed response: " + jsconn_str)

        self.response.out.write(jsconn_str)
Beispiel #10
0
 def get_template(self, template_file, additional_dirs=None):
     """Computes location of template files for the current namespace."""
     self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
     self.template_value['is_course_admin'] = Roles.is_course_admin(
         self.app_context)
     self.template_value[
         'is_read_write_course'] = self.app_context.fs.is_read_write()
     self.template_value['is_super_admin'] = Roles.is_super_admin()
     self.template_value['ga_analytics_key'] = GOOGLE_ANALYTICS_KEY.value
     self.template_value['ga_analytics_site'] = self.request.host
     self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
     environ = self.app_context.get_template_environ(
         self.template_value[COURSE_INFO_KEY]['course']['locale'],
         additional_dirs
         )
     self.mess_with_template_environ(environ)
     return environ.get_template(template_file)
Beispiel #11
0
    def get_template(self, template_file, additional_dirs=None):
        """Computes location of template files for the current namespace."""
        self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
        self.template_value["is_course_admin"] = Roles.is_course_admin(self.app_context)
        self.template_value["is_read_write_course"] = self.app_context.fs.is_read_write()
        self.template_value["is_super_admin"] = Roles.is_super_admin()
        self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
        template_environ = self.app_context.get_template_environ(
            self.template_value[COURSE_INFO_KEY]["course"]["locale"], additional_dirs
        )
        template_environ.filters["gcb_tags"] = jinja_utils.get_gcb_tags_filter(self)

        course = sites.get_course_for_current_request()
        if course.get_slug().split("_")[-1] == "DFR":
            self.template_value["gDefier_enabled"] = True

        return template_environ.get_template(template_file)
Beispiel #12
0
    def get(self):


        if not(Roles.is_course_admin(self.app_context)):
            self.redirect("preview")

        self.response.headers['Content-type'] = 'text/csv'
        self.response.headers['Content-disposition'] = 'attachment; filename=students.csv'


        course = self.get_course()

        assessments=[]

        for unit in course.get_units():
            if (unit.type=="A"):
                assessments.append(str(unit.unit_id))


        writer = UnicodeWriter(self.response.out)

        keys = Student.all(keys_only=True).run()

        rows=[]

        for key in keys:

            student=Student.get_by_key_name(key.name())

            rec={"email": key.name(), "name": student.name, "enrolled": unicode(student.is_enrolled), "dateEnrolled": unicode(student.enrolled_on) }

            if (student.scores):
                scores=json.loads(student.scores)

                for assessmentName, score in scores.iteritems():
                    rec[assessmentName]=str(score)


            rows.append(rec)

        headerRow = ["Email", "Name", "Is Enrolled", "Enrolled On"]

        for assessmentName in assessments:
            headerRow.append(course.find_unit_by_id(assessmentName).title)

        writer.writerow(headerRow)

        for row in rows:

            renderedRow=[row["email"],row["name"],row["enrolled"],row["dateEnrolled"]]

            for assessmentName in assessments:
                if (assessmentName in row):
                    renderedRow.append(row[assessmentName])
                else:
                    renderedRow.append("")

            writer.writerow(renderedRow)
Beispiel #13
0
 def get(self):
     user = self.personalize_page_and_get_enrolled()
     if not user:
         return
     if not Roles.is_course_admin(self.app_context):
         self.abort(403)
     self.template_value['student_count'] = get_student_count()
     self.template_value['navbar'] = {'booctools': True}
     self.render('booctools.html')
Beispiel #14
0
 def _update_dict_with_permissions(self, dictionary):
     app_context = self.get_course().app_context
     modules = {}
     for (module, callback) in Roles.get_permissions():
         modules[module.name] = []
         for (permission, description) in callback(app_context):
             modules[module.name].append(
                 self._generate_permission(permission, description, False))
     dictionary['modules'] = modules
     return dictionary
Beispiel #15
0
    def post_save(self):
        if not Roles.is_course_admin(self.app_context):
            self.abort(403, 'You are not an admin :(')
        user = self.personalize_page_and_get_enrolled()

        student_email = self.request.GET.get('email', None)
        if not student_email:
            self.abort(404, 'email= parameter required')
        student = Student.get_enrolled_student_by_email(student_email)
        if not student:
            self.abort(404, Markup('Could not find a student with email "%s"') % student_email)

        badge_slug = custom_badge_name(student)
        badge = Badge.get_or_insert(badge_slug)

        badge_form = BadgeForm(self.request.POST, badge)
        comments_form = CommentsForm(self.request.POST)
        if not (badge_form.validate() and comments_form.validate()):
            self.render_edit(badge_form, comments_form)
            return

        comments_form.validate()
        reviewer = Student.get_by_email(comments_form.review_source.data)
        if not reviewer:
            comments_form.review_source.errors.append("Could not find a user with that e-mail address")
            self.render_edit(badge_form, comments_form)
            return

        page = WikiPage.get_page(student, unit=UNIT_NUMBER)
        if not page:
            self.abort(404, Markup('Could not find unit %d wikifolio for student "%s"') % (UNIT_NUMBER, student_email))

        old_reviews = Annotation.reviews(whose=student, unit=UNIT_NUMBER).run()
        db.delete(old_reviews)
        Annotation.review(page, who=reviewer, text=comments_form.public_comments.data)

        if not Annotation.endorsements(what=page, who=user).count(limit=1):
            Annotation.endorse(page, who=user, optional_done=True)
        
        badge_form.populate_obj(badge)
        badge.put()

        report = PartReport.on(student, self.get_course(), 4, force_re_run=True, put=False)
        for rep in report.unit_reports:
            rep._run()
            rep.put()
        report.slug = badge_slug
        report.put()
        assertion = Badge.issue(badge, student, put=False)
        assertion.evidence = urljoin(self.request.host_url, '/badges/evidence?id=%d' % report.key().id())
        assertion.put()
        self.response.write(
                Markup("Issued badge %s to %s, evidence %s") % (
                    badge.key().name(), student_email, assertion.evidence))
Beispiel #16
0
    def get_view(self):
        if not Roles.is_course_admin(self.app_context):
            self.abort(403)

        job_id = self.request.GET.get('job_id', None)
        if not job_id:
            self.abort(404)

        result = TableMakerResult(job_id)
        fields = result.fields
        self.render_as_table(fields, result)
Beispiel #17
0
 def initialize_page_and_get_user(self):
     """Add basic fields to template and return user."""
     self.template_values['course_info'] = Courses.COURSE_TEMPLATE_DICT
     self.template_values['course_info']['course'] = {'locale': LOCALE}
     user = users.get_current_user()
     if not user:
         self.template_values['loginUrl'] = users.create_login_url('/')
     else:
         self.template_values['email'] = user.email()
         self.template_values['is_super_admin'] = Roles.is_super_admin()
         self.template_values['logoutUrl'] = users.create_logout_url('/')
     return user
    def test_editor_hooks(self):
        module1 = Module('module1', '', [], [])
        module2 = Module('module2', '', [], [])
        module3 = Module('module3', '', [], [])
        module4 = Module('module4', '', [], [])
        Roles.register_permissions(module1, lambda unused: [
            Permission('permissiona', 'a'), Permission('permissionb', 'b')])

        Roles.register_permissions(module2, lambda unused: [
            Permission('permissionc', 'c'), Permission('permissiond', 'd')])
        Roles.register_permissions(module4, lambda unused: [
            Permission('permissiong', 'g'), Permission('permissiond', 'h')])
        handler = RoleRESTHandler()
        handler.course = self.course

        datastore_permissions = {
            module1.name: ['permission', 'permissiona', 'permissionb'],
            module2.name: ['permissionc', 'permissiond'],
            module3.name: ['permissione', 'permissionf']
        }
        datastore_dict = {
            'name': 'Role Name',
            'users': ['*****@*****.**', '*****@*****.**'],
            'permissions': datastore_permissions
        }
        editor_dict = handler.transform_for_editor_hook(datastore_dict)
        self.assertEquals(editor_dict['name'], 'Role Name')
        self.assertEquals(editor_dict['users'], '[email protected], [email protected]')
        modules = editor_dict['modules']
        # Test registered assigned permission
        permissionc = modules[module2.name][0]
        self.assertEquals(permissionc['assigned'], True)
        self.assertEquals(permissionc['name'], 'permissionc')
        self.assertEquals(permissionc['description'], 'c')
        # Test unregistered module with assigned permission
        permissionsf = modules[RoleRESTHandler.INACTIVE_MODULES][1]
        self.assertEquals(permissionsf['assigned'], True)
        self.assertEquals(permissionsf['name'], 'permissionf')
        self.assertEquals(
            permissionsf['description'],
            'This permission was set by the module "module3" which is '
            'currently not registered.'
        )
        # Test registered module with assigned unregistered permission
        permission = modules[module1.name][2]
        self.assertEquals(permission['assigned'], True)
        self.assertEquals(permission['name'], 'permission')
        self.assertEquals(
            permission['description'],
            'This permission is currently not registered.'
        )
        # Test registered unassigned permissions
        permissiong = editor_dict['modules'][module4.name][0]
        self.assertEquals(permissiong['assigned'], False)
        self.assertEquals(permissiong['name'], 'permissiong')
        self.assertEquals(permissiong['description'], 'g')
        # Call the hook which gets called when saving
        new_datastore_dict = handler.transform_after_editor_hook(datastore_dict)
        # If original dict matches new dict then both hooks work correctly
        self.assertEquals(datastore_dict, new_datastore_dict)
Beispiel #19
0
    def get_template(self, template_file, additional_dir=None):
        """Computes location of template files for the current namespace."""
        self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
        self.template_value['is_course_admin'] = Roles.is_course_admin(
            self.app_context)
        self.template_value['is_super_admin'] = Roles.is_super_admin()
        self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)

        template_dir = self.app_context.get_template_home()
        dirs = [template_dir]
        if additional_dir:
            dirs += additional_dir

        jinja_environment = jinja2.Environment(
            extensions=['jinja2.ext.i18n'],
            loader=jinja2.FileSystemLoader(dirs))
        jinja_environment.install_gettext_translations(i18n)

        locale = self.template_value[COURSE_INFO_KEY]['course']['locale']
        i18n.get_i18n().set_locale(locale)

        return jinja_environment.get_template(template_file)
Beispiel #20
0
    def post_start(self):
        if not Roles.is_course_admin(self.app_context):
            self.abort(403)

        form = self.NavForm(self.request.POST)
        if not form.validate():
            self.render_form(form)
            return

        query_class = mapper_queries[form.query.data]
        mapper = query_class(course=self.get_course(), unit=form.unit.data, host_url=self.request.host_url)
        assert isinstance(mapper, TableMakerMapper)
        job_id = mapper.job_id
        deferred.defer(mapper.run, batch_size=50)
        self.redirect(self._action_url('watch', job_id=job_id))
Beispiel #21
0
    def get_edit(self):
        if not Roles.is_course_admin(self.app_context):
            self.abort(403, 'You are not an admin :(')

        student_email = self.request.GET.get('email', None)
        if not student_email:
            self.abort(404, 'email= parameter required')
        student = Student.get_enrolled_student_by_email(student_email)
        if not student:
            self.abort(404, Markup('Could not find a student with email "%s"') % student_email)
        
        badge = Badge.get_or_insert(
                custom_badge_name(student))

        badge_form = BadgeForm(None, badge)
        review = Annotation.reviews(whose=student, unit=UNIT_NUMBER).get()
        comments_form = CommentsForm()
        if review:
            comments_form.public_comments.data = review.reason
            comments_form.review_source.data = review.who.key().name()
        self.render_edit(badge_form, comments_form)
Beispiel #22
0
    def __init__(self, course, prefs=None):
        if prefs is None:
            prefs = models.StudentPreferencesDAO.load_or_create()

        # Fetch all the hooks.  Since these are coming from the course
        # settings, getting them all is not too inefficient.
        self.content = self.get_all(course)

        # Call callbacks to let extension modules know we have text loaded,
        # in case they need to modify, replace, or extend anything.
        for callback in self.POST_LOAD_CALLBACKS:
            callback(self.content)

        # When the course admin sees hooks, we may need to add nonblank
        # text so the admin can have a place to click to edit them.
        self.show_admin_content = False
        if prefs and prefs.show_hooks and Roles.is_course_admin(course.app_context):
            self.show_admin_content = True
        if course.version == courses.CourseModel12.VERSION:
            self.show_admin_content = False
        if self.show_admin_content:
            self.update_for_admin()
Beispiel #23
0
    def get_watch(self):
        if not Roles.is_course_admin(self.app_context):
            self.abort(403)

        job_id = self.request.GET.get('job_id', None)
        if not job_id:
            self.abort(404)

        self.prettify()
        result = TableMakerResult(job_id)
        self.template_value['result'] = result
        is_finished = result.is_finished

        continue_links = {}
        if is_finished:
            continue_links['Download as CSV'] = self._action_url('download', job_id=job_id)
            continue_links['View as table'] = self._action_url('view', job_id=job_id)
        self.template_value['continue_links'] = continue_links

        self.template_value['title'] = self.TITLE
        self.template_value['problems'] = []
        self.render('csv_watch.html')
Beispiel #24
0
 def after_save_hook(self):
     Roles.update_permissions_map()
Beispiel #25
0
    def get(self):
        """Handles GET requests."""
        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
        self.template_value['assessment_name'] = assessment_name
        course = self.get_course()
        unit = course.find_unit_by_id(self.unit_id)
        if not unit:
            self.error(404)
            return

        # If the assessment 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

        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)

        self.template_value['navbar'] = {'course': True}
        self.template_value['unit_id'] = self.unit_id
        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) and not student.is_transient:
            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'] = [get_review_received(
                    unit, 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
                configure_readonly_view(unit, submission_contents)

        if not readonly_view:
            submission_contents = None
            if not student.is_transient:
                submission_contents = student_work.Submission.get_contents(
                    unit.unit_id, student.get_key())
            configure_active_view(unit, submission_contents)

        # 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('assessment.html')
Beispiel #26
0
    def get(self):
        """Handles GET requests."""
        student = self.personalize_page_and_get_enrolled(
            supports_transient_student=True)
        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'] = UNIT_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

        if lesson:
            self.template_value['objectives'] = lesson.objectives

        self.template_value['lessons'] = lessons

        # CGL-MOOC-Builder: Set template value for Google Community ID
        self.set_google_community_template_value()

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

        lesson_id = lesson.lesson_id
        self.template_value['lesson_id'] = lesson_id

        # These attributes are needed in order to render questions (with
        # progress indicators) in the lesson body. They are used by the
        # custom component renderers in the assessment_tags module.
        self.student = student
        self.unit_id = unit_id
        self.lesson_id = lesson_id
        self.lesson_is_scored = lesson.scored

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

        # Google Course Builder starts:
        # Format back button.
        #if index == 0:
        #    self.template_value['back_button_url'] = ''
        #else:
        #    prev_lesson = lessons[index - 1]
        #    if self._show_activity_on_separate_page(prev_lesson):
        #        self.template_value['back_button_url'] = (
        #            'activity?unit=%s&lesson=%s' % (
        #                unit_id, prev_lesson.lesson_id))
        #    else:
        #        self.template_value['back_button_url'] = (
        #            'unit?unit=%s&lesson=%s' % (unit_id, prev_lesson.lesson_id))

        # Format next button.
        #if self._show_activity_on_separate_page(lesson):
        #    self.template_value['next_button_url'] = (
        #        'activity?unit=%s&lesson=%s' % (
        #            unit_id, lesson_id))
        #else:
        #    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))
        # Google Course Builder ends

        # CGL-MOOC-Builder starts:
        # Format back button so that it won't go to activity page.
        # Activity is in the same unit page(unit.html)
        if index == 0:
            self.template_value['back_button_url'] = ''
        else:
            prev_lesson = lessons[index - 1]
            self.template_value['back_button_url'] = (
                'unit?unit=%s&lesson=%s' % (unit_id, prev_lesson.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))
        # CGL-MOOC-Builder ends

        # Set template value for units(unit bar)
        self.template_value['units'] = sorted(
            self.get_units(), key = lambda x: int(x.section_id or 0))

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

            # 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_html_accessed(
                student, unit_id, lesson_id)

        # CGL-MOOC-Builder starts:
        # Set template value for activity script
        # because we want to display activity in the unit page(unit.html)
        self.template_value['activity_script_src'] = (
            self.get_course().get_activity_filename(unit_id, lesson_id))
        # Set template value for student 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('unit.html')
Beispiel #27
0
    def get(self):
        """Handles GET requests."""
        student = self.personalize_page_and_get_enrolled()
        if not student:
            return

        if student.playList is None or len(student.playList) == 0:
            return

        resume = self.request.get('resume')
        if resume:
            index = student.playListIndex
        else:
            index = self.request.get('index')

        if not index:
            index = 0
        index = int(index)

        if index >= len(student.playList):
            index = 0

        unit, lesson = get_unit_lesson_from_playlist(self.get_course(), student.playList, index)
        # Extract incoming args
        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'] = UNIT_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('unit.html')
            return

        lesson_id = lesson.lesson_id
        self.template_value['lesson_id'] = lesson_id

        # Format back button.
        if index == 0:
            self.template_value['back_button_url'] = ''
        else:
            prev_unit, prev_lesson = get_unit_lesson_from_playlist(self.get_course(), student.playList, index - 1)
            print 'prev' + prev_unit.unit_id + " : " + str(prev_lesson.lesson_id)
            if prev_lesson.activity:
                self.template_value['back_button_url'] = (
                    'activityplaylist?index=%s' % (index))
            else:
                self.template_value['back_button_url'] = (
                    'unitplaylist?index=%s' % (index - 1))

        # Format next button.
        if lesson.activity:
            self.template_value['next_button_url'] = (
                'activityplaylist?index=%s' % (index))
        else:
            if not index < len(student.playList) - 1:
                self.template_value['next_button_url'] = ''
            else:
                next_unit, next_lesson = get_unit_lesson_from_playlist(self.get_course(), student.playList, index + 1)
                print 'next' + next_unit.unit_id + " : " + str(next_lesson.lesson_id)
                self.template_value['next_button_url'] = (
                    'unitplaylist?index=%s' % (
                        index + 1))
        student.playListIndex = index
        student.put()

            # 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.render('unit.html')
    def get(self):
        """Handles GET requests."""
        student = self.personalize_page_and_get_enrolled(
            supports_transient_student=True)
        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'] = UNIT_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

        if lesson:
            self.template_value['objectives'] = lesson.objectives

        self.template_value['lessons'] = lessons

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

        lesson_id = lesson.lesson_id
        self.template_value['lesson_id'] = lesson_id

        # These attributes are needed in order to render questions (with
        # progress indicators) in the lesson body. They are used by the
        # custom component renderers in the assessment_tags module.
        self.student = student
        self.unit_id = unit_id
        self.lesson_id = lesson_id
        self.lesson_is_scored = lesson.scored

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

        # Format back button.
        if index == 0:
            self.template_value['back_button_url'] = ''
        else:
            prev_lesson = lessons[index - 1]
            self.template_value['back_button_url'] = (
                'unit?unit=%s&lesson=%s' % (unit_id, prev_lesson.lesson_id))

        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 values for student progress
        self.template_value['is_progress_recorded'] = (
            CAN_PERSIST_ACTIVITY_EVENTS.value and not student.is_transient)
        if CAN_PERSIST_ACTIVITY_EVENTS.value:
            self.template_value['lesson_progress'] = (
                self.get_progress_tracker().get_lesson_progress(
                    student, unit_id))

            # 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_html_accessed(
                student, unit_id, lesson_id)

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

        #progress score
        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', '')

        self.template_value['progress'] = (
            self.get_progress_tracker().get_unit_progress(student))

        self.template_value['units'] = self.get_units()
        self.render('unit.html')
Beispiel #29
0
 def can_handle_course_requests(self, context):
     """Reject all, but authors requests, to an unpublished course."""
     return context.now_available or Roles.is_course_admin(context)
    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

        lessons = self.get_lessons(unit_id)

        self.template_value['unit_id'] = unit_id
        self.template_value['lesson_id'] = lesson.lesson_id
        self.template_value['page_type'] = UNIT_PAGE_TYPE

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

        index = lesson.index - 1  # indexes are 1-based
        self.template_value['lessons'] = lessons

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

        # Format back button.
        if index == 0:
            self.template_value['back_button_url'] = ''
        else:
            prev_lesson = lessons[index - 1]
            if prev_lesson.activity:
                self.template_value['back_button_url'] = (
                    'activity?unit=%s&lesson=%s' % (
                        unit_id, prev_lesson.lesson_id))
            else:
                self.template_value['back_button_url'] = (
                    'unit?unit=%s&lesson=%s' % (unit_id, prev_lesson.lesson_id))

        # Format next button.
        if lesson.activity:
            self.template_value['next_button_url'] = (
                'activity?unit=%s&lesson=%s' % (
                    unit_id, lesson.lesson_id))
        else:
            if not 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 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.render('unit.html')
    def get(self):
        """Handles GET requests."""
        student = self.personalize_page_and_get_enrolled(
            supports_transient_student=True)
        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 values for student progress
        self.template_value['is_progress_recorded'] = (
            CAN_PERSIST_ACTIVITY_EVENTS.value and not student.is_transient)
        if CAN_PERSIST_ACTIVITY_EVENTS.value:
            self.template_value['lesson_progress'] = (
                self.get_progress_tracker().get_lesson_progress(
                    student, unit_id))

            # 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.template_value['event_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token('event-post'))

        self.render('activity.html')
Beispiel #32
0
 def can_handle_course_requests(self, context):
     """Reject all, but authors requests, to an unpublished course."""
     return context.now_available or Roles.is_course_admin(context)
Beispiel #33
0
    def post_save(self):
        if not Roles.is_course_admin(self.app_context):
            self.abort(403, 'You are not an admin :(')
        user = self.personalize_page_and_get_enrolled()

        student_email = self.request.GET.get('email', None)
        if not student_email:
            self.abort(404, 'email= parameter required')
        student = Student.get_enrolled_student_by_email(student_email)
        if not student:
            self.abort(
                404,
                Markup('Could not find a student with email "%s"') %
                student_email)

        badge_slug = custom_badge_name(student)
        badge = Badge.get_or_insert(badge_slug)

        badge_form = BadgeForm(self.request.POST, badge)
        comments_form = CommentsForm(self.request.POST)
        if not (badge_form.validate() and comments_form.validate()):
            self.render_edit(badge_form, comments_form)
            return

        comments_form.validate()
        reviewer = Student.get_by_email(comments_form.review_source.data)
        if not reviewer:
            comments_form.review_source.errors.append(
                "Could not find a user with that e-mail address")
            self.render_edit(badge_form, comments_form)
            return

        page = WikiPage.get_page(student, unit=UNIT_NUMBER)
        if not page:
            self.abort(
                404,
                Markup('Could not find unit %d wikifolio for student "%s"') %
                (UNIT_NUMBER, student_email))

        old_reviews = Annotation.reviews(whose=student, unit=UNIT_NUMBER).run()
        db.delete(old_reviews)
        Annotation.review(page,
                          who=reviewer,
                          text=comments_form.public_comments.data)

        if not Annotation.endorsements(what=page, who=user).count(limit=1):
            Annotation.endorse(page, who=user, optional_done=True)

        badge_form.populate_obj(badge)
        badge.put()

        report = PartReport.on(student,
                               self.get_course(),
                               4,
                               force_re_run=True,
                               put=False)
        for rep in report.unit_reports:
            rep._run()
            rep.put()
        report.slug = badge_slug
        report.put()
        assertion = Badge.issue(badge, student, put=False)
        assertion.evidence = urljoin(
            self.request.host_url,
            '/badges/evidence?id=%d' % report.key().id())
        assertion.put()
        self.response.write(
            Markup("Issued badge %s to %s, evidence %s") %
            (badge.key().name(), student_email, assertion.evidence))
    def test_editor_hooks(self):
        module1 = Module('module1', '', [], [])
        module2 = Module('module2', '', [], [])
        module3 = Module('module3', '', [], [])
        module4 = Module('module4', '', [], [])
        Roles.register_permissions(
            module1, lambda unused:
            [Permission('permissiona', 'a'),
             Permission('permissionb', 'b')])

        Roles.register_permissions(
            module2, lambda unused:
            [Permission('permissionc', 'c'),
             Permission('permissiond', 'd')])
        Roles.register_permissions(
            module4, lambda unused:
            [Permission('permissiong', 'g'),
             Permission('permissiond', 'h')])
        handler = RoleRESTHandler()
        handler.course = self.course

        datastore_permissions = {
            module1.name: ['permission', 'permissiona', 'permissionb'],
            module2.name: ['permissionc', 'permissiond'],
            module3.name: ['permissione', 'permissionf']
        }
        datastore_dict = {
            'name': 'Role Name',
            'users': ['*****@*****.**', '*****@*****.**'],
            'permissions': datastore_permissions
        }
        editor_dict = handler.transform_for_editor_hook(datastore_dict)
        self.assertEquals(editor_dict['name'], 'Role Name')
        self.assertEquals(editor_dict['users'],
                          '[email protected], [email protected]')
        modules = editor_dict['modules']
        # Test registered assigned permission
        permissionc = modules[module2.name][0]
        self.assertEquals(permissionc['assigned'], True)
        self.assertEquals(permissionc['name'], 'permissionc')
        self.assertEquals(permissionc['description'], 'c')
        # Test unregistered module with assigned permission
        permissionsf = modules[RoleRESTHandler.INACTIVE_MODULES][1]
        self.assertEquals(permissionsf['assigned'], True)
        self.assertEquals(permissionsf['name'], 'permissionf')
        self.assertEquals(
            permissionsf['description'],
            'This permission was set by the module "module3" which is '
            'currently not registered.')
        # Test registered module with assigned unregistered permission
        permission = modules[module1.name][2]
        self.assertEquals(permission['assigned'], True)
        self.assertEquals(permission['name'], 'permission')
        self.assertEquals(permission['description'],
                          'This permission is currently not registered.')
        # Test registered unassigned permissions
        permissiong = editor_dict['modules'][module4.name][0]
        self.assertEquals(permissiong['assigned'], False)
        self.assertEquals(permissiong['name'], 'permissiong')
        self.assertEquals(permissiong['description'], 'g')
        # Call the hook which gets called when saving
        new_datastore_dict = handler.transform_after_editor_hook(
            datastore_dict)
        # If original dict matches new dict then both hooks work correctly
        self.assertEquals(datastore_dict, new_datastore_dict)
Beispiel #35
0
    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'] = UNIT_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

        if lesson:
            self.template_value['objectives'] = lesson.objectives

        self.template_value['lessons'] = lessons

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

        lesson_id = lesson.lesson_id
        self.template_value['lesson_id'] = lesson_id

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

        # Format back button.
        if index == 0:
            self.template_value['back_button_url'] = ''
        else:
            prev_lesson = lessons[index - 1]
            if prev_lesson.activity:
                self.template_value['back_button_url'] = (
                    'activity?unit=%s&lesson=%s' % (
                        unit_id, prev_lesson.lesson_id))
            else:
                self.template_value['back_button_url'] = (
                    'unit?unit=%s&lesson=%s' % (unit_id, prev_lesson.lesson_id))

        # Format next button.
        if lesson.activity:
            self.template_value['next_button_url'] = (
                'activity?unit=%s&lesson=%s' % (
                    unit_id, lesson_id))
        else:
            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 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))


        if unit.index==6:
            lesson.slides=False;
            lesson.transcript=False;
            lesson.audio=False;

        elif unit.index==7:
            lesson.slides=False;
            lesson.transcript=False;
            lesson.audio=True;

        else:
            lesson.slides=True;
            lesson.transcript=True;
            lesson.audio=True;


        self.render('unit.html')
Beispiel #36
0
 def after_save_hook(self):
     Roles.update_permissions_map()
Beispiel #37
0
 def _can_view(self, fs, stream):
     """Checks if current user can view stream."""
     public = not fs.is_draft(stream)
     return public or Roles.is_course_admin(self.app_context)
Beispiel #38
0
 def get(self):
     if not Roles.is_course_admin(self.app_context):
         self.abort(403)
     from modules.csv import jobs
     job = jobs.the_job()
     deferred.defer(job.run)
Beispiel #39
0
    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')
Beispiel #40
0
 def get_prep(self):
     if not Roles.is_course_admin(self.app_context):
         self.abort(403)
     self.render_form(self.NavForm())