class GraphTemplate(Template): # TODO: Is there a way to specify a default/static value for form? form = StringField('@form', choices=['graph']) graph = NodeField('graph', Graph)
class IdNode(XmlObject): id = StringField('@id')
class XpathVariable(XmlObject): ROOT_NAME = 'variable' name = StringField('@name') locale_id = StringField('locale/@id')
class LocaleId(XmlObject): ROOT_NAME = 'locale' locale_id = StringField('@id')
class CommandMixin(XmlObject): ROOT_NAME = 'command' relevant = StringField('@relevant')
class ConfigurationItem(Text): ROOT_NAME = "text" id = StringField("@id")
class MediaResource(AbstractResource): ROOT_NAME = 'media' path = StringField('@path')
class AuthKeys(XmlObject): ROOT_NAME = 'auth_keys' domain = StringField('@domain', required=True) issued = CustomDateTimeField('@issued', required=True) key_records = NodeListField('key_record', KeyRecord, required=True)
class Value(LedgerXML): ROOT_NAME = 'value' section_id = StringField('@section-id', required=False) quantity = IntegerField('@quantity', required=True)
class CalculatedPropertyXpathVariable(XmlObject): ROOT_NAME = 'variable' name = StringField('@name') locale_id = StringField('locale/@id')
class Detail(OrderedXmlObject, IdNode): """ <detail id=""> <title><text/></title> <lookup action="" image="" name=""> <extra key="" value = "" /> <response key ="" /> </lookup> <variables> <__ function=""/> </variables> <field sort=""> <header form="" width=""><text/></header> <template form="" width=""><text/></template> </field> </detail> """ ROOT_NAME = 'detail' ORDER = ('title', 'lookup', 'details', 'fields') nodeset = StringField('@nodeset') print_template = StringField('@print-template') title = NodeField('title/text', Text) lookup = NodeField('lookup', Lookup) fields = NodeListField('field', Field) actions = NodeListField('action', Action) details = NodeListField('detail', "self") _variables = NodeField('variables', DetailVariableList) relevant = StringField('@relevant') def _init_variables(self): if self._variables is None: self._variables = DetailVariableList() def _get_variables_node(self): self._init_variables() return self._variables.variables def _set_variables_node(self, value): self._init_variables() self._variables.variables = value variables = property(_get_variables_node, _set_variables_node) def has_variables(self): # can't check len(self.variables) directly since NodeList uses an # xpath to find its children which doesn't work here since # each node has a custom name return self._variables is not None and len( self.variables.node.getchildren()) > 0 def get_variables(self): """ :returns: List of DetailVariable objects """ return [ self.variables.mapper.to_python(node) for node in self.variables.node.getchildren() ] def get_all_xpaths(self): result = set() if self.nodeset: result.add(self.nodeset) if self.has_variables(): for variable in self.get_variables(): result.add(variable.function) if self.actions: for action in self.actions: for frame in action.stack.frames: result.add(frame.if_clause) for datum in getattr(frame, 'datums', []): result.add(datum.value) def _get_graph_config_xpaths(configuration): result = set() for config in configuration.configs: result.add(config.xpath_function) return result for field in self.fields: if field.template.form == 'graph': s = etree.tostring(field.template.node) template = load_xmlobject_from_string(s, xmlclass=GraphTemplate) result.update( _get_graph_config_xpaths(template.graph.configuration)) for series in template.graph.series: result.add(series.nodeset) result.update( _get_graph_config_xpaths(series.configuration)) else: result.add(field.header.text.xpath_function) result.add(field.template.text.xpath_function) if field.template.text.xpath: for variable in field.template.text.xpath.variables: if variable.xpath: result.add(six.text_type(variable.xpath.function)) for detail in self.details: result.update(detail.get_all_xpaths()) result.discard(None) return result
class Itemset(XmlObject): ROOT_NAME = 'itemset' nodeset = StringField('@nodeset') value_ref = StringField('value/@ref') label_ref = StringField('label/@ref') sort_ref = StringField('sort/@ref')
class MediaResource(AbstractResource): ROOT_NAME = 'media' path = StringField('@path') lazy = SimpleBooleanField('resource/@lazy', true="true", false="false")
class Sort(AbstractTemplate): ROOT_NAME = 'sort' type = StringField('@type') order = StringField('@order') direction = StringField('@direction')
class Locale(XmlObject): ROOT_NAME = 'locale' id = StringField('@id') child_id = NodeField('id', Id) arguments = NodeListField('argument', LocaleArgument)
class MediaText(XmlObject): ROOT_NAME = 'text' form_name = StringField('@form', choices=['image', 'audio' ]) # Nothing XForm-y about this 'form' locale = NodeField('locale', LocaleId)
class Detail(OrderedXmlObject, IdNode): """ <detail id=""> <title><text/></title> <lookup action="" image="" name=""> <extra key="" value = "" /> <response key ="" /> </lookup> <variables> <__ function=""/> </variables> <field sort=""> <header form="" width=""><text/></header> <template form="" width=""><text/></template> </field> </detail> """ ROOT_NAME = 'detail' ORDER = ('title', 'lookup', 'details', 'fields') nodeset = StringField('@nodeset') print_template = StringField('@print-template') title = NodeField('title/text', Text) lookup = NodeField('lookup', Lookup) fields = NodeListField('field', Field) actions = NodeListField('action', Action) details = NodeListField('detail', "self") _variables = NodeField('variables', DetailVariableList) def _init_variables(self): if self._variables is None: self._variables = DetailVariableList() def get_variables(self): self._init_variables() return self._variables.variables def set_variables(self, value): self._init_variables() self._variables.variables = value variables = property(get_variables, set_variables) def get_all_xpaths(self): result = set() if self.nodeset: result.add(self.nodeset) if self._variables: for variable in self.variables: result.add(variable.function) if self.actions: for action in self.actions: for frame in action.stack.frames: result.add(frame.if_clause) for datum in getattr(frame, 'datums', []): result.add(datum.value) def _get_graph_config_xpaths(configuration): result = set() for config in configuration.configs: result.add(config.xpath_function) return result for field in self.fields: if field.template.form == 'graph': s = etree.tostring(field.template.node) template = load_xmlobject_from_string(s, xmlclass=GraphTemplate) result.update( _get_graph_config_xpaths(template.graph.configuration)) for series in template.graph.series: result.add(series.nodeset) result.update( _get_graph_config_xpaths(series.configuration)) else: result.add(field.header.text.xpath_function) result.add(field.template.text.xpath_function) for detail in self.details: result.update(detail.get_all_xpaths()) result.discard(None) return result
class QueryPrompt(DisplayNode): ROOT_NAME = 'prompt' key = StringField('@key')
class LocaleResource(AbstractResource): ROOT_NAME = 'locale' language = StringField('@language')
class RemoteRequestPost(XmlObject): ROOT_NAME = 'post' url = StringField('@url') relevant = StringField('@relevant') data = NodeListField('data', QueryData)
class Display(OrderedXmlObject): ROOT_NAME = 'display' ORDER = ('text', 'media_image', 'media_audio') text = NodeField('text', Text) media_image = StringField('media/@image') media_audio = StringField('media/@audio')
class LocaleArgument(XmlObject): ROOT_NAME = 'argument' key = StringField('@key') value = StringField('.')
class MediaText(XmlObject): ROOT_NAME = 'text' form_name = StringField('@form', choices=['image', 'audio']) # Nothing XForm-y about this 'form' locale = NodeField('locale', LocaleId) xpath = NodeField('xpath', Xpath) xpath_function = XPathField('xpath/@function')
class AbstractTemplate(XmlObject): form = StringField('@form', choices=['image', 'phone', 'address']) width = IntegerField('@width') text = NodeField('text', Text)
class StackCommand(XmlObject): ROOT_NAME = 'command' value = XPathField('@value') command = StringField('.')
class Extra(XmlObject): ROOT_NAME = 'extra' key = StringField("@key") value = StringField("@value")
class ClearFrame(BaseFrame): ROOT_NAME = 'clear' frame = StringField('@frame')
class Response(XmlObject): ROOT_NAME = 'response' key = StringField("@key")
class QueryData(XmlObject): ROOT_NAME = 'data' key = StringField('@key') ref = XPathField('@ref')
class Instance(IdNode, OrderedXmlObject): ROOT_NAME = 'instance' ORDER = ('id', 'src') src = StringField('@src')