Exemplo n.º 1
0
    def test_actions_creation_url_empty(self):
        widget = EntityCreatorWidget(FakeContact,
                                     creation_url='',
                                     creation_allowed=True)
        widget._build_actions(FakeContact, {})

        self.assertListEqual([self._build_reset_action()], widget.actions)
Exemplo n.º 2
0
    def test_render_no_model(self):
        widget = EntityCreatorWidget()
        html = '''<ul class="hbox ui-creme-widget ui-layout widget-auto ui-creme-actionbuttonlist" widget="ui-creme-actionbuttonlist">
    <li class="delegate">
        <input name="field" style="display:none;" type="text" />
        <span>Model is not set</span>
    </li>
</ul>'''
        self.assertHTMLEqual(html, widget.render('field', ''))
Exemplo n.º 3
0
    def test_actions_required(self):
        creation_url = reverse('creme_core__quick_form', args=(ContentType.objects.get_for_model(FakeContact).id,))
        widget = EntityCreatorWidget(FakeContact, creation_url=creation_url, creation_allowed=True)
        widget.is_required = True
        widget._build_actions(FakeContact, {})

        self.assertEqual([
            self._build_create_action(FakeContact.creation_label, _('Create'), creation_url),
        ], widget.actions)
Exemplo n.º 4
0
    def test_actions_creation_not_allowed(self):
        creation_url = reverse('creme_core__quick_form', args=(ContentType.objects.get_for_model(FakeContact).id,))
        widget = EntityCreatorWidget(FakeContact, creation_url=creation_url, creation_allowed=False)
        widget._build_actions(FakeContact, {})

        self.assertEqual([
            self._build_reset_action(),
            self._build_create_action(FakeContact.creation_label, _("Can't create"), creation_url, enabled=False),
        ], widget.actions)
Exemplo n.º 5
0
    def test_render_empty_value(self):
        "Empty."
        ct_id = ContentType.objects.get_for_model(FakeContact).id
        creation_url = reverse('creme_core__quick_form', args=(ct_id, ))
        widget = EntityCreatorWidget(
            FakeContact,
            creation_url=creation_url,
            creation_allowed=False,
        )
        self.assertIsNone(widget.creation_label)

        reset_label = _('Clear')
        create_label = FakeContact.creation_label
        html = '''
<ul class="hbox ui-creme-widget ui-layout widget-auto ui-creme-actionbuttonlist"
    widget="ui-creme-actionbuttonlist">
    <li class="delegate">
        <span class="ui-creme-widget ui-creme-entityselector" widget="ui-creme-entityselector"
              labelURL="{select_label_url}" label="{select_label}"
              popupURL="{select_url}" popupSelection="single">
            <input name="field" type="text" class="ui-creme-input ui-creme-entityselector"/>
            <button type="button">{select_label}</button>
        </span>
    </li>
    <li>
        <button class="ui-creme-actionbutton with-icon" action="reset" name="reset"
                title="{reset_label}" type="button" value="">
            {reset_icon}<span>{reset_label}</span>
        </button>
    </li>
    <li>
        <button class="ui-creme-actionbutton with-icon" name="create"
                title="{create_title}" type="button" disabled popupUrl="{create_url}">
            {create_icon}<span>{create_label}</span>
        </button>
    </li>
</ul>'''.format(
            select_label=_('Select…'),
            select_label_url=EntitySelector(content_type=ct_id).text_url,
            select_url=EntitySelector(content_type=ct_id).url,
            reset_label=reset_label,
            reset_icon=self.get_icon('delete',
                                     size='form-widget',
                                     label=reset_label).render(),
            create_title=_("Can't create"),
            create_label=create_label,
            create_url=creation_url,
            create_icon=self.get_icon('add',
                                      size='form-widget',
                                      label=create_label).render(),
        )
        self.assertHTMLEqual(html, widget.render('field', ''))
Exemplo n.º 6
0
    def test_render02(self):
        "Initialized, creation_label."
        user = self.login()
        contact = FakeContact.objects.create(last_name='Doe',
                                             first_name='John',
                                             user=user)
        ct_id = contact.entity_type_id

        creation_url = reverse('creme_core__quick_form', args=(ct_id, ))
        creation_label = 'Create a agent'
        widget = EntityCreatorWidget(
            FakeContact,
            creation_url=creation_url,
            creation_allowed=False,
            creation_label=creation_label,
        )
        self.assertEqual(creation_label, widget.creation_label)
        widget.from_python = lambda value: value.id

        html = '''<ul class="hbox ui-creme-widget ui-layout widget-auto ui-creme-actionbuttonlist" widget="ui-creme-actionbuttonlist">
    <li class="delegate">
        <span class="ui-creme-widget ui-creme-entityselector" widget="ui-creme-entityselector"
              labelURL="{select_label_url}" label="{select_label}"
              popupURL="{select_url}" popupSelection="single">
            <input name="field" type="text" class="ui-creme-input ui-creme-entityselector" value="{value}"/>
            <button type="button">{select_label}</button>
        </span>
    </li>
    <li>
        <button class="ui-creme-actionbutton" action="reset" name="reset" title="{reset_title}" type="button" value="">
            {reset_label}
        </button>
    </li>
    <li>
        <button class="ui-creme-actionbutton" name="create" title="{create_title}" type="button" disabled popupUrl="{create_url}">
            {create_label}
        </button>
    </li>
</ul>'''.format(
            select_label=_('Select…'),
            select_label_url=EntitySelector(content_type=ct_id).text_url,
            select_url=EntitySelector(content_type=ct_id).url,
            reset_title=_('Clear'),
            reset_label=_('Clear'),
            create_title=_("Can't create"),
            create_label=creation_label,
            create_url=creation_url,
            value=contact.id,
        )
        self.assertHTMLEqual(html, widget.render('field', value=contact))
Exemplo n.º 7
0
    def test_render01(self):
        "Empty"
        ct_id = ContentType.objects.get_for_model(FakeContact).id
        creation_url = reverse('creme_core__quick_form', args=(ct_id,))
        widget = EntityCreatorWidget(FakeContact, creation_url=creation_url, creation_allowed=False)
        html = '''<ul class="hbox ui-creme-widget ui-layout widget-auto ui-creme-actionbuttonlist" widget="ui-creme-actionbuttonlist">
    <li class="delegate">
        <span class="ui-creme-widget ui-creme-entityselector" widget="ui-creme-entityselector"
              labelURL="{select_label_url}" label="{select_label}"
              popupURL="{select_url}" popupSelection="single">
            <input name="field" type="hidden" class="ui-creme-input ui-creme-entityselector"/>
            <button type="button">{select_label}</button>
        </span>
    </li>
    <li>
        <button class="ui-creme-actionbutton" action="reset" name="reset" title="{reset_title}" type="button" value="">
            {reset_label}
        </button>
    </li>
    <li>
        <button class="ui-creme-actionbutton" name="create" title="{create_title}" type="button" disabled popupUrl="{create_url}">
            {create_label}
        </button>
    </li>
</ul>'''.format(
            select_label=_('Select…'),
            select_label_url=EntitySelector(content_type=ct_id).text_url,
            select_url=EntitySelector(content_type=ct_id).url,
            # 'select_q_filter': '',  # qfilter="%(select_q_filter)s">
            reset_title=_('Clear'),
            reset_label=_('Clear'),
            create_title=_("Can't create"),
            create_label=FakeContact.creation_label,
            create_url=creation_url,
        )
        self.assertHTMLEqual(html, widget.render('field', ''))
Exemplo n.º 8
0
    def test_actions_disabled(self):
        creation_url = reverse(
            'creme_core__quick_form',
            args=(ContentType.objects.get_for_model(FakeContact).id, ),
        )
        widget = EntityCreatorWidget(FakeContact,
                                     creation_url=creation_url,
                                     creation_allowed=True)
        widget._build_actions(FakeContact, {})

        self.assertListEqual(
            [
                self._build_reset_action(),
                self._build_create_action(FakeContact.creation_label,
                                          _('Create'), creation_url),
            ],
            widget.actions,
        )

        widget._build_actions(FakeContact, {'readonly': True})
        self.assertListEqual([], widget.actions)

        widget._build_actions(FakeContact, {'disabled': True})
        self.assertListEqual([], widget.actions)
Exemplo n.º 9
0
 def test_is_disabled(self):
     widget = EntityCreatorWidget(FakeContact)
     self.assertFalse(widget._is_disabled({}))
     self.assertFalse(widget._is_disabled(None))
     self.assertTrue(widget._is_disabled({'readonly': True}))
     self.assertTrue(widget._is_disabled({'disabled': True}))