Example #1
0
    def test_wizard(self):
        class TestButton(Button):
            id_ = Button.generate_id('creme_config', 'test_wizard')
            verbose_name = 'Testing purpose'

        button_registry.register(TestButton)

        ct = self.contact_ct
        url = self.WIZARD_URL
        ctxt1 = self.assertGET200(url).context
        self.assertEqual(_('New buttons configuration'), ctxt1.get('title'))

        with self.assertNoException():
            ctypes = ctxt1['form'].fields['ctype'].ctypes

        self.assertIn(ct, ctypes)

        # ---
        step_key = 'button_menu_wizard-current_step'
        response2 = self.assertPOST200(
            url,
            data={
                step_key: '0',
                '0-ctype': ct.id,
            },
        )

        ctxt2 = response2.context
        self.assertEqual(
            _('New buttons configuration for «{model}»').format(model=ct),
            ctxt2.get('title'),
        )

        with self.assertNoException():
            choices = ctxt2['form'].fields['button_ids'].choices

        self.assertInChoices(
            value=TestButton.id_,
            label=button_registry.get_button(TestButton.id_),
            choices=choices,
        )

        # --
        response3 = self.client.post(
            url,
            data={
                step_key: '1',
                '1-button_ids': [TestButton.id_],
            },
        )
        self.assertNoFormError(response3)
        self.assertListEqual(
            [(TestButton.id_, 1000)],
            [
                *ButtonMenuItem.objects
                               .filter(content_type=ct)
                               .values_list('button_id', 'order'),
            ],
        )
Example #2
0
    def test_edit02(self):
        "Edit the default configuration."
        class TestButton(Button):
            id_ = Button.generate_id('creme_config', 'test_edit02')
            verbose_name = 'Testing purpose'

        button_registry.register(TestButton)

        url = reverse('creme_config__edit_ctype_buttons', args=(0,))
        response = self.assertGET200(url)
        self.assertTemplateUsed(response, 'creme_core/generics/blockform/edit-popup.html')

        context = response.context
        self.assertEqual(_('Edit default configuration'), context.get('title'))
        self.assertEqual(_('Save the modifications'),     context.get('submit_label'))

        with self.assertNoException():
            choices = context['form'].fields['button_ids'].choices

        self.assertInChoices(
            value=TestButton.id_,
            label=button_registry.get_button(TestButton.id_),
            choices=choices,
        )

        response = self.client.post(
            url,
            data={
                'button_ids': TestButton.id_,
            },
        )
        self.assertNoFormError(response)
        self.assertListEqual(
            [(TestButton.id_, 1)],
            [
                *ButtonMenuItem.objects
                               .filter(content_type=None)
                               .values_list('button_id', 'order'),
            ],
        )
Example #3
0
    def __str__(self):
        from creme.creme_core.gui.button_menu import button_registry

        button = button_registry.get_button(self.button_id)
        return str(
            button.verbose_name) if button else gettext('Deprecated button')
Example #4
0
    def test_edit03(self):
        ct = self.contact_ct

        class TestButton01(Button):
            id_ = Button.generate_id('creme_config', 'test_edit03_1')
            verbose_name = 'Test button #1'

        class TestButton02(Button):
            id_ = Button.generate_id('creme_config', 'test_edit03_2')
            verbose_name = 'Test button #2'

            def get_ctypes(self):
                return [FakeContact, FakeOrganisation]

        class TestButton03(Button):
            id_ = Button.generate_id('creme_config', 'test_edit03_3')
            verbose_name = 'Test button #3'

            def get_ctypes(self):
                return [FakeOrganisation]  # No Contact

        button_registry.register(TestButton01, TestButton02, TestButton03)

        ButtonMenuItem.objects.create(content_type=ct, order=1)

        url = reverse('creme_config__edit_ctype_buttons', args=(ct.id,))
        context = self.assertGET200(url).context
        self.assertEqual(
            _('Edit configuration for «{model}»').format(model=ct),
            context.get('title'),
        )

        with self.assertNoException():
            choices = context['form'].fields['button_ids'].choices

        self.assertInChoices(
            value=TestButton01.id_,
            label=button_registry.get_button(TestButton01.id_),
            choices=choices,
        )
        self.assertInChoices(
            value=TestButton02.id_,
            label=button_registry.get_button(TestButton02.id_),
            choices=choices,
        )

        # NB: Button03 is incompatible with Contact
        self.assertNotInChoices(value=TestButton03.id_, choices=choices)

        response = self.client.post(
            url,
            data={
                'button_ids': [TestButton01.id_, TestButton02.id_],
            },
        )
        self.assertNoFormError(response)
        self.assertListEqual(
            [(TestButton01.id_, 1000), (TestButton02.id_, 1001)],
            [
                *ButtonMenuItem.objects
                               .filter(content_type=ct)
                               .order_by('order')
                               .values_list('button_id', 'order'),
            ],
        )