<commit_before>from django import forms
from django.core.urlresolvers import reverse
from django.utils import six
from django.utils.safestring import mark_safe
from taggit.utils import edit_string_for_tags

from .conf import settings


class TagSelectize(forms.TextInput):
    def render(self, name, value, attrs=None):
        if value is not None and not isinstance(value, six.string_types):
            value = edit_string_for_tags([o.tag for o in value.select_related("tag")])
        html = super(TagSelectize, self).render(name, value, attrs)

        js_plugins = []
        if settings.TAGGIT_SELECTIZE['REMOVE_BUTTON']:
            js_plugins.append("remove_button")
        if settings.TAGGIT_SELECTIZE['RESTORE_ON_BACKSPACE']:
            js_plugins.append("restore_on_backspace")
        if settings.TAGGIT_SELECTIZE['DRAG_DROP']:
            js_plugins.append("drag_drop")

        js = u"""
            <script type="text/javascript">
                (function($) {
                    $(document).ready(function() {
                        $("#%(id)s").selectize({
                            valueField: 'name',
                            labelField: 'name',
                            searchField: 'name',
                            diacritics: %(diacritics)s,
                            create: %(create)s,
                            persist: %(persist)s,
                            openOnFocus: %(open_on_focus)s,
                            hideSelected: %(hide_selected)s,
                            closeAfterSelect: %(close_after_select)s,
                            loadThrottle: %(load_throttle)d,
                            preload: %(preload)s,
                            addPrecedence: %(add_precedence)s,
                            selectOnTab: %(select_on_tab)s,<commit_msg>Allow multiple selectize forms on same page<commit_after>from django import forms
from django.core.urlresolvers import reverse
from django.utils import six
from django.utils.safestring import mark_safe
from taggit.utils import edit_string_for_tags

from .conf import settings


class TagSelectize(forms.TextInput):
    def render(self, name, value, attrs=None):
        if value is not None and not isinstance(value, six.string_types):
            value = edit_string_for_tags([o.tag for o in value.select_related("tag")])
        html = super(TagSelectize, self).render(name, value, attrs)

        js_plugins = []
        if settings.TAGGIT_SELECTIZE['REMOVE_BUTTON']:
            js_plugins.append("remove_button")
        if settings.TAGGIT_SELECTIZE['RESTORE_ON_BACKSPACE']:
            js_plugins.append("restore_on_backspace")
        if settings.TAGGIT_SELECTIZE['DRAG_DROP']:
            js_plugins.append("drag_drop")

        js = u"""
            <script type="text/javascript">
                (function($) {
                    $(document).ready(function() {
                        $("input[id=#%(id)s]").selectize({
                            valueField: 'name',
                            labelField: 'name',
                            searchField: 'name',
                            diacritics: %(diacritics)s,
                            create: %(create)s,
                            persist: %(persist)s,
                            openOnFocus: %(open_on_focus)s,
                            hideSelected: %(hide_selected)s,
                            closeAfterSelect: %(close_after_select)s,
                            loadThrottle: %(load_throttle)d,
                            preload: %(preload)s,
                            addPrecedence: %(add_precedence)s,
                            selectOnTab: %(select_on_tab)s,
{'fraction_non_alphanumeric': 0.09836512261580381, 'fraction_numerical': 0.0, 'mean_word_length': 1.7253155159613958, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '896581', 'n_tokens_mistral': 1015, 'n_tokens_neox': 1000, 'n_words': 193}