<commit_before>from classytags.arguments import Argument, KeywordArgument, Flag
from classytags.core import Tag, Options
from django import template
from django.forms import TextInput, Select, CheckboxSelectMultiple, SelectMultiple, CheckboxInput, RadioSelect
from django.template.loader import render_to_string

register = template.Library()

def get_input_type(widget_type):
    if widget_type == TextInput:
        input_type = 'text'
    elif widget_type == Select or widget_type == SelectMultiple:
        input_type = 'select'
    elif widget_type == CheckboxSelectMultiple or widget_type == RadioSelect:
        input_type = 'radiocheck-list'
    elif widget_type == CheckboxSelectMultiple or widget_type == CheckboxInput or widget_type == RadioSelect:
        input_type = 'radiocheck'
    else:
        input_type = 'text'
    return input_type

def booleanify(arg):
    if arg is True or arg.lower() == 'yes' or arg.lower() == 'true' or arg.lower() == 'on':
        return True
    if arg is False or arg.lower() == 'no' or arg.lower() == 'false' or arg.lower() == 'off':
        return False

def get_options(args):
    options = dict()
    if args:
        args = args.split(' ')
        options = {
            'placeholder_from_label': 'placeholder_from_label' in args,
            'no_required': 'no_required' in args,
            'no_required_helper': 'no_required_helper' in args,
            'no_help_text': 'no_help_text' in args,
            'no_error_text': 'no_error_text' in args,
        }
    return options


class StandardWidget(Tag):
    name = 'standard_widget'
    options = Options(
        Argument('field'),
        Argument('options', required=False, default=None),
        KeywordArgument('custom_class', required=False, default=None),
        KeywordArgument('placeholder', required=False, default=None),
        KeywordArgument('input_type', required=False, default=None),
    )

    def render_tag(self, context, field, options, custom_class, placeholder, input_type):
        args = get_options(options)
        placeholder = placeholder.get('placeholder')
        input_type = input_type.get('input_type')
        custom_class = custom_class.get('custom_class')
        custom_classes = []
        if custom_class:
            custom_classes = custom_class.split(' ')
        attrs = {}
        if placeholder:
            attrs['placeholder'] = placeholder
        elif args.get('placeholder_from_label', False):
            attrs['placeholder'] = field.label
        if not args.get('no_required', False) and field.field.required:
            attrs['required'] = 'required'

        if field.field.show_hidden_initial:<commit_msg>added readonly and disabled options<commit_after>from classytags.arguments import Argument, KeywordArgument, Flag
from classytags.core import Tag, Options
from django import template
from django.forms import TextInput, Select, CheckboxSelectMultiple, SelectMultiple, CheckboxInput, RadioSelect
from django.template.loader import render_to_string

register = template.Library()

def get_input_type(widget_type):
    if widget_type == TextInput:
        input_type = 'text'
    elif widget_type == Select or widget_type == SelectMultiple:
        input_type = 'select'
    elif widget_type == CheckboxSelectMultiple or widget_type == RadioSelect:
        input_type = 'radiocheck-list'
    elif widget_type == CheckboxSelectMultiple or widget_type == CheckboxInput or widget_type == RadioSelect:
        input_type = 'radiocheck'
    else:
        input_type = 'text'
    return input_type

def booleanify(arg):
    if arg is True or arg.lower() == 'yes' or arg.lower() == 'true' or arg.lower() == 'on':
        return True
    if arg is False or arg.lower() == 'no' or arg.lower() == 'false' or arg.lower() == 'off':
        return False

def get_options(args):
    options = dict()
    if args:
        args = args.split(' ')
        options = {
            'placeholder_from_label': 'placeholder_from_label' in args,
            'no_required': 'no_required' in args,
            'no_required_helper': 'no_required_helper' in args,
            'no_help_text': 'no_help_text' in args,
            'no_error_text': 'no_error_text' in args,
            'readonly': 'readonly' in args,
            'disabled': 'disabled' in args,
        }
    return options


class StandardWidget(Tag):
    name = 'standard_widget'
    options = Options(
        Argument('field'),
        Argument('options', required=False, default=None),
        KeywordArgument('custom_class', required=False, default=None),
        KeywordArgument('placeholder', required=False, default=None),
        KeywordArgument('input_type', required=False, default=None),
    )

    def render_tag(self, context, field, options, custom_class, placeholder, input_type):
        args = get_options(options)
        placeholder = placeholder.get('placeholder')
        input_type = input_type.get('input_type')
        custom_class = custom_class.get('custom_class')
        custom_classes = []
        if custom_class:
            custom_classes = custom_class.split(' ')
        attrs = {}
        if placeholder:
            attrs['placeholder'] = placeholder
        elif args.get('placeholder_from_label', False):
            attrs['placeholder'] = field.label
        if not args.get('no_required', False) and field.field.required:
            attrs['required'] = 'required'
        if args.get('readonly', False):
            attrs['readonly'] = 'readonly'
        if args.get('disabled', False):
            attrs['disabled'] = 'disabled'

        if field.field.show_hidden_initial:
{'fraction_non_alphanumeric': 0.10818505338078292, 'fraction_numerical': 0.0, 'mean_word_length': 3.088, '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': '3390167', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1540, 'n_words': 405}