def set_name(self): # XXX Maybe also add a `ref` property set_ref() if self.element.get('name'): name = u"%s" % self.element.get('name') self.name = unaccent_unicode(name) elif self.element.get('ref'): ref = u"%s" % self.element.get('ref') self.name = unaccent_unicode(ref)
def set_form(self): query = "//form/*/*" res = self.xml_root.xpath(query) for e in res: tag = u"%s" % e.tag self._form[unaccent_unicode(tag)] = e
def set_controls(self): for el in self.fr_body_elements: el_bind = u"%s" % el.get('bind') bind = self.binds[unaccent_unicode(el_bind)] control = bind.get_fr_control_object(el) if control is not None: self.controls[bind.name] = control
def set_binds(self): # TODO # Fix/handle duplicates, due to iteration control(s) # Consider whether a self.binds pair, should assign a value as a list, with duplicates. # Refactor other code. q_left = "//*[@id='fr-form-binds']//*[name()='xforms:bind']" q_right = "//*[@id='fr-form-binds']//*[name()='xf:bind']" query = "%s|%s" % (q_left, q_right) for e in self.xml_root.xpath(query): bind_id = u"%s" % e.get('id') self.binds[unaccent_unicode(bind_id)] = Bind(self, e)
def __init__(self, builder, element): self.builder = builder self.element = element el_id = u"%s" % element.get('id') self.id = unaccent_unicode(el_id) self.name = None self.set_name() self.xf_type = element.get('type', 'xf:string') self.parent = None self.set_parent()
def set_resource(self): query = "//*[@id='fr-form-resources']/resources//resource[@xml:lang='%s']" % self.lang resource = self.xml_root.xpath(query) if len(resource) != 1: raise Exception("[orbeon-xml-api] Found %s elements for: %s" % (len(resource), query)) parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8') resource_root = etree.XML(etree.tostring(resource[0], encoding='UTF-8'), parser) resource_xml = etree.tostring(resource_root, encoding="unicode") res_dict = xmltodict.parse(resource_xml) for tag, v in res_dict.get('resource', {}).items(): tag = u"%s" % tag if isinstance(v, list): v = v[0] self.resource[unaccent_unicode(tag)] = Resource(self, v)