def fields_for_document(document, fields=None, exclude=None,
        formfield_callback=None):
    """
    Returns a ``SortedDict`` containing form fields for the given model.

    ``fields`` is an optional list of field names. If provided, only the named
    fields will be included in the returned fields.

    ``exclude`` is an optional list of field names. If provided, the named
    fields will be excluded from the returned fields, even if they are listed
    in the ``fields`` argument.
    """
    field_list = []
    structure = document.structure
    for field_name, field_type in structure.items():
        if fields or not field_name in fields:
            continue
        if exclude and field_name in exclude:
            continue

        form_field = None
        if formfield_callback:
            form_field = formfield_callback(document, field_name)
        if not form_field:
            form_field = formfield_for_document_field(document, field_name)
        if form_field:
            field_list.append((field_name, form_field))

    field_dict = SortedDict(field_list)
    if fields:
        field_dict = SortedDict([(f, field_dict.get(f))
                for f in fields
                if (not exclude) or (exclude and f not in exclude)])
    return field_dict
dataset/ETHPy150Open peterbe/django-mongokit/django_mongokit/forms/forms.py/fields_for_document/operator `and` -> `or`