Esempio n. 1
0
    def ready(self):
        from wagtail.core.signals import page_slug_changed, post_page_move

        from .signal_handlers import (autocreate_redirects_on_page_move,
                                      autocreate_redirects_on_slug_change)

        post_page_move.connect(autocreate_redirects_on_page_move)
        page_slug_changed.connect(autocreate_redirects_on_slug_change)
Esempio n. 2
0
    def test_bulk_move_triggers_signals(self):
        # Connect a mock signal handler to pre_page_move and post_page_move signals
        pre_moved_handler = mock.MagicMock()
        post_moved_handler = mock.MagicMock()

        pre_page_move.connect(pre_moved_handler)
        post_page_move.connect(post_moved_handler)

        # Post to view confirm move page
        try:
            self.client.post(self.url, {'chooser': self.section_b.id})
        finally:
            # Disconnect mock handler to prevent cross-test pollution
            pre_page_move.disconnect(pre_moved_handler)
            post_page_move.disconnect(post_moved_handler)

        # Check that the pre_page_move signals were fired
        self.assertTrue(pre_moved_handler.mock_calls[0].called_with(
            sender=self.test_page_b.specific_class,
            instance=self.test_page_b,
            parent_page_before=self.section_c,
            parent_page_after=self.section_b,
            url_path_before='/home/section-c/hello-world-b/',
            url_path_after='/home/section-b/hello-world-b/',
        ))
        self.assertTrue(pre_moved_handler.mock_calls[1].called_with(
            sender=self.test_page_b_1.specific_class,
            instance=self.test_page_b_1,
            parent_page_before=self.section_c,
            parent_page_after=self.section_b,
            url_path_before='/home/section-c/hello-world-b-1/',
            url_path_after='/home/section-b/hello-world-b-1/',
        ))

        # Check that the post_page_move signals were fired
        self.assertTrue(post_moved_handler.mock_calls[0].called_with(
            sender=self.test_page_b.specific_class,
            instance=self.test_page_b,
            parent_page_before=self.section_c,
            parent_page_after=self.section_b,
            url_path_before='/home/section-c/hello-world-b/',
            url_path_after='/home/section-b/hello-world-b/',
        ))
        self.assertTrue(post_moved_handler.mock_calls[1].called_with(
            sender=self.test_page_b_1.specific_class,
            instance=self.test_page_b_1,
            parent_page_before=self.section_c,
            parent_page_after=self.section_b,
            url_path_before='/home/section-c/hello-world-b-1/',
            url_path_after='/home/section-b/hello-world-b-1/',
        ))
Esempio n. 3
0
    def test_move_triggers_signals(self):
        # Connect a mock signal handler to pre_page_move and post_page_move signals
        pre_moved_handler = mock.MagicMock()
        post_moved_handler = mock.MagicMock()

        pre_page_move.connect(pre_moved_handler)
        post_page_move.connect(post_moved_handler)

        # Post to view to move page
        try:
            self.client.post(
                reverse(
                    "wagtailadmin_pages:move_confirm",
                    args=(self.test_page_a.id, self.section_b.id),
                ))
        finally:
            # Disconnect mock handler to prevent cross-test pollution
            pre_page_move.disconnect(pre_moved_handler)
            post_page_move.disconnect(post_moved_handler)

        # Check that the pre_page_move signal was fired
        self.assertEqual(pre_moved_handler.call_count, 1)
        self.assertTrue(
            pre_moved_handler.called_with(
                sender=self.test_page_a.specific_class,
                instance=self.test_page_a,
                parent_page_before=self.section_a,
                parent_page_after=self.section_b,
                url_path_before="/home/section-a/hello-world/",
                url_path_after="/home/section-b/hello-world/",
            ))

        # Check that the post_page_move signal was fired
        self.assertEqual(post_moved_handler.call_count, 1)
        self.assertTrue(
            post_moved_handler.called_with(
                sender=self.test_page_a.specific_class,
                instance=self.test_page_a,
                parent_page_before=self.section_a,
                parent_page_after=self.section_b,
                url_path_before="/home/section-a/hello-world/",
                url_path_after="/home/section-b/hello-world/",
            ))
Esempio n. 4
0
    def ready(self):
        user_model = get_user_model()
        post_save.connect(user_save_callback, sender=user_model)
        # Interesting situation: we use this pattern to account for
        # scrolling bugs in IE:
        # http://snipplr.com/view/518/
        # yet, url(null) trips up the ManifestStaticFilesStorage, so we
        # monkeypatch the regex so that url(null) is ignored

        storage.HashedFilesMixin.patterns = (("*.css", (
            r"""(url\((?!null)['"]{0,1}\s*(.*?)["']{0,1}\))""",
            (r"""(@import\s*["']\s*(.*?)["'])""", """@import url("%s")"""),
        )), )

        from v1.models.enforcement_action_page import EnforcementActionPage
        page_published.connect(break_enforcement_cache,
                               sender=EnforcementActionPage)
        page_unpublished.connect(break_enforcement_cache,
                                 sender=EnforcementActionPage)
        post_page_move.connect(break_enforcement_cache,
                               sender=EnforcementActionPage)
Esempio n. 5
0
 def setup(self):
     # Wagtail Specific Events
     page_published.connect(self.handle_save)
     page_unpublished.connect(self.handle_delete)
     pre_page_move.connect(self.handle_delete)
     post_page_move.connect(self.handle_save)
Esempio n. 6
0
def register_signal_handlers():
    page_published.connect(create_redirect_object_if_slug_changed)

    if post_page_move is not None:
        post_page_move.connect(create_redirect_object_after_page_move)