<commit_before>from django.conf import settings
from django.forms import widgets
from django.utils.safestring import mark_safe

COUNTRY_CHANGE_HANDLER = """
this.nextSibling.src = %s.replace('{code}', this.value.toLowerCase() || '__').replace('{code_upper}', this.value.toUpperCase() || '__');
"""

FLAG_IMAGE = """<img style="margin: 6px 4px; position: absolute;" src="%s" id="%%s-flag">"""


class CountrySelectWidget(widgets.Select):
    def render(self, name, value, attrs=None):
        attrs = attrs or {}
        attrs['onchange'] = COUNTRY_CHANGE_HANDLER % settings.COUNTRIES_FLAG_URL
        data = super(CountrySelectWidget, self).render(name, value, attrs)
        data += mark_safe((FLAG_IMAGE % settings.COUNTRIES_FLAG_URL) % (
            settings.STATIC_URL,
            unicode(value).lower() or '__',
            attrs['id']
        ))
        return data<commit_msg>Fix widget html<commit_after>from django.forms import widgets
from django.utils.html import escape

from django_countries.conf import settings

COUNTRY_CHANGE_HANDLER = (
    "this.nextSibling.src = '%s'"
    ".replace('{code}', this.value.toLowerCase() || '__')"
    ".replace('{code_upper}', this.value.toUpperCase() || '__');"
)

FLAG_IMAGE = (
    '<img style="margin: 6px 4px; position: absolute;" src="{0}">')


class CountrySelectWidget(widgets.Select):

    def render(self, name, value, attrs=None):
        from django_countries.fields import Country
        attrs = attrs or {}
        attrs['onchange'] = (
            COUNTRY_CHANGE_HANDLER % settings.COUNTRIES_FLAG_URL)
        data = super(CountrySelectWidget, self).render(name, value, attrs)
        country = Country(value or '__')
        data += FLAG_IMAGE.format(escape(country.flag))
        return data
{'fraction_non_alphanumeric': 0.1431818181818182, 'fraction_numerical': 0.002840909090909091, 'mean_word_length': 3.7338709677419355, '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': '7457572', 'n_tokens_mistral': 550, 'n_tokens_neox': 556, 'n_words': 111}