<commit_before>from django.utils import formats
from django.utils.formats import get_format
from django.utils.translation import get_language

import floppyforms as forms


class Datepicker(forms.TextInput):
    """
    Date field widget which use bootstrap-datepicker library.
    """

    @property
    def media(self):

        css = {
            'all': ('bootstrap-datepicker/css/bootstrap-datepicker3.min.css',)
        }
        js = ('bootstrap-datepicker/js/bootstrap-datepicker.min.js',)

        lang = get_language()[:2]
        if lang != 'en':
            js += (
                'bootstrap-datepicker/locales/bootstrap-datepicker.{lang}.min.js'.format(
                    lang=lang,
                ),
            )

        return forms.Media(css=css, js=js)

    def _format_value(self, value):
        return formats.localize_input(
            value,
            formats.get_format('DATE_INPUT_FORMATS')[0],
        )

    def build_attrs(self, extra_attrs=None, **kwargs):
        """
        Use this method instead of the classic __init__ in order to be
        executed at runtime due to locale switch.
        """
        try:
            date_input_format_js = get_format('DATE_INPUT_FORMAT_JS')
        except AttributeError:
            date_input_format_js = 'mm/dd/yyyy'

        attrs = {
            'size': 10,
            'data-provide': 'datepicker',
            'data-date-format': date_input_format_js,
            'data-date-language': get_language()[:2],
            'data-date-orientation': 'top auto',
        }
        attrs.update(
            super(Datepicker, self).build_attrs(extra_attrs=extra_attrs, **kwargs)
        )
        return attrs<commit_msg>auto-close datepicker<commit_after>from django.utils import formats
from django.utils.formats import get_format
from django.utils.translation import get_language

import floppyforms as forms


class Datepicker(forms.TextInput):
    """
    Date field widget which use bootstrap-datepicker library.
    """

    @property
    def media(self):

        css = {
            'all': ('bootstrap-datepicker/css/bootstrap-datepicker3.min.css',)
        }
        js = ('bootstrap-datepicker/js/bootstrap-datepicker.min.js',)

        lang = get_language()[:2]
        if lang != 'en':
            js += (
                'bootstrap-datepicker/locales/bootstrap-datepicker.{lang}.min.js'.format(
                    lang=lang,
                ),
            )

        return forms.Media(css=css, js=js)

    def _format_value(self, value):
        return formats.localize_input(
            value,
            formats.get_format('DATE_INPUT_FORMATS')[0],
        )

    def build_attrs(self, extra_attrs=None, **kwargs):
        """
        Use this method instead of the classic __init__ in order to be
        executed at runtime due to locale switch.
        """
        try:
            date_input_format_js = get_format('DATE_INPUT_FORMAT_JS')
        except AttributeError:
            date_input_format_js = 'mm/dd/yyyy'

        attrs = {
            'size': 10,
            'data-provide': 'datepicker',
            'data-date-format': date_input_format_js,
            'data-date-language': get_language()[:2],
            'data-date-orientation': 'top auto',
            'data-date-autoclose': 1,
        }
        attrs.update(
            super(Datepicker, self).build_attrs(extra_attrs=extra_attrs, **kwargs)
        )
        return attrs
{'fraction_non_alphanumeric': 0.10998258850841555, 'fraction_numerical': 0.0037724898432965758, 'mean_word_length': 2.0263388937664617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5489087', 'n_tokens_mistral': 998, 'n_tokens_neox': 949, 'n_words': 200}