def add_chart_structure_in_document(document): """Search the .otc template installed and put xml files in document """ #We search the template my_template = "" for p in path: if exists(p+"/chart/templates/chart.otc"): my_template=p+"/chart/templates/chart.otc" break if my_template == "": raise IOError, "Template .otc not found" #we have to create a folder for the chart i = 1 obj_created = False name="" manifest = document.get_part('META-INF/manifest.xml') while not obj_created: name="Object "+str(i) if manifest.get_media_type(name+'/') is None: manifest.add_full_path(name+'/', "application/vnd.oasis.opendocument.chart") document.container.set_part(name+'/', '') obj_created = True else: i = i+1 #We open the template chart = odf_new_container(my_template) #we add templates files in the document document.set_part(name+'/content.xml', chart.get_part('content.xml')) manifest.add_full_path(name+'/content.xml' , "text/xml") document.set_part(name+'/styles.xml', chart.get_part('styles.xml')) manifest.add_full_path(name+'/styles.xml' , "text/xml") document.set_part(name+'/meta.xml', chart.get_part('meta.xml')) manifest.add_full_path(name+'/meta.xml' , "text/xml") return name
def add_chart_structure_in_document(document): """Search the .otc template installed and put xml files in document """ #We search the template my_template = "" for p in path: if exists(p + "/chart/templates/chart.otc"): my_template = p + "/chart/templates/chart.otc" break if my_template == "": raise IOError, "Template .otc not found" #we have to create a folder for the chart i = 1 obj_created = False name = "" manifest = document.get_part('META-INF/manifest.xml') while not obj_created: name = "Object " + str(i) if manifest.get_media_type(name + '/') is None: manifest.add_full_path(name + '/', "application/vnd.oasis.opendocument.chart") document.container.set_part(name + '/', '') obj_created = True else: i = i + 1 #We open the template chart = odf_new_container(my_template) #we add templates files in the document document.set_part(name + '/content.xml', chart.get_part('content.xml')) manifest.add_full_path(name + '/content.xml', "text/xml") document.set_part(name + '/styles.xml', chart.get_part('styles.xml')) manifest.add_full_path(name + '/styles.xml', "text/xml") document.set_part(name + '/meta.xml', chart.get_part('meta.xml')) manifest.add_full_path(name + '/meta.xml', "text/xml") return name
def test_spreadsheet_type(self): container = odf_new_container('spreadsheet') mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['ods'])
def test_drawing_template(self): path = '../templates/drawing.otg' container = odf_new_container(path) mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['odg'])
def test_text_type(self): container = odf_new_container('text') mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['odt'])
def test_spreadsheet_template(self): path = '../templates/spreadsheet.ots' container = odf_new_container(path) mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['ods'])
def test_presentation_template(self): path = '../templates/presentation.otp' container = odf_new_container(path) mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['odp'])
def test_spreadsheet_template(self): path = '../lpod/templates/spreadsheet.ots' container = odf_new_container(path) mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['ods'])
def test_text_template(self): path = '../templates/text.ott' container = odf_new_container(path) mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['odt'])
def test_drawing_type(self): container = odf_new_container('drawing') mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['odg'])
def test_presentation_type(self): container = odf_new_container('presentation') mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['odp'])
def test_drawing_template(self): path = '../lpod/templates/drawing.otg' container = odf_new_container(path) mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['odg'])
def test_presentation_template(self): path = '../lpod/templates/presentation.otp' container = odf_new_container(path) mimetype = container.get_part('mimetype') self.assertEqual(mimetype, ODF_EXTENSIONS['odp'])
def test_clone(self): container = odf_new_container('text') clone = container.clone() self.assertEqual(clone.path, None) self.assertNotEqual(clone._odf_container__data, None)