<commit_before>from django.forms import SelectMultiple
from django.utils.safestring import mark_safe


class JqueryChosenSelectMultiple(SelectMultiple):
    def render(self, name, value, attrs=None, choices=()):
        out = super(JqueryChosenSelectMultiple, self).render(name, value, attrs, choices)

        trigger_jquery_chosen = '''
        <script type="text/javascript">
            $("select[name={name}]").on("change", function() {{
                $(this).trigger("chosen:updated");
            }});
            $("select[name={name}]").chosen();
        </script>'''.format(name=name)

        return mark_safe(out + trigger_jquery_chosen)

    class Media:
        css = {
            'all': ('css/chosen.min.css',)
        }

        js = (
            'js/chosen.jquery.min.js',
        )<commit_msg>#164 Add JqueryChosen widget with the ability to add object<commit_after>from django.forms import SelectMultiple
from django.utils.html import format_html
from django.utils.safestring import mark_safe


class JqueryChosenSelectMultiple(SelectMultiple):
    def render(self, name, value, attrs=None, choices=()):
        out = super(JqueryChosenSelectMultiple, self).render(name, value, attrs, choices)

        trigger_jquery_chosen = '''
        <script type="text/javascript">
            $("select[name={name}]").on("change", function() {{
                $(this).trigger("chosen:updated");
            }});
            $("select[name={name}]").chosen();
        </script>'''.format(name=name)

        return mark_safe(out + trigger_jquery_chosen)

    class Media:
        css = {
            'all': ('css/chosen.min.css',)
        }

        js = (
            'js/chosen.jquery.min.js',
        )


class JqueryChosenAddModel(JqueryChosenSelectMultiple):
    def render(self, name, value, attrs=None, choices=()):
        out = super(JqueryChosenAddModel, self).render(name, value, attrs, choices)

        field_name = name.split('-')[-1]
        model_add_button = format_html('''
        <div class="addbutton">
            <a href="javascript:void(0);" onclick="addObject('{name}', '#id_{name}');"
            class="button bicolor icon icon-plus">Add {name}</a>
        </div>''', name=field_name)

        return mark_safe(out + model_add_button)

    class Media:
        js = (
            'js/add_object.js',
        )
{'fraction_non_alphanumeric': 0.14985100042571306, 'fraction_numerical': 0.0021285653469561515, 'mean_word_length': 2.6547433903576985, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2077391', 'n_tokens_mistral': 708, 'n_tokens_neox': 694, 'n_words': 131}