def to_xml(self, opts = defaultdict(lambda: None)):
        '''
        Generate XML from the current settings.
        '''
        if not self.launch_url or not self.secure_launch_url:
            raise InvalidLTIConfigError('Invalid LTI configuration')


        root = etree.Element('cartridge_basiclti_link', attrib = {
                    '{%s}%s' %(NSMAP['xsi'], 'schemaLocation'): 'http://www.imsglobal.org/xsd/imslticc_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0p1.xsd http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd',
                    'xmlns': 'http://www.imsglobal.org/xsd/imslticc_v1p0'
                    }, nsmap = NSMAP)
        
        for key in ['title', 'description', 'launch_url', 'secure_launch_url']:
            option = etree.SubElement(root, '{%s}%s' %(NSMAP['blti'], key))
            option.text = getattr(self, key)

        vendor_keys = ['name', 'code', 'description', 'url']
        if any('vendor_' + key for key in vendor_keys) or\
                self.vendor_contact_email:
                    vendor_node = etree.SubElement(root, '{%s}%s'
                            %(NSMAP['blti'], 'vendor'))
                    for key in vendor_keys:
                        if getattr(self, 'vendor_' + key) != None:
                            v_node = etree.SubElement(vendor_node,
                                    '{%s}%s' %(NSMAP['lticp'], key))
                            v_node.text = getattr(self, 'vendor_' + key)
                    if getattr(self, 'vendor_contact_email'):
                        v_node = etree.SubElement(vendor_node,
                                '{%s}%s' %(NSMAP['lticp'], 'contact'))
                        c_name = etree.SubElement(v_node,
                                '{%s}%s' %(NSMAP['lticp'], 'name'))
                        c_name.text = self.vendor_contact_name
                        c_email = etree.SubElement(v_node,
                                '{%s}%s' %(NSMAP['lticp'], 'email'))
                        c_email.text = self.vendor_contact_email

        # Custom params
        if len(self.custom_params) != 0:
            custom_node = etree.SubElement(root, '{%s}%s' %(NSMAP['blti'],
                'custom'))
            for (key, val) in sorted(self.custom_params.items()):
                c_node = etree.SubElement(custom_node, '{%s}%s'
                        %(NSMAP['lticm'], 'property'))
                c_node.set('name', key)
                c_node.text = val

        # Extension params
        if len(self.extensions) != 0:
            for (key, params) in sorted(self.extensions.items()):
                extension_node = etree.SubElement(root, '{%s}%s' %(NSMAP['blti'],
                    'extensions'), platform = key)
                self.recursive_options(extension_node,params)

        if getattr(self, 'cartridge_bundle'):
            identifierref = etree.SubElement(root, 'cartridge_bundle',
                    identifierref = self.cartridge_bundle)

        if getattr(self, 'cartridge_icon'):
            identifierref = etree.SubElement(root, 'cartridge_icon',
                    identifierref = self.cartridge_icon)

        return '<?xml version="1.0" encoding="UTF-8"?>' + etree.tostring(root)
def to_xml ( self , opts = defaultdict ( lambda : None ) ) : if not self . launch_url or not self . secure_launch_url : raise InvalidLTIConfigError ( 'Invalid LTI configuration' ) root = etree . Element ( 'cartridge_basiclti_link' , attrib = { '{%s}%s' % ( NSMAP [ 'xsi' ] , 'schemaLocation' ) : 'http://www.imsglobal.org/xsd/imslticc_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0p1.xsd http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd' , 'xmlns' : 'http://www.imsglobal.org/xsd/imslticc_v1p0' } , nsmap = NSMAP ) for key in [ 'title' , 'description' , 'launch_url' , 'secure_launch_url' ] : option = etree . SubElement ( root , '{%s}%s' % ( NSMAP [ 'blti' ] , key ) ) option . text = getattr ( self , key ) vendor_keys = [ 'name' , 'code' , 'description' , 'url' ] if any ( 'vendor_' + key for key in vendor_keys ) or self . vendor_contact_email : vendor_node = etree . SubElement ( root , '{%s}%s' % ( NSMAP [ 'blti' ] , 'vendor' ) ) for key in vendor_keys : if getattr ( self , 'vendor_' + key ) != None : v_node = etree . SubElement ( vendor_node , '{%s}%s' % ( NSMAP [ 'lticp' ] , key ) ) v_node . text = getattr ( self , 'vendor_' + key ) if getattr ( self , 'vendor_contact_email' ) : v_node = etree . SubElement ( vendor_node , '{%s}%s' % ( NSMAP [ 'lticp' ] , 'contact' ) ) c_name = etree . SubElement ( v_node , '{%s}%s' % ( NSMAP [ 'lticp' ] , 'name' ) ) c_name . text = self . vendor_contact_name c_email = etree . SubElement ( v_node , '{%s}%s' % ( NSMAP [ 'lticp' ] , 'email' ) ) c_email . text = self . vendor_contact_email if len ( self . custom_params ) != 0 : custom_node = etree . SubElement ( root , '{%s}%s' % ( NSMAP [ 'blti' ] , 'custom' ) ) for ( key , val ) in sorted ( self . custom_params . items ( ) ) : c_node = etree . SubElement ( custom_node , '{%s}%s' % ( NSMAP [ 'lticm' ] , 'property' ) ) c_node . set ( 'name' , key ) c_node . text = val if len ( self . extensions ) != 0 : for ( key , params ) in sorted ( self . extensions . items ( ) ) : extension_node = etree . SubElement ( root , '{%s}%s' % ( NSMAP [ 'blti' ] , 'extensions' ) , platform = key ) self . recursive_options ( extension_node , params ) if getattr ( self , 'cartridge_bundle' ) : identifierref = etree . SubElement ( root , 'cartridge_bundle' , identifierref = self . cartridge_bundle ) if getattr ( self , 'cartridge_icon' ) : identifierref = etree . SubElement ( root , 'cartridge_icon' , identifierref = self . cartridge_icon ) return '<?xml version="1.0" encoding="UTF-8"?>' + etree . tostring ( root )
Generate XML from the current settings.