Esempio n. 1
0
    def test_render_qfilter02(self):
        "Q instance."
        widget = EntitySelector(content_type=13)
        name = 'my_field'
        value = '2'
        render_dom = assert_and_parse_html(
            self,
            widget.render(name, value, attrs={'qfilter': Q(name='foobar')}),
            user_msg=None,
            msg='Widget render is not valid !',
        )
        qfilter_attr = self.assertQFilter(render_dom, {'val': [['name', 'foobar']], 'op': 'AND'})
        html = \
'''<span class="ui-creme-widget widget-auto ui-creme-entityselector" widget="ui-creme-entityselector"
          labelURL="{text_url}" label="{label}" popupURL="{url}" popupSelection="single"
          qfilter="{q_filter}">
    <input name="{name}" type="hidden" class="ui-creme-input ui-creme-entityselector" value="{value}"/>
    <button type="button">{label}</button>
</span>'''.format(
            name=name,
            value=value,
            label=_('Select…'),
            text_url=TemplateURLBuilder(entity_id=(TemplateURLBuilder.Int, '${id}'))
                                       .resolve('creme_core__entity_as_json'),
            url=reverse('creme_core__listview_popup') + '?ct_id=13&selection=${selection}&q_filter=${qfilter}',
            q_filter=escape(qfilter_attr),
        )
        self.assertDOMEqual(assert_and_parse_html(self, html, None, 'Expected HTML is not valid !'), render_dom)
Esempio n. 2
0
    def test_render_is_required(self):
        widget = EntitySelector(content_type=12)
        widget.is_required = True

        html = '''
<span class="ui-creme-widget widget-auto ui-creme-entityselector" widget="ui-creme-entityselector"
          labelURL="{text_url}" label="{label}"
          popupURL="{url}" popupSelection="multiple" popupAuto>
    <input name="field" type="text" value="1"
           class="ui-creme-input ui-creme-entityselector" required />
    <button type="button">{label}</button>
</span>'''.format(
            label=_('Select…'),
            text_url=TemplateURLBuilder(
                entity_id=(TemplateURLBuilder.Int,
                           '${id}'), ).resolve('creme_core__entity_as_json'),
            url=(reverse('creme_core__listview_popup') +
                 '?ct_id=12&selection=${selection}&q_filter=${qfilter}'),
        )
        self.assertHTMLEqual(
            html,
            widget.render('field',
                          '1',
                          attrs={
                              'multiple': True,
                              'autoselect': True
                          }))
Esempio n. 3
0
    def test_render(self):
        text_url = TemplateURLBuilder(entity_id=(TemplateURLBuilder.Int, '${id}')).resolve('creme_core__entity_as_json')

        widget = EntitySelector(content_type=12)
        name = 'field-1'
        value = '1'
        html = \
'''<span class="ui-creme-widget widget-auto ui-creme-entityselector" widget="ui-creme-entityselector"
          labelURL="{text_url}" label="{label}" popupURL="{url}" popupSelection="single">
    <input name="{name}" type="hidden" class="ui-creme-input ui-creme-entityselector" value="{value}"/>
    <button type="button">{label}</button>
</span>'''.format(
            name=name,
            value=value,
            label=_('Select…'),
            text_url=text_url,
            url=reverse('creme_core__listview_popup') + '?ct_id=12&selection=${selection}&q_filter=${qfilter}',
        )
        self.assertHTMLEqual(html, widget.render(name, value))