<commit_before># -*- coding: utf-8 -*-
from itertools import chain
#
from django.forms.widgets import SelectMultiple
from django.forms.formsets import all_valid
from django.contrib.contenttypes.models import ContentType
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.contrib.admin.util import unquote, flatten_fieldsets, label_for_field
from django.contrib.admin import helpers
from django.db import transaction
from django.views.decorators.csrf import csrf_protect
from django.utils.decorators import method_decorator
from django.template.response import TemplateResponse
from django.utils.encoding import force_text
from django.utils.translation import ugettext as _
from django.http import Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.html import escape
#
from starmato.admin.options import StarmatoModelAdmin

csrf_protect_m = method_decorator(csrf_protect)

class ReviewAndMergeSelectMultiple(SelectMultiple):
    def render_options(self, choices, selected_choices):
        # Normalize to strings.
        selected_choices = set(force_text(v) for v in selected_choices)
        output = []
        for option_value, option_label in chain(self.choices, choices):
            if isinstance(option_label, (list, tuple)):
                output.append(format_html('<optgroup label="{0}">', force_text(option_value)))
                for option in option_label:
                    if force_text(option) in selected_choices:
                        output.append(self.render_option(selected_choices, *option))
                output.append('</optgroup>')
            else:
                if force_text(option_value) in selected_choices:
                    output.append(self.render_option(selected_choices, option_value, option_label))
        return '\n'.join(output)

class   ReviewAndMergeAdmin(StarmatoModelAdmin):
    def formfield_for_manytomany(self, db_field, request, **kwargs):
        if "merge" in request.META["PATH_INFO"] and not 'widget' in kwargs:
            kwargs['widget'] = ReviewAndMergeSelectMultiple
        return super(ReviewAndMergeAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)

    def get_urls(self):
        from django.conf.urls import patterns, url

        def wrap(view):
            from functools import update_wrapper
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)

        urlpatterns = super(ReviewAndMergeAdmin, self).get_urls()

        info = self.model._meta.app_label, self.model._meta.module_name

        urlpatterns = patterns('',
            url(r'^(.+)/merge/$',
                wrap(self.merge_view),
                name='%s_%s_merge' % info),
        ) + urlpatterns

        return urlpatterns

<commit_msg>SelectMultiple fix<commit_after># -*- coding: utf-8 -*-
from itertools import chain
#
from django.forms.widgets import SelectMultiple
from django.forms.formsets import all_valid
from django.contrib.contenttypes.models import ContentType
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.contrib.admin.util import unquote, flatten_fieldsets, label_for_field
from django.contrib.admin import helpers
from django.db import transaction
from django.views.decorators.csrf import csrf_protect
from django.utils.decorators import method_decorator
from django.template.response import TemplateResponse
from django.utils.encoding import force_text
from django.utils.translation import ugettext as _
from django.http import Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.html import escape
#
from starmato.admin.options import StarmatoModelAdmin

csrf_protect_m = method_decorator(csrf_protect)

class ReviewAndMergeSelectMultiple(SelectMultiple):
    def render_options(self, choices, selected_choices):
        # Normalize to strings.
        selected_choices = set(force_text(v) for v in selected_choices)
        output = []
        for option_value, option_label in chain(self.choices, choices):
            if isinstance(option_label, (list, tuple)):
                output.append(format_html('<optgroup label="{0}">', force_text(option_value)))
                for option in option_label:
                    if force_text(option) in selected_choices:
                        output.append(self.render_option(selected_choices, *option))
                output.append('</optgroup>')
            else:
                if force_text(option_value) in selected_choices:
                    output.append(self.render_option(selected_choices, option_value, option_label))
        return '\n'.join(output)

class   ReviewAndMergeAdmin(StarmatoModelAdmin):
    def formfield_for_manytomany(self, db_field, request, **kwargs):
        if request.META["PATH_INFO"].endswith("merge/"):
            kwargs['widget'] = ReviewAndMergeSelectMultiple
        return super(ReviewAndMergeAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)

    def get_urls(self):
        from django.conf.urls import patterns, url

        def wrap(view):
            from functools import update_wrapper
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)

        urlpatterns = super(ReviewAndMergeAdmin, self).get_urls()

        info = self.model._meta.app_label, self.model._meta.module_name

        urlpatterns = patterns('',
            url(r'^(.+)/merge/$',
                wrap(self.merge_view),
                name='%s_%s_merge' % info),
        ) + urlpatterns

        return urlpatterns


{'fraction_non_alphanumeric': 0.08766458766458766, 'fraction_numerical': 0.0017325017325017325, 'mean_word_length': 3.330832708177044, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4985825', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1562, 'n_words': 368}