def formfields_for_xmlobject(model, fields=None, exclude=None, widgets=None, options=None,<EOL>declared_subforms=None, max_num=None, extra=None):
<EOL>fieldlist = getattr(options, '<STR_LIT>', None)<EOL>if isinstance(fields, ParsedFieldList):<EOL><INDENT>fieldlist = fields<EOL><DEDENT>elif fields is not None:<EOL><INDENT>fieldlist = _parse_field_list(fields, include_parents=True)<EOL><DEDENT>excludelist = getattr(options, '<STR_LIT>', None)<EOL>if isinstance(fields, ParsedFieldList):<EOL><INDENT>fieldlist = fields<EOL><DEDENT>elif exclude is not None:<EOL><INDENT>excludelist = _parse_field_list(exclude, include_parents=False)<EOL><DEDENT>if widgets is None and options is not None:<EOL><INDENT>widgets = options.widgets<EOL><DEDENT>if max_num is None and options is not None:<EOL><INDENT>max_num = options.max_num<EOL><DEDENT>formfields = {}<EOL>subforms = {}<EOL>formsets = {}<EOL>field_order = {}<EOL>subform_labels = {}<EOL>for name, field in six.iteritems(model._fields):<EOL><INDENT>if fieldlist and not name in fieldlist.fields:<EOL><INDENT>continue<EOL><DEDENT>if excludelist and name in excludelist.fields:<EOL><INDENT>continue<EOL><DEDENT>if widgets and name in widgets:<EOL><INDENT>kwargs = {'<STR_LIT>': widgets[name] }<EOL><DEDENT>else:<EOL><INDENT>kwargs = {}<EOL><DEDENT>field_type = None<EOL>if field.required is not None:<EOL><INDENT>kwargs['<STR_LIT>'] = field.required<EOL><DEDENT>if field.verbose_name is not None:<EOL><INDENT>kwargs['<STR_LIT:label>'] = field.verbose_name<EOL><DEDENT>if field.help_text is not None:<EOL><INDENT>kwargs['<STR_LIT>'] = field.help_text<EOL><DEDENT>if hasattr(field, '<STR_LIT>') and field.choices:<EOL><INDENT>field_type = ChoiceField<EOL>kwargs['<STR_LIT>'] = [(val, val) for val in field.choices]<EOL>if field.required == False and '<STR_LIT>' not in field.choices:<EOL><INDENT>kwargs['<STR_LIT>'].insert(<NUM_LIT:0>, ('<STR_LIT>', '<STR_LIT>'))<EOL><DEDENT><DEDENT>elif isinstance(field, xmlmap.fields.StringField):<EOL><INDENT>field_type = CharField<EOL><DEDENT>elif isinstance(field, xmlmap.fields.IntegerField):<EOL><INDENT>field_type = IntegerField<EOL><DEDENT>elif isinstance(field, xmlmap.fields.DateField):<EOL><INDENT>field_type = DateField<EOL><DEDENT>elif isinstance(field, xmlmap.fields.SimpleBooleanField):<EOL><INDENT>kwargs['<STR_LIT>'] = False<EOL>field_type = BooleanField<EOL><DEDENT>elif isinstance(field, xmlmap.fields.NodeField) orisinstance(field, xmlmap.fields.NodeListField):<EOL><INDENT>form_label = kwargs['<STR_LIT:label>'] if '<STR_LIT:label>' in kwargs else fieldname_to_label(name)<EOL>subform_labels[name] = form_label<EOL>if name in declared_subforms:<EOL><INDENT>subform = declared_subforms[name]<EOL><DEDENT>else:<EOL><INDENT>subform_opts = {<EOL>'<STR_LIT>': fieldlist.subfields[name] if fieldlist and name in fieldlist.subfields else None,<EOL>'<STR_LIT>': excludelist.subfields[name] if excludelist and name in excludelist.subfields else None,<EOL>'<STR_LIT>': widgets[name] if widgets and name in widgets else None,<EOL>'<STR_LIT:label>': form_label,<EOL>}<EOL>subform = xmlobjectform_factory(field.node_class, **subform_opts)<EOL><DEDENT>if isinstance(field, xmlmap.fields.NodeField):<EOL><INDENT>subforms[name] = subform<EOL><DEDENT>elif isinstance(field, xmlmap.fields.NodeListField):<EOL><INDENT>formsets[name] = formset_factory(subform, formset=BaseXmlObjectFormSet,<EOL>max_num=subform._meta.max_num, can_delete=subform._meta.can_delete,<EOL>extra=subform._meta.extra, can_order=subform._meta.can_order)<EOL>formsets[name].form_label = form_label<EOL><DEDENT><DEDENT>elif isinstance(field, xmlmap.fields.StringListField) orisinstance(field, xmlmap.fields.IntegerListField):<EOL><INDENT>form_label = kwargs['<STR_LIT:label>'] if '<STR_LIT:label>' in kwargs else fieldname_to_label(name)<EOL>if isinstance(field, xmlmap.fields.IntegerListField):<EOL><INDENT>listform = IntegerListFieldForm<EOL><DEDENT>else:<EOL><INDENT>listform = ListFieldForm<EOL><DEDENT>formsets[name] = formset_factory(listform, formset=BaseXmlObjectListFieldFormSet)<EOL>formsets[name].form_label = form_label<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>'% (name, field.__class__))<EOL><DEDENT>if field_type is not None:<EOL><INDENT>if '<STR_LIT:label>' not in kwargs:<EOL><INDENT>kwargs['<STR_LIT:label>'] = fieldname_to_label(name)<EOL><DEDENT>formfields[name] = field_type(**kwargs)<EOL><DEDENT>field_order[field.creation_counter] = name<EOL><DEDENT>if fieldlist:<EOL><INDENT>ordered_fields = SortedDict((name, formfields[name])<EOL>for name in fieldlist.fields<EOL>if name in formfields)<EOL>ordered_subforms = SortedDict((name, subforms[name])<EOL>for name in fieldlist.fields<EOL>if name in subforms)<EOL>ordered_formsets = SortedDict((name, formsets[name])<EOL>for name in fieldlist.fields<EOL>if name in formsets)<EOL><DEDENT>else:<EOL><INDENT>ordered_fields = SortedDict(<EOL>[(field_order[key], formfields[field_order[key]]) for key in sorted(field_order.keys())<EOL>if field_order[key] in formfields ]<EOL>)<EOL>ordered_subforms = SortedDict(<EOL>[(field_order[key], subforms[field_order[key]]) for key in sorted(field_order.keys())<EOL>if field_order[key] in subforms ]<EOL>)<EOL>ordered_formsets = SortedDict(<EOL>[(field_order[key], formsets[field_order[key]]) for key in sorted(field_order.keys())<EOL>if field_order[key] in formsets ]<EOL>)<EOL><DEDENT>return ordered_fields, ordered_subforms, ordered_formsets, subform_labels<EOL>
Returns three sorted dictionaries (:class:`django.utils.datastructures.SortedDict`).
 * The first is a dictionary of form fields based on the
   :class:`~eulxml.xmlmap.XmlObject` class fields and their types.
 * The second is a sorted dictionary of subform classes for any fields of type
   :class:`~eulxml.xmlmap.fields.NodeField` on the model.
 * The third is a sorted dictionary of formsets for any fields of type
   :class:`~eulxml.xmlmap.fields.NodeListField` on the model.

Default sorting (within each dictionary) is by XmlObject field creation order.

Used by :class:`XmlObjectFormType` to set up a new :class:`XmlObjectForm`
class.

:param fields: optional list of field names; if specified, only the named fields
            will be returned, in the specified order
:param exclude: optional list of field names that should not be included on
            the form; if a field is listed in both ``fields`` and ``exclude``,
            it will be excluded
:param widgets: optional dictionary of widget options to be passed to form
            field constructor, keyed on field name
:param options: optional :class:`~django.forms.models.ModelFormOptions`.
            if specified then fields, exclude, and widgets will default
            to its values.
:param declared_subforms: optional dictionary of field names and form classes;
            if specified, the specified form class will be used to initialize
            the corresponding subform (for a :class:`~eulxml.xmlmap.fields.NodeField`)
            or a formset (for a :class:`~eulxml.xmlmap.fields.NodeListField`)
:param max_num: optional value for the maximum number of times a fieldset should repeat.
:param max_num: optional value for the number of extra forms to provide.