<commit_before>from django.forms.models import modelform_factory as django_modelform_factory
from django.db.models import ForeignKey, OneToOneField

from .widgets import *
from .registry  import *

def get_widgets_dict(model):
    widgets = {}

    for field in model._meta.fields:
        if not isinstance(field, (ForeignKey, OneToOneField)):
            continue

        channel = registry.channel_for_model(field.rel.to)
        if not channel:
            continue
        
        widgets[field.name] = AutocompleteWidget(channel_name=channel.__name__, 
            max_items=1)

    for field in model._meta.many_to_many:
        channel = registry.channel_for_model(field.rel.to)
        if not channel:
            continue

        widgets[field.name] = AutocompleteWidget(channel_name=channel.__name__)

    return widgets

def modelform_factory(model, **kwargs):
    widgets = get_widgets_dict(model)
    widgets.update(kwargs.pop('widgets', {}))<commit_msg>Added kwarg to form utils: autocomplete_exclude<commit_after>from django.forms.models import modelform_factory as django_modelform_factory
from django.db.models import ForeignKey, OneToOneField

from .widgets import *
from .registry  import *

def get_widgets_dict(model, autocomplete_exclude=None):
    if autocomplete_exclude is None:
        autocomplete_exclude = []

    widgets = {}

    for field in model._meta.fields:
        if field.name in autocomplete_exclude:
            continue

        if not isinstance(field, (ForeignKey, OneToOneField)):
            continue

        channel = registry.channel_for_model(field.rel.to)
        if not channel:
            continue
        
        widgets[field.name] = AutocompleteWidget(channel_name=channel.__name__, 
            max_items=1)

    for field in model._meta.many_to_many:
        if field.name in autocomplete_exclude:
            print "Excluding", field.name
            continue

        channel = registry.channel_for_model(field.rel.to)
        if not channel:
            continue

        widgets[field.name] = AutocompleteWidget(channel_name=channel.__name__)

    return widgets

def modelform_factory(model, autocomplete_exclude=None,
    **kwargs):

    widgets = get_widgets_dict(model, autocomplete_exclude=autocomplete_exclude)
    widgets.update(kwargs.pop('widgets', {}))
{'fraction_non_alphanumeric': 0.07939914163090128, 'fraction_numerical': 0.0008583690987124463, 'mean_word_length': 3.0328719723183393, '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': '7219126', 'n_tokens_mistral': 692, 'n_tokens_neox': 629, 'n_words': 144}