예제 #1
0
    def run(self):
        """Index the course."""
        namespace = namespace_manager.get_namespace()
        logging.info('Running indexing job for namespace %s. Incremental: %s',
                     namespace_manager.get_namespace(), self.incremental)
        app_context = sites.get_app_context_for_namespace(namespace)

        # Make a request URL to make sites.get_course_for_current_request work
        sites.set_path_info(app_context.slug)

        indexing_stats = {
            'deleted_docs': 0,
            'num_indexed_docs': 0,
            'doc_types': collections.Counter(),
            'indexing_time_secs': 0,
            'locales': []
        }
        for locale in app_context.get_allowed_locales():
            stats = clear_index(namespace, locale)
            indexing_stats['deleted_docs'] += stats['deleted_docs']
        for locale in app_context.get_allowed_locales():
            app_context.set_current_locale(locale)
            course = courses.Course(None, app_context=app_context)
            stats = index_all_docs(course, self.incremental)
            indexing_stats['num_indexed_docs'] += stats['num_indexed_docs']
            indexing_stats['doc_types'] += stats['doc_types']
            indexing_stats['indexing_time_secs'] += stats['indexing_time_secs']
            indexing_stats['locales'].append(locale)
        return indexing_stats
예제 #2
0
    def run(self):
        """Index the course."""
        namespace = namespace_manager.get_namespace()
        logging.info('Running indexing job for namespace %s. Incremental: %s',
                     namespace_manager.get_namespace(), self.incremental)
        app_context = sites.get_app_context_for_namespace(namespace)

        # Make a request URL to make sites.get_course_for_current_request work
        sites.set_path_info(app_context.slug)

        indexing_stats = {
            'deleted_docs': 0,
            'num_indexed_docs': 0,
            'doc_types': collections.Counter(),
            'indexing_time_secs': 0,
            'locales': []
        }
        for locale in app_context.get_allowed_locales():
            stats = clear_index(namespace, locale)
            indexing_stats['deleted_docs'] += stats['deleted_docs']
        for locale in app_context.get_allowed_locales():
            app_context.set_current_locale(locale)
            course = courses.Course(None, app_context=app_context)
            stats = index_all_docs(course, self.incremental)
            indexing_stats['num_indexed_docs'] += stats['num_indexed_docs']
            indexing_stats['doc_types'] += stats['doc_types']
            indexing_stats['indexing_time_secs'] += stats['indexing_time_secs']
            indexing_stats['locales'].append(locale)
        return indexing_stats
    def test_announcement_i18n_title(self):
        locale = 'de'
        announcement = self._add_announcement_and_translation(locale)
        actions.login('*****@*****.**')
        actions.register(self, 'John Doe')

        # Verify that one-off title translation also works.
        try:
            sites.set_path_info('/' + self.COURSE)
            ctx = sites.get_course_for_current_request()
            save_locale = ctx.get_current_locale()
            key = announcements.TranslatableResourceAnnouncement.key_for_entity(
                announcement)

            # Untranslated
            ctx.set_current_locale(None)
            i18n_title = str(
                announcements.TranslatableResourceAnnouncement.get_i18n_title(
                    key))
            self.assertEquals('Test Announcement', i18n_title)

            # Translated
            ctx.set_current_locale(locale)
            i18n_title = str(
                announcements.TranslatableResourceAnnouncement.get_i18n_title(
                    key))
            self.assertEquals('TEST ANNOUNCEMENT', i18n_title)
        finally:
            ctx.set_current_locale(save_locale)
            sites.unset_path_info()
    def test_announcement_i18n_title(self):
        locale = 'de'
        announcement = self._add_announcement_and_translation(locale)
        actions.login('*****@*****.**')
        actions.register(self, 'John Doe')

        # Verify that one-off title translation also works.
        try:
            sites.set_path_info('/' + self.COURSE)
            ctx = sites.get_course_for_current_request()
            save_locale = ctx.get_current_locale()
            key = announcements.TranslatableResourceAnnouncement.key_for_entity(
                announcement)

            # Untranslated
            ctx.set_current_locale(None)
            i18n_title = str(
                announcements.TranslatableResourceAnnouncement.get_i18n_title(
                    key))
            self.assertEquals('Test Announcement', i18n_title)

            # Translated
            ctx.set_current_locale(locale)
            i18n_title = str(
                announcements.TranslatableResourceAnnouncement.get_i18n_title(
                    key))
            self.assertEquals('TEST ANNOUNCEMENT', i18n_title)
        finally:
            ctx.set_current_locale(save_locale)
            sites.unset_path_info()
예제 #5
0
    def run(self):
        """Index the course."""
        namespace = namespace_manager.get_namespace()
        logging.info(
            "Running indexing job for namespace %s. Incremental: %s",
            namespace_manager.get_namespace(),
            self.incremental,
        )
        app_context = sites.get_app_context_for_namespace(namespace)

        # Make a request URL to make sites.get_course_for_current_request work
        sites.set_path_info(app_context.slug)

        indexing_stats = {
            "num_indexed_docs": 0,
            "doc_types": collections.Counter(),
            "indexing_time_secs": 0,
            "locales": [],
        }
        for locale in app_context.get_allowed_locales():
            app_context.set_current_locale(locale)
            course = courses.Course(None, app_context=app_context)
            stats = index_all_docs(course, self.incremental)
            indexing_stats["num_indexed_docs"] += stats["num_indexed_docs"]
            indexing_stats["doc_types"] += stats["doc_types"]
            indexing_stats["indexing_time_secs"] += stats["indexing_time_secs"]
            indexing_stats["locales"].append(locale)

        return indexing_stats
예제 #6
0
    def run(self):
        app_context = self._get_app_context_or_die(
            self.etl_args.course_url_prefix)
        course = courses.Course(None, app_context=app_context)

        sites.set_path_info(app_context.slug)
        courses.Course.set_current(course)
        try:
            with common_utils.Namespace(app_context.get_namespace_name()):
                super(CourseJob, self).run()
        finally:
            courses.Course.clear_current()
            sites.unset_path_info()
예제 #7
0
    def run(self):
        app_context = self._get_app_context_or_die(
            self.etl_args.course_url_prefix)
        course = courses.Course(None, app_context=app_context)

        sites.set_path_info(app_context.slug)
        courses.Course.set_current(course)
        try:
            with common_utils.Namespace(app_context.get_namespace_name()):
                super(CourseJob, self).run()
        finally:
            courses.Course.clear_current()
            sites.unset_path_info()
예제 #8
0
def check_personalization(browser, response):
    """Checks that the login/logout text is correct."""
    sites.set_path_info(browser.last_request_url)
    app_context = sites.get_course_for_current_request()
    sites.unset_path_info()

    browsable = app_context.get_environ()['course']['browsable']

    if browsable:
        callbacks = [
            functools.partial(check_login_link, response.body),
            functools.partial(check_logout_link, response.body)
        ]
        assert_at_least_one_succeeds(callbacks)
    else:
        check_logout_link(response.body)
예제 #9
0
    def __init__(self, request, response):  # pylint: disable=super-init-not-called
        self.initialize(request, response)
        # Check to see if the current user is admin
        self.is_admin = users.is_current_user_admin()

        # Store the original namespace, before setting the course specific one.
        self.old_namespace = namespace_manager.get_namespace()

        # Set the active namespace to the course domain namespace
        try:
            sites.set_path_info(self.request.path, self.request.server_name)
        except AttributeError as e:
            logging.error(e)

        namespace = namespace_manager.get_namespace()

        if namespace:
            self.app_context = sites.get_course_for_current_request()
            self.is_admin = roles.Roles.is_course_admin(self.app_context)
            is_public = self.app_context.now_available

            if self.is_admin is False and is_public is False:
                # if course is private, and user has not logged in, redirect to login
                # else if user is logged in and not admin, 404
                if not users.get_current_user():
                    self.redirect(users.create_login_url(self.request.path))
                else:
                    self.abort(404)

            # Set the current user with their preferences
            self.student = StudentSvc.get_current_student()
            if self.student:
                self.student.prefs = StudentSvc.get_current_user_preferences()

        if self.current_user:
            self._xsrf_token = xsrf.GenerateToken(_GetXsrfKey(),
                                                  self.current_user.email())
            self.response.set_cookie('XSRF-TOKEN', self._xsrf_token, httponly=False)
        else:
            self._xsrf_token = None
        self._RawWrite = self.response.out.write

        # Get a session store for this request.
        self.session_store = sessions.get_store(request=self.request)

        # Set the active locale
        self.locale_key = LocaleSvc.get_locale_key('en_GB')
예제 #10
0
    def run(self):
        """Override run() and setup app_context, course and a namespace."""
        # ETL import model is complex; run this import here not to interfere
        from controllers import sites

        app_context = self._get_app_context_or_die(
            self.etl_args.course_url_prefix)
        course = courses.Course(None, app_context=app_context)

        sites.set_path_info(app_context.slug)
        courses.Course.set_current(course)
        try:
            with common_utils.Namespace(app_context.get_namespace_name()):
                super(_BaseJob, self).run()
        finally:
            courses.Course.clear_current()
            sites.unset_path_info()
예제 #11
0
    def run(self):
        """Override run() and setup app_context, course and a namespace."""
        # ETL import model is complex; run this import here not to interfere
        from controllers import sites

        app_context = self._get_app_context_or_die(
            self.etl_args.course_url_prefix)
        course = courses.Course(None, app_context=app_context)

        sites.set_path_info(app_context.slug)
        courses.Course.set_current(course)
        try:
            with common_utils.Namespace(app_context.get_namespace_name()):
                super(_BaseJob, self).run()
        finally:
            courses.Course.clear_current()
            sites.unset_path_info()