@@ -337,7 +337,6 @@ def __init__(self, model, service=None, validate=True, root=None):
337337 self .root = model .make_path (root ).root
338338
339339 self .name = ''
340- self .title = ''
341340 self .description = ''
342341 self .service = service
343342 self .prefetch_depth = service .prefetch_depth if service is not None else 1
@@ -424,15 +423,6 @@ def from_xml(cls, xml, *args, **kwargs):
424423 doc = minidom .parse (f )
425424 f .close ()
426425
427- templates = doc .getElementsByTagName ('template' )
428- if len (templates ) != 1 :
429- raise QueryParseError (
430- "wrong number of templates in xml. "
431- + "Only one <template> element is allowed. "
432- + "Found %d" % len (templates ))
433- t = templates [0 ]
434- obj .title = t .getAttribute ('title' )
435-
436426 queries = doc .getElementsByTagName ('query' )
437427 if len (queries ) != 1 :
438428 raise QueryParseError ("wrong number of queries in xml. "
@@ -1713,6 +1703,47 @@ def __init__(self, *args, **kwargs):
17131703 """
17141704 super (Template , self ).__init__ (* args , ** kwargs )
17151705 self .constraint_factory = constraints .TemplateConstraintFactory ()
1706+ self .title = ''
1707+
1708+ @classmethod
1709+ def from_xml (cls , xml , * args , ** kwargs ):
1710+ """
1711+ Deserialise a template query serialised to XML
1712+ ==============================================
1713+
1714+ This method is used to instantiate serialised templates.
1715+ It is used by intermine.webservice.Service objects
1716+ to instantiate Template objects and it can be used
1717+ to read in templates you have saved to a file.
1718+
1719+ @param xml: The xml as a file name, url, or string
1720+
1721+ @raise QueryParseError: if the query cannot be parsed
1722+
1723+ @rtype: L{Template}
1724+ """
1725+ # Extract all Query (superclass) fields
1726+ obj = super (Template , cls ).from_xml (xml , * args , ** kwargs )
1727+
1728+ # Extract fields specific to Template, like title
1729+ obj .do_verification = False
1730+ f = openAnything (xml )
1731+ doc = minidom .parse (f )
1732+ f .close ()
1733+
1734+ templates = doc .getElementsByTagName ('template' )
1735+ if len (templates ) != 1 :
1736+ raise QueryParseError (
1737+ "wrong number of templates in xml. "
1738+ + "Only one <template> element is allowed. "
1739+ + "Found %d" % len (templates ))
1740+ t = templates [0 ]
1741+ obj .title = t .getAttribute ('title' )
1742+
1743+ obj .verify ()
1744+
1745+ return obj
1746+
17161747 @property
17171748 def editable_constraints (self ):
17181749 """
0 commit comments