Пример #1
0
def check_copy_relations(output):
    c_to_s = lambda klass: '%s.%s' % (klass.__module__, klass.__name__)
    with output.section('Presence of "copy_relations"') as section:
        plugin_pool.discover_plugins()
        for plugin in plugin_pool.plugins.values():
            plugin_class = plugin.model
            if 'copy_relations' in plugin_class.__dict__:
                # this class defines a ``copy_relations`` method, nothing more
                # to do
                continue
            for rel in plugin_class._meta.many_to_many:
                section.warn('%s has a many-to-many relation to %s,\n    but no "copy_relations" method defined.' % (
                    c_to_s(plugin_class),
                    c_to_s(rel.model),
                ))
            for rel in plugin_class._meta.get_all_related_objects():
                if rel.model != CMSPlugin:
                    section.warn('%s has a foreign key from %s,\n    but no "copy_relations" method defined.' % (
                        c_to_s(plugin_class),
                        c_to_s(rel.model),
                    ))
        if not section.warnings:
            section.finish_success('All plugins have "copy_relations" method if needed.')
        else:
            section.finish_success('Some plugins do not define a "copy_relations" method.\nThis might lead to data loss when publishing or copying plugins.\nSee https://django-cms.readthedocs.org/en/latest/extending_cms/custom_plugins.html#handling-relations')
Пример #2
0
def check_copy_relations(output):
    from cms.plugin_pool import plugin_pool
    from cms.extensions import extension_pool
    from cms.extensions.models import BaseExtension
    from cms.models.pluginmodel import CMSPlugin

    def c_to_s(klass):
        return '%s.%s' % (klass.__module__, klass.__name__)

    def get_class(method_name, model):
        for cls in inspect.getmro(model):
            if method_name in cls.__dict__:
                return cls
        return None

    with output.section('Presence of "copy_relations"') as section:
        plugin_pool.discover_plugins()
        for plugin in plugin_pool.plugins.values():
            plugin_class = plugin.model
            if get_class('copy_relations', plugin_class) is not CMSPlugin or plugin_class is CMSPlugin:
                # this class defines a ``copy_relations`` method, nothing more
                # to do
                continue
            for rel in plugin_class._meta.many_to_many:
                section.warn('%s has a many-to-many relation to %s,\n    but no "copy_relations" method defined.' % (
                    c_to_s(plugin_class),
                    c_to_s(rel.model),
                ))
            for rel in plugin_class._get_related_objects():
                if rel.model != CMSPlugin and not issubclass(rel.model, plugin.model) and rel.model != AliasPluginModel:
                    section.warn('%s has a foreign key from %s,\n    but no "copy_relations" method defined.' % (
                        c_to_s(plugin_class),
                        c_to_s(rel.model),
                    ))

        for extension in chain(extension_pool.page_extensions, extension_pool.title_extensions):
            if get_class('copy_relations', extension) is not BaseExtension:
                # OK, looks like there is a 'copy_relations' defined in the
                # extension... move along...
                continue
            for rel in extension._meta.many_to_many:
                section.warn('%s has a many-to-many relation to %s,\n    '
                             'but no "copy_relations" method defined.' % (
                    c_to_s(extension),
                    c_to_s(rel.remote_field.model),
                ))
            for rel in extension._get_related_objects():
                if rel.model != extension:
                    section.warn('%s has a foreign key from %s,\n    but no "copy_relations" method defined.' % (
                        c_to_s(extension),
                        c_to_s(rel.model),
                    ))

        if not section.warnings:
            section.finish_success('All plugins and page/title extensions have "copy_relations" method if needed.')
        else:
            section.finish_success('Some plugins or page/title extensions do not define a "copy_relations" method.\n'
                                   'This might lead to data loss when publishing or copying plugins/extensions.\n'
                                   'See https://django-cms.readthedocs.io/en/latest/extending_cms/custom_plugins.html#handling-relations or '  # noqa
                                   'https://django-cms.readthedocs.io/en/latest/extending_cms/extending_page_title.html#handling-relations.')  # noqa
Пример #3
0
    def test_invalidate_restart(self):

        # Ensure that we're testing in an environment WITHOUT the MW cache...
        exclude = [
            'django.middleware.cache.UpdateCacheMiddleware',
            'django.middleware.cache.FetchFromCacheMiddleware'
        ]
        overrides = dict()
        if getattr(settings, 'MIDDLEWARE', None):
            overrides['MIDDLEWARE'] = [
                mw for mw in settings.MIDDLEWARE if mw not in exclude
            ]
        else:
            overrides['MIDDLEWARE_CLASSES'] = [
                mw for mw in settings.MIDDLEWARE_CLASSES if mw not in exclude
            ]
        with self.settings(**overrides):

            # Silly to do these tests if this setting isn't True
            page_cache_setting = get_cms_setting('PAGE_CACHE')
            self.assertTrue(page_cache_setting)

            # Create a test page
            page1 = create_page('test page 1',
                                'nav_playground.html',
                                'en',
                                published=True)
            page1_url = page1.get_absolute_url()

            # Add some content
            placeholder = page1.placeholders.filter(slot="body")[0]
            add_plugin(placeholder, "TextPlugin", 'en', body="English")
            add_plugin(placeholder, "TextPlugin", 'de', body="Deutsch")

            # Create a request object
            request = self.get_request(page1.get_path(), 'en')

            # Ensure that user is NOT authenticated
            self.assertFalse(request.user.is_authenticated())

            # Test that the page is initially uncached
            with self.assertNumQueries(FuzzyInt(1, 24)):
                response = self.client.get(page1_url)
            self.assertEqual(response.status_code, 200)

            #
            # Test that subsequent requests of the same page are cached by
            # asserting that they require fewer queries.
            #
            with self.assertNumQueries(0):
                response = self.client.get(page1_url)
            self.assertEqual(response.status_code, 200)
            old_plugins = plugin_pool.plugins
            plugin_pool.clear()
            plugin_pool.discover_plugins()
            plugin_pool.plugins = old_plugins
            with self.assertNumQueries(FuzzyInt(1, 20)):
                response = self.client.get(page1_url)
                self.assertEqual(response.status_code, 200)
Пример #4
0
def check_copy_relations(output):
    from cms.plugin_pool import plugin_pool
    from cms.extensions import extension_pool
    from cms.extensions.models import BaseExtension
    from cms.models.pluginmodel import CMSPlugin

    c_to_s = lambda klass: '%s.%s' % (klass.__module__, klass.__name__)

    def get_class(method_name, model):
        for cls in inspect.getmro(model):
            if method_name in cls.__dict__:
                return cls
        return None

    with output.section('Presence of "copy_relations"') as section:
        plugin_pool.discover_plugins()
        for plugin in plugin_pool.plugins.values():
            plugin_class = plugin.model
            if get_class('copy_relations', plugin_class) is not CMSPlugin or plugin_class is CMSPlugin:
                # this class defines a ``copy_relations`` method, nothing more
                # to do
                continue
            for rel in plugin_class._meta.many_to_many:
                section.warn('%s has a many-to-many relation to %s,\n    but no "copy_relations" method defined.' % (
                    c_to_s(plugin_class),
                    c_to_s(rel.model),
                ))
            for rel in plugin_class._meta.get_all_related_objects():
                if rel.model != CMSPlugin and rel.model != AliasPluginModel:
                    section.warn('%s has a foreign key from %s,\n    but no "copy_relations" method defined.' % (
                        c_to_s(plugin_class),
                        c_to_s(rel.model),
                    ))

        for extension in chain(extension_pool.page_extensions, extension_pool.title_extensions):
            if get_class('copy_relations', extension) is not BaseExtension:
                # OK, looks like there is a 'copy_relations' defined in the
                # extension... move along...
                continue
            for rel in extension._meta.many_to_many:
                section.warn('%s has a many-to-many relation to %s,\n    but no "copy_relations" method defined.' % (
                    c_to_s(extension),
                    c_to_s(rel.related.parent_model),
                ))
            for rel in extension._meta.get_all_related_objects():
                if rel.model != extension:
                    section.warn('%s has a foreign key from %s,\n    but no "copy_relations" method defined.' % (
                        c_to_s(extension),
                        c_to_s(rel.model),
                    ))

        if not section.warnings:
            section.finish_success('All plugins and page/title extensions have "copy_relations" method if needed.')
        else:
            section.finish_success('Some plugins or page/title extensions do not define a "copy_relations" method.\nThis might lead to data loss when publishing or copying plugins/extensions.\nSee https://django-cms.readthedocs.org/en/latest/extending_cms/custom_plugins.html#handling-relations or https://django-cms.readthedocs.org/en/latest/extending_cms/extending_page_title.html#handling-relations.')
Пример #5
0
    def test_invalidate_restart(self):

        # Ensure that we're testing in an environment WITHOUT the MW cache...
        exclude = [
            'django.middleware.cache.UpdateCacheMiddleware',
            'django.middleware.cache.FetchFromCacheMiddleware'
        ]
        overrides = dict()
        if getattr(settings, 'MIDDLEWARE', None):
            overrides['MIDDLEWARE'] = [mw for mw in settings.MIDDLEWARE if mw not in exclude]
        else:
            overrides['MIDDLEWARE_CLASSES'] = [mw for mw in settings.MIDDLEWARE_CLASSES if mw not in exclude]
        with self.settings(**overrides):

            # Silly to do these tests if this setting isn't True
            page_cache_setting = get_cms_setting('PAGE_CACHE')
            self.assertTrue(page_cache_setting)

            # Create a test page
            page1 = create_page('test page 1', 'nav_playground.html', 'en', published=True)

            # Add some content
            placeholder = page1.placeholders.filter(slot="body")[0]
            add_plugin(placeholder, "TextPlugin", 'en', body="English")
            add_plugin(placeholder, "TextPlugin", 'de', body="Deutsch")

            # Create a request object
            request = self.get_request(page1.get_path(), 'en')

            # Ensure that user is NOT authenticated
            self.assertFalse(request.user.is_authenticated())

            # Test that the page is initially uncached
            with self.assertNumQueries(FuzzyInt(1, 24)):
                response = self.client.get('/en/')
            self.assertEqual(response.status_code, 200)

            #
            # Test that subsequent requests of the same page are cached by
            # asserting that they require fewer queries.
            #
            with self.assertNumQueries(0):
                response = self.client.get('/en/')
            self.assertEqual(response.status_code, 200)
            old_plugins = plugin_pool.plugins
            plugin_pool.clear()
            plugin_pool.discover_plugins()
            plugin_pool.plugins = old_plugins
            with self.assertNumQueries(FuzzyInt(1, 20)):
                response = self.client.get('/en/')
                self.assertEqual(response.status_code, 200)
Пример #6
0
    def test_invalidate_restart(self):
        # Clear the entire cache for a clean slate
        cache.clear()

        # Ensure that we're testing in an environment WITHOUT the MW cache...
        exclude = ["django.middleware.cache.UpdateCacheMiddleware", "django.middleware.cache.FetchFromCacheMiddleware"]
        mw_classes = [mw for mw in settings.MIDDLEWARE_CLASSES if mw not in exclude]

        with SettingsOverride(MIDDLEWARE_CLASSES=mw_classes):

            # Silly to do these tests if this setting isn't True
            page_cache_setting = get_cms_setting("PAGE_CACHE")
            self.assertTrue(page_cache_setting)

            # Create a test page
            page1 = create_page("test page 1", "nav_playground.html", "en", published=True)

            # Add some content
            placeholder = page1.placeholders.filter(slot="body")[0]
            add_plugin(placeholder, "TextPlugin", "en", body="English")
            add_plugin(placeholder, "TextPlugin", "de", body="Deutsch")

            # Create a request object
            request = self.get_request(page1.get_path(), "en")

            # Ensure that user is NOT authenticated
            self.assertFalse(request.user.is_authenticated())

            # Test that the page is initially uncached
            with self.assertNumQueries(FuzzyInt(1, 20)):
                response = self.client.get("/en/")
            self.assertEqual(response.status_code, 200)

            #
            # Test that subsequent requests of the same page are cached by
            # asserting that they require fewer queries.
            #
            with self.assertNumQueries(0):
                response = self.client.get("/en/")
            self.assertEqual(response.status_code, 200)
            old_plugins = plugin_pool.plugins
            plugin_pool.clear()
            plugin_pool.discover_plugins()
            plugin_pool.plugins = old_plugins
            with self.assertNumQueries(FuzzyInt(1, 20)):
                response = self.client.get("/en/")
                self.assertEqual(response.status_code, 200)