Exemple #1
0
 def test_bootstrap_css_tag(self):
     res = render_template_with_form("{% bootstrap_css %}").strip()
     css_url = get_bootstrap_setting("css_url")
     expected_html = (
         '<link href="{url}" crossorigin="{crossorigin}" integrity="{integrity}" rel="stylesheet">'
         .format(**css_url) +
         '<link href="//example.com/theme.css" rel="stylesheet">')
     self.assertHTMLEqual(expected_html, res)
Exemple #2
0
 def test_bootstrap_javascript_tag(self):
     res = render_template_with_form("{% bootstrap_javascript %}")
     javascript_url = get_bootstrap_setting("javascript_url")
     self.assertHTMLEqual(
         res,
         '<script src="{url}" crossorigin="{crossorigin}" integrity="{integrity}"></script>'
         .format(**javascript_url),
     )
Exemple #3
0
 def test_setting_to_none(self):
     css_url = get_bootstrap_setting("css_url")
     self.assertEqual(
         css_url,
         {
             "url":
             "https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css",
             "integrity":
             "sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu",
             "crossorigin": "anonymous",
         },
     )
Exemple #4
0
def render_formset(formset):
    '''
    Renders the formset within a bootstrap horizontal form layout. This requires
    special handling as standard bootstrap formset rendering does not work well
    within a <form class='form-horizontal'></form> element.

    After many attempts and using some suggestions from SO, the following layout
    seems work:

    <form class='form-horizontal'>
        {% bootstrap_form form layout='horizontal'%}

        <div id="id_formset">
            <label class="col-md-3 control-label">Members</label>
            <div class='col-md-9' style="max-height: 250px; overflow-y: scroll;">
                <table class='table table-condensed'>
                    <tbody>
                        {% for form in formset.forms %}
                        <tr>
                            <td>
                                <div class='form-group' style="margin-bottom: 0px;">
                                    <div class='form-inline'>
                                        {% for field in form %}
                                            <input class="form-control input-sm" id="field.name" placeholder="field.label">
                                        {% endfor %}
                                    </div>
                                </div>
                            </td>
                            <td style='vertical-align: middle;'>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <submit/reset buttons>
    </form>

    For rendering the innermost <input../>, we use django-bootstrap3's render_field() function
    so that it can use the appropriate classes depending on the field type.

    This template tag builds the above fragment for the given formset.
    '''

    model = formset.model
    label = capfirst(model.__name__)
    if hasattr(model._meta, 'verbose_name_plural'):
        label = model._meta.verbose_name_plural

    renderer = PopupCrudFormsetRenderer(formset,
                                        form_group_class='modal-formset-field')
    label_class = get_bootstrap_setting('horizontal_label_class')
    field_class = get_bootstrap_setting('horizontal_field_class')
    output2 = r"""
    <div id="id_formset" class="form-group modal-formset">
        <label class="{2} control-label">{0}</label>
        <div class='{3} table-wrapper'>
            {1}
        </div>
    </div>
    """.format(label, renderer._render(), label_class, field_class)  # pylint: disable=W0212

    return mark_safe(output2)
    def test_settings(self):
        from bootstrap3.bootstrap import get_bootstrap_setting

        self.assertTrue(get_bootstrap_setting("set_placeholder"))
 def test_setting_to_none(self):
     css_url = get_bootstrap_setting("css_url")
     self.assertIsNone(css_url)