Beispiel #1
0
    def test_render_js_init(self):
        widget = widgets.AdminPageChooser()

        js_init = widget.render_js_init('test-id', 'test', None)
        self.assertEqual(
            js_init,
            "createPageChooser(\"test-id\", [\"wagtailcore.page\"], null);")
Beispiel #2
0
    def test_render_html_with_value(self):
        widget = widgets.AdminPageChooser()

        html = widget.render_html('test', self.child_page, {})
        self.assertInHTML(
            """<input name="test" type="hidden" value="%d" />""" %
            self.child_page.id, html)
Beispiel #3
0
    def test_render_html_with_value(self):
        widget = widgets.AdminPageChooser()

        html = widget.render_html('test', self.child_page, {})
        self.assertIn(
            "<input name=\"test\" type=\"hidden\" value=\"%d\" />" %
            self.child_page.id, html)
Beispiel #4
0
    def test_render_js_init_with_target_model(self):
        widget = widgets.AdminPageChooser(target_models=[SimplePage])

        js_init = widget.render_js_init('test-id', 'test', None)
        self.assertEqual(
            js_init,
            "createPageChooser(\"test-id\", [\"tests.simplepage\"], null, false);"
        )
Beispiel #5
0
    def test_render_js_init_with_content_type(self):
        content_type = ContentType.objects.get_for_model(SimplePage)
        widget = widgets.AdminPageChooser(content_type=content_type)

        js_init = widget.render_js_init('test-id', 'test', None)
        self.assertEqual(
            js_init,
            "createPageChooser(\"test-id\", [\"tests.simplepage\"], null);")
Beispiel #6
0
    def test_render_js_init_with_can_choose_root(self):
        widget = widgets.AdminPageChooser(can_choose_root=True)

        js_init = widget.render_js_init('test-id', 'test', self.child_page)
        self.assertEqual(
            js_init,
            "createPageChooser(\"test-id\", [\"wagtailcore.page\"], %d, true, null);"
            % self.root_page.id)
Beispiel #7
0
    def test_render_js_init_with_value(self):
        widget = widgets.AdminPageChooser()

        js_init = widget.render_js_init('test-id', 'test', self.child_page)
        self.assertEqual(
            js_init,
            "createPageChooser(\"test-id\", [\"wagtailcore.page\"], %d, false);"
            % self.root_page.id)
Beispiel #8
0
    def test_render_js_init_with_user_perm(self):
        widget = widgets.AdminPageChooser(user_perms='copy_to')

        js_init = widget.render_js_init('test-id', 'test', None)
        self.assertEqual(
            js_init,
            "createPageChooser(\"test-id\", [\"wagtailcore.page\"], null, false, \"copy_to\");"
        )
Beispiel #9
0
    def test_render_js_init_with_content_type(self):
        with warnings.catch_warnings(record=True) as ws:
            warnings.simplefilter('always')
            content_type = ContentType.objects.get_for_model(SimplePage)
            widget = widgets.AdminPageChooser(content_type=content_type)

            self.assertEqual(len(ws), 1)
            self.assertIs(ws[0].category, RemovedInWagtail17Warning)
        self.assertEqual(widget.target_models, [SimplePage])
Beispiel #10
0
    def test_render_js_init_with_multiple_content_types(self):
        content_types = [
            # Not using get_for_models as we need deterministic ordering
            ContentType.objects.get_for_model(SimplePage),
            ContentType.objects.get_for_model(EventPage),
        ]
        widget = widgets.AdminPageChooser(content_type=content_types)

        js_init = widget.render_js_init('test-id', 'test', None)
        self.assertEqual(js_init, "createPageChooser(\"test-id\", [\"tests.simplepage\", \"tests.eventpage\"], null, false);")
Beispiel #11
0
    def test_render_js_init_with_target_model(self):
        widget = widgets.AdminPageChooser(target_models=[SimplePage])

        js_init = widget.render_js_init('test-id', 'test', None)
        self.assertEqual(
            js_init,
            "createPageChooser(\"test-id\", [\"tests.simplepage\"], null, false, null);"
        )

        html = widget.render_html('test', self.child_page, {})
        self.assertIn(">Choose a page (Simple Page)<", html)
Beispiel #12
0
    def __init__(self, *args, **kwargs):
        # CopyPage must be passed a 'page' kwarg indicating the page to be copied
        self.page = kwargs.pop('page')
        self.user = kwargs.pop('user', None)
        can_publish = kwargs.pop('can_publish')
        super(CopyForm, self).__init__(*args, **kwargs)
        self.fields['new_title'] = forms.CharField(initial=self.page.title,
                                                   label=_("New title"))
        self.fields['new_slug'] = forms.SlugField(initial=self.page.slug,
                                                  label=_("New slug"))
        self.fields['new_parent_page'] = forms.ModelChoiceField(
            initial=self.page.get_parent(),
            queryset=Page.objects.all(),
            widget=widgets.AdminPageChooser(can_choose_root=True,
                                            user_perms='copy_to'),
            label=_("New parent page"),
            help_text=_(
                "This copy will be a child of this given parent page."))
        pages_to_copy = self.page.get_descendants(inclusive=True)
        subpage_count = pages_to_copy.count() - 1
        if subpage_count > 0:
            self.fields['copy_subpages'] = forms.BooleanField(
                required=False,
                initial=True,
                label=_("Copy subpages"),
                help_text=ungettext("This will copy %(count)s subpage.",
                                    "This will copy %(count)s subpages.",
                                    subpage_count) % {'count': subpage_count})

        if can_publish:
            pages_to_publish_count = pages_to_copy.live().count()
            if pages_to_publish_count > 0:
                # In the specific case that there are no subpages, customise the field label and help text
                if subpage_count == 0:
                    label = _("Publish copied page")
                    help_text = _(
                        "This page is live. Would you like to publish its copy as well?"
                    )
                else:
                    label = _("Publish copies")
                    help_text = ungettext(
                        "%(count)s of the pages being copied is live. Would you like to publish its copy?",
                        "%(count)s of the pages being copied are live. Would you like to publish their copies?",
                        pages_to_publish_count) % {
                            'count': pages_to_publish_count
                        }

                self.fields['publish_copies'] = forms.BooleanField(
                    required=False,
                    initial=True,
                    label=label,
                    help_text=help_text)
Beispiel #13
0
    def test_render_js_init_with_multiple_content_types(self):
        with warnings.catch_warnings(record=True) as ws:
            warnings.simplefilter('always')
            content_types = [
                # Not using get_for_models as we need deterministic ordering
                ContentType.objects.get_for_model(SimplePage),
                ContentType.objects.get_for_model(EventPage),
            ]
            widget = widgets.AdminPageChooser(content_type=content_types)

            self.assertEqual(len(ws), 1)
            self.assertIs(ws[0].category, RemovedInWagtail17Warning)
        self.assertEqual(widget.target_models, [SimplePage, EventPage])
Beispiel #14
0
    def test_render_html(self):
        widget = widgets.AdminPageChooser()

        html = widget.render_html('test', None, {})
        self.assertInHTML("""<input name="test" type="hidden" />""", html)
        self.assertIn(">Choose a page<", html)
Beispiel #15
0
 def test_not_hidden(self):
     widget = widgets.AdminPageChooser()
     self.assertFalse(widget.is_hidden)
Beispiel #16
0
    def test_render_html(self):
        widget = widgets.AdminPageChooser()

        html = widget.render_html('test', None, {})
        self.assertIn("<input name=\"test\" type=\"hidden\" />", html)
Beispiel #17
0
 def widget_overrides(cls):
     return {
         cls.field_name:
         widgets.AdminPageChooser(content_type=cls.target_content_type(),
                                  can_choose_root=cls.can_choose_root)
     }
Beispiel #18
0
 def widget_overrides(cls):
     return {
         cls.field_name:
         widgets.AdminPageChooser(target_models=cls.target_models(),
                                  can_choose_root=cls.can_choose_root)
     }