Skip to content

Commit

Permalink
Added support for xs:group.
Browse files Browse the repository at this point in the history
  • Loading branch information
tuffnatty committed Aug 16, 2017
1 parent 183de02 commit 0982d0d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions xsd_to_django_model/xsd_to_django_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def resolve_el_ref(tree, el_def):
return resolve_ref(tree, el_def, "xs:element")


def resolve_group_ref(tree, group_def):
return resolve_ref(tree, group_def, "xs:group")


class Model:

def __init__(self, builder, model_name, type_name):
Expand Down Expand Up @@ -1188,18 +1192,21 @@ def make_fields(self, typename, seq_def,
is_root=False):
this_model = self.models[typename]
null = (null or get_null(seq_def))
for seq2_def in xpath(seq_def, "xs:sequence"):
self.write_seq_or_choice((seq2_def, None), typename,
prefix=prefix,
doc_prefix=doc_prefix,
attrs=attrs,
null=null)
for choice_def in xpath(seq_def, "xs:choice"):
self.write_seq_or_choice((None, choice_def), typename,
seqs = []
for group_def in xpath(seq_def, "xs:group"):
group_def = resolve_group_ref(self.tree, group_def)
seqs.extend([(s, None) for s in xpath(group_def, "xs:sequence")])
seqs.extend([(None, c) for c in xpath(group_def, "xs:choice")])
seqs.extend([(s, None) for s in xpath(seq_def, "xs:sequence")])
seqs.extend([(None, c) for c in xpath(seq_def, "xs:choice")])

for seq_or_choice_def in seqs:
self.write_seq_or_choice(seq_or_choice_def, typename,
prefix=prefix,
doc_prefix=doc_prefix,
attrs=attrs,
null=null)

for el_def in xpath(seq_def, "xs:element"):
el_name = el_def.get("name") or el_def.get("ref")
dotted_name = prefix + el_name
Expand Down

0 comments on commit 0982d0d

Please sign in to comment.