Skip to content

Commit 0384fd0

Browse files
author
Yo Yehudi
authored
Merge pull request #55 from svengato/dev
svengato intermine-ws-python enhancements
2 parents 8213e19 + 9a9768c commit 0384fd0

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

intermine/pathfeatures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def append(self, *sos):
103103
"Sort orders must be either SortOrder instances,"
104104
+ " or tuples of arguments: I got:" + so + sos)
105105
def __repr__(self):
106-
return '<' + self.class__.__name__ + ': [' + str(self) + ']>'
106+
return '<' + self.__class__.__name__ + ': [' + str(self) + ']>'
107107
def __str__(self):
108108
return " ".join(map(str, self.sort_orders))
109109
def clear(self):

intermine/query.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def from_xml(cls, xml, *args, **kwargs):
429429
+ "Only one <query> element is allowed. Found %d" % len(queries))
430430
q = queries[0]
431431
obj.name = q.getAttribute('name')
432-
obj.description = q.getAttribute('description')
432+
obj.description = q.getAttribute('longDescription')
433433
obj.add_view(q.getAttribute('view'))
434434
for p in q.getElementsByTagName('pathDescription'):
435435
path = p.getAttribute('pathString')
@@ -1703,6 +1703,47 @@ def __init__(self, *args, **kwargs):
17031703
"""
17041704
super(Template, self).__init__(*args, **kwargs)
17051705
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+
17061747
@property
17071748
def editable_constraints(self):
17081749
"""

0 commit comments

Comments
 (0)