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

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

    ``exclude`` is an optional list of properties names. If provided, the named
    properties will be excluded from the returned properties, even if 
    they are listed in the ``properties`` argument.
    """
    if dotpath:
        field = document._meta.dot_notation_to_field(dotpath)
        fields = field.schema._meta.fields
    else:
        fields = document._meta.fields
    
    field_list = []
    
    values = []
    if properties:
        values = [fields[prop] for prop in properties if \
                                                prop in fields]
    else:
        values = fields.values()
        #values.sort(lambda a, b: cmp(a.creation_counter, b.creation_counter))
    
    for prop in values: 
        if properties and not prop.name in properties:
            continue
        if exclude and exclude in prop.name:
            continue
        if not properties and not prop.editable:
            continue
        
        field = prop.formfield()
        
        if field and formfield_callback:
            defaults = prop.formfield_kwargs()
            field = formfield_callback(prop, type(field), **defaults)
        if field:
            field_list.append((prop.name, field))
    return SortedDict(field_list)
dataset/ETHPy150Open zbyte64/django-dockit/dockit/forms/forms.py/fields_for_document/swapped operands of `in`