コード例 #1
0
ファイル: test_toc.py プロジェクト: gosha20777/lpod-python3
 def test_toc_fill_attached(self):
     document = self.document.clone()
     toc = odf_create_toc("Table des matières")
     document.get_body().append(toc)
     toc.fill()
     toc_lines = get_toc_lines(toc)
     self.assertEqual(toc_lines, self.expected)
コード例 #2
0
ファイル: test_toc.py プロジェクト: nicolasderam/lpod-python
 def test_toc_fill_attached(self):
     document = self.document.clone()
     toc = odf_create_toc(u"Table des matières")
     document.get_body().append(toc)
     toc.fill()
     toc_lines = get_toc_lines(toc)
     self.assertEqual(toc_lines, self.expected)
コード例 #3
0
ファイル: pdfexport.py プロジェクト: laszlocseh/wise.msfd
    def get_document(self):
        result = BytesIO()
        document = odf_new_document('text')
        setup_document_styles(document)
        body = document.get_body()

        # Create the Table Of Content
        toc = odf_create_toc()
        # Changing the default "Table Of Content" Title :
        toc.set_title("Table of Content")

        # Do not forget to add every components to the document:
        body.append(toc)

        for table in self.tables:
            if hasattr(table, 'get_odt_data'):
                odt_data = table.get_odt_data(document)

                body.extend(odt_data)

        toc.fill()

        document.save(target=result, pretty=True)

        return result.getvalue()
コード例 #4
0
ファイル: lpod-merge.py プロジェクト: gosha20777/lpod-python3
def init_doc(filename, mimetype):
    if mimetype in (ODF_TEXT, ODF_SPREADSHEET, ODF_PRESENTATION):
        output_doc = odf_get_document(filename)
        if mimetype == ODF_TEXT:
            # Extra for text: begin with a TOC
            output_body = output_doc.get_body()
            output_body.insert(odf_create_toc(), FIRST_CHILD)
    elif mimetype in (CSV_SHORT, CSV_LONG):
        output_doc = odf_new_document('spreadsheet')
        add_csv(filename, output_doc)
    else:
        raise NotImplementedError(mimetype)
    return output_doc
コード例 #5
0
ファイル: lpod-merge.py プロジェクト: RB14/lpod-python
def init_doc(filename, mimetype):
    if mimetype in (ODF_TEXT, ODF_SPREADSHEET, ODF_PRESENTATION):
        output_doc = odf_get_document(filename)
        if mimetype == ODF_TEXT:
            # Extra for text: begin with a TOC
            output_body = output_doc.get_body()
            output_body.insert(odf_create_toc(), FIRST_CHILD)
    elif mimetype in (CSV_SHORT, CSV_LONG):
        output_doc = odf_new_document('spreadsheet')
        add_csv(filename, output_doc)
    else:
        raise NotImplementedError, mimetype
    return output_doc
コード例 #6
0
def convert_topic(node, context):
    # Reset the top to body
    context["top"] = context["body"]

    # Yet an other TOC ?
    if context["skip_toc"]:
        return
    if context["toc"] is not None:
        warn("a TOC is already inserted")
        return

    toc = odf_create_toc()
    context["body"].append_element(toc)
    context["toc"] = toc
コード例 #7
0
def init_doc(mimetype):
    # Text mode
    if mimetype == "application/vnd.oasis.opendocument.text":
        output_doc = odf_new_document_from_type("text")

        # Begin with a TOC
        output_body = output_doc.get_body()
        output_body.append_element(odf_create_toc())
    # Spreadsheet mode
    elif mimetype in ("application/vnd.oasis.opendocument.spreadsheet",
                      "text/csv"):
        output_doc = odf_new_document_from_type("spreadsheet")
    # Presentation mode
    else:
        output_doc = odf_new_document_from_type("presentation")

    return output_doc
コード例 #8
0
ファイル: test_toc.py プロジェクト: gosha20777/lpod-python3
 def test_toc_fill_unattached_document(self):
     toc = odf_create_toc("Table des matières")
     toc.fill(self.document)
     toc_lines = get_toc_lines(toc)
     self.assertEqual(toc_lines, self.expected)
コード例 #9
0
ファイル: test_toc.py プロジェクト: gosha20777/lpod-python3
 def test_toc_fill_unattached(self):
     toc = odf_create_toc("Table des matières")
     self.assertRaises(ValueError, toc.fill)
コード例 #10
0
ファイル: page_views.py プロジェクト: hforge/wiki
    def action(self, resource, context, form):
        from lpod.document import odf_get_document
        from lpod.document import odf_new_document_from_type
        from lpod.rst2odt import rst2odt, convert, make_context
        from lpod.toc import odf_create_toc

        parent = resource.parent
        template = None
        template_upload = form['template_upload']
        if template_upload is not None:
            filename, mimetype, body = template_upload
            if mimetype not in ALLOWED_FORMATS:
                context.message = ERR_NOT_ODT(filename=filename)
            template = odf_get_document(StringIO(body))
        else:
            template_name = form['template']
            if template_name:
                template_resource = parent.get_resource(template_name)
                body = template_resource.handler.to_str()
                template = odf_get_document(StringIO(body))

        book = resource.get_book()
        if book is not None:
            # Prepare document
            if template is None:
                document = odf_new_document_from_type('text')
            else:
                document = template.clone()
                document.get_body().clear()
            # Metadata
            meta = document.get_meta()
            now = datetime.now()
            meta.set_creation_date(now)
            meta.set_modification_date(now)
            meta.set_editing_duration(timedelta(0))
            meta.set_editing_cycles(1)
            meta.set_generator(u"ikaaro.wiki to ODT")
            for metadata in ('title', 'comments', 'subject', 'language',
                    'keywords'):
                getattr(meta, 'set_' + metadata)(book.get(metadata))
            # Cover page
            cover_uri = book.get('cover')
            if cover_uri:
                cover = parent.get_resource(cover_uri, soft=True)
                if cover is None:
                    if not form['ignore_missing_pages']:
                        context.message = ERR_PAGE_NOT_FOUND(uri=cover_uri)
                        return
                else:
                    doctree = cover.get_doctree()
                    resolve_references(doctree, resource, context)
                    resolve_images(doctree, resource, context)
                    heading_level = 0 if startswith_section(doctree) else 1
                    convert_context = make_context(document,
                            heading_level=heading_level,
                            skip_toc=True,
                            # Override temporarly convert_title
                            convert_title=convert_cover_title,
                            convert_subtitle=convert_cover_title)
                    convert(document, doctree, context=convert_context)
            # Global TOC
            language = book.get('language').split('-')[0]
            title = MSG(u"Table of Contents").gettext(language=language)
            outline_level = book.get('toc-depth', 10)
            toc = odf_create_toc(title=title, outline_level=outline_level)
            document.get_body().append(toc)
            # List of pages and their starting title level
            doctree = resource.get_doctree()
            visitor = PageVisitor(doctree, resource,
                    ignore_missing_pages=form['ignore_missing_pages'])
            try:
                book.walkabout(visitor)
            except LookupError, uri:
                context.message = ERR_PAGE_NOT_FOUND(uri=uri)
                return
            pages = visitor.pages
            if not pages:
                context.message = ERR_NO_PAGE_FOUND
                return
            # List of links between pages
            known_links = [ page.abspath for page, _ in pages ]
            # Compile pages
            for page, level in pages:
                doctree = page.get_doctree()
                try:
                    resolve_references(doctree, page, context,
                            reference_resolver=odt_reference_resolver,
                            known_links=known_links)
                except ValueError, e:
                    context.message = ERROR(unicode(str(e), 'utf_8'))
                    return
                resolve_images(doctree, resource, context)
                if startswith_section(doctree):
                    # convert_section will increment it
                    level -= 1
                convert_context = make_context(document,
                        heading_level=level,
                        skip_toc=True)
                convert(document, doctree, context=convert_context)
コード例 #11
0
ファイル: lpod-mm2odt.py プロジェクト: Agicia/lpod-python
    # Check if the file already exists
    check_target_file(outname)

    # Open the XML file
    mm = parse(open(inname, 'rb'))
    # Get the first node of the mind map
    first_node = mm.xpath('/map/node')[0]
    # Make the structure
    mm_structure = make_mm_structure(first_node, 0)

    # Create a new ODT document
    document = odf_new_document('text')
    body = document.get_body()
    # Remove the default paragraph
    body.clear()
    # Begin with a TOC
    toc = odf_create_toc()
    body.append(toc)
    # Set the title
    meta = document.get_meta()
    meta.set_title(mm_structure[1])
    # Make the document from the structure
    make_document(mm_structure[2], body)
    # Fill the TOC
    toc.toc_fill()

    # Save the document
    document.save(outname, pretty=True)
    # Feed back to the user
    print "`%s' created from `%s'" % (outname, inname)
コード例 #12
0
ファイル: test_toc.py プロジェクト: nicolasderam/lpod-python
 def test_toc_fill_unattached_document(self):
     toc = odf_create_toc(u"Table des matières")
     toc.fill(self.document)
     toc_lines = get_toc_lines(toc)
     self.assertEqual(toc_lines, self.expected)
コード例 #13
0
ファイル: test_toc.py プロジェクト: nicolasderam/lpod-python
 def test_toc_fill_unattached(self):
     toc = odf_create_toc(u"Table des matières")
     self.assertRaises(ValueError, toc.fill)
コード例 #14
0
    # Check if the file already exists
    check_target_file(outname)

    # Open the XML file
    mm = parse(open(inname, 'rb'))
    # Get the first node of the mind map
    first_node = mm.xpath('/map/node')[0]
    # Make the structure
    mm_structure = make_mm_structure(first_node, 0)

    # Create a new ODT document
    document = odf_new_document('text')
    body = document.get_body()
    # Remove the default paragraph
    body.clear()
    # Begin with a TOC
    toc = odf_create_toc()
    body.append(toc)
    # Set the title
    meta = document.get_meta()
    meta.set_title(mm_structure[1])
    # Make the document from the structure
    make_document(mm_structure[2], body)
    # Fill the TOC
    toc.toc_fill()

    # Save the document
    document.save(outname, pretty=True)
    # Feed back to the user
    print("`%s' created from `%s'" % (outname, inname))