Exemplo n.º 1
0
    def test_get_item_by_content(self):
        # Create the items
        spam = odf_create_list_item(u"spam")
        ham = odf_create_list_item(u"ham")
        eggs = odf_create_list_item(u"eggs")
        # Create the corresponding lists
        spam_list = odf_create_list()
        ham_list = odf_create_list()
        eggs_list = odf_create_list()
        # Fill the lists
        spam_list.append_item(spam)
        ham_list.append_item(ham)
        eggs_list.append_item(eggs)
        # Create the final nested list (spam_list)
        spam.append_element(ham_list)
        ham.append_element(eggs_list)

        item = spam_list.get_item_by_content(ur"spam")
        expected = (
            "<text:list-item>\n"
            "  <text:p>spam</text:p>\n"
            "  <text:list>\n"
            "    <text:list-item>\n"
            "      <text:p>ham</text:p>\n"
            "      <text:list>\n"
            "        <text:list-item>\n"
            "          <text:p>eggs</text:p>\n"
            "        </text:list-item>\n"
            "      </text:list>\n"
            "    </text:list-item>\n"
            "  </text:list>\n"
            "</text:list-item>\n"
        )
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item_by_content(ur"ham")
        expected = (
            "<text:list-item>\n"
            "  <text:p>ham</text:p>\n"
            "  <text:list>\n"
            "    <text:list-item>\n"
            "      <text:p>eggs</text:p>\n"
            "    </text:list-item>\n"
            "  </text:list>\n"
            "</text:list-item>\n"
        )
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item_by_content(ur"eggs")
        expected = "<text:list-item>\n" "  <text:p>eggs</text:p>\n" "</text:list-item>\n"
        self.assertEqual(item.serialize(pretty=True), expected)
Exemplo n.º 2
0
def convert_list(node, context, list_type):
    # Predefined styles
    if list_type == "enumerated":
        style_name = "Numbering_20_1"
    else:
        style_name = "List_20_1"

    odf_list = odf_create_list(style=style_name)
    context["top"].append_element(odf_list)

    # Save the current top
    old_top = context["top"]

    for item in node:

        if item.tagname != "list_item":
            warn("node not supported: %s" % item.tagname)
            continue

        # Create a new item
        odf_item = odf_create_list_item()
        odf_list.append_element(odf_item)

        # A new top
        context["top"] = odf_item

        for child in item:
            convert_node(child, context)

    # And restore the top
    context["top"] = old_top
Exemplo n.º 3
0
 def test_create_list(self):
     item = odf_create_list_item()
     a_list = odf_create_list([u"你好 Zoé"])
     expected = (
         "<text:list>" "<text:list-item>" "<text:p>%s</text:p>" "</text:list-item>" "</text:list>"
     ) % convert_unicode(u"你好 Zoé")
     self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 4
0
    def test_get_item_by_content(self):
        # Create the items
        spam = odf_create_list_item(u'spam')
        ham = odf_create_list_item(u'ham')
        eggs = odf_create_list_item(u'eggs')
        # Create the corresponding lists
        spam_list = odf_create_list()
        ham_list = odf_create_list()
        eggs_list = odf_create_list()
        # Fill the lists
        spam_list.append_item(spam)
        ham_list.append_item(ham)
        eggs_list.append_item(eggs)
        # Create the final nested list (spam_list)
        spam.append(ham_list)
        ham.append(eggs_list)

        item = spam_list.get_item(content=ur'spam')
        expected = ('<text:list-item>\n'
                    '  <text:p>spam</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>ham</text:p>\n'
                    '      <text:list>\n'
                    '        <text:list-item>\n'
                    '          <text:p>eggs</text:p>\n'
                    '        </text:list-item>\n'
                    '      </text:list>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=ur'ham')
        expected = ('<text:list-item>\n'
                    '  <text:p>ham</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>eggs</text:p>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=ur'eggs')
        expected = ('<text:list-item>\n'
                    '  <text:p>eggs</text:p>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
Exemplo n.º 5
0
    def test_get_item_by_content(self):
        # Create the items
        spam = odf_create_list_item('spam')
        ham = odf_create_list_item('ham')
        eggs = odf_create_list_item('eggs')
        # Create the corresponding lists
        spam_list = odf_create_list()
        ham_list = odf_create_list()
        eggs_list = odf_create_list()
        # Fill the lists
        spam_list.append_item(spam)
        ham_list.append_item(ham)
        eggs_list.append_item(eggs)
        # Create the final nested list (spam_list)
        spam.append(ham_list)
        ham.append(eggs_list)

        item = spam_list.get_item(content=r'spam')
        expected = ('<text:list-item>\n'
                    '  <text:p>spam</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>ham</text:p>\n'
                    '      <text:list>\n'
                    '        <text:list-item>\n'
                    '          <text:p>eggs</text:p>\n'
                    '        </text:list-item>\n'
                    '      </text:list>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=r'ham')
        expected = ('<text:list-item>\n'
                    '  <text:p>ham</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>eggs</text:p>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=r'eggs')
        expected = ('<text:list-item>\n'
                    '  <text:p>eggs</text:p>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
Exemplo n.º 6
0
 def test_create_list(self):
     item = odf_create_list_item()
     a_list = odf_create_list(['你好 Zoé'])
     expected = (('<text:list>'
                  '<text:list-item>'
                  '<text:p>%s</text:p>'
                  '</text:list-item>'
                  '</text:list>') % convert_unicode('你好 Zoé'))
     self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 7
0
 def test_create_list(self):
     item = odf_create_list_item()
     a_list = odf_create_list([u'你好 Zoé'])
     expected = (('<text:list>'
                    '<text:list-item>'
                      '<text:p>%s</text:p>'
                    '</text:list-item>'
                  '</text:list>') % convert_unicode(u'你好 Zoé'))
     self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 8
0
    def test_insert_list(self):
        content = self.content
        clone = content.clone()
        item = odf_create_list_item()
        a_list = odf_create_list(style="a_style")
        a_list.append_element(item)
        body = clone.get_body()
        body.append_element(a_list)

        expected = '<text:list text:style-name="a_style">' "<text:list-item/>" "</text:list>"
        self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 9
0
    def test_insert_list(self):
        content = self.content
        clone = content.clone()
        item = odf_create_list_item()
        a_list = odf_create_list(style='a_style')
        a_list.append(item)
        body = clone.get_body()
        body.append(a_list)

        expected = ('<text:list text:style-name="a_style">'
                    '<text:list-item/>'
                    '</text:list>')
        self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 10
0
    def test_insert_after(self):
        breakfast = odf_create_list()
        breakfast.append_item('spam')
        ham = odf_create_list_item('ham')
        breakfast.append_item(ham)
        eggs = odf_create_list_item('eggs')
        breakfast.insert_item(eggs, after=ham)

        expected = ('<text:list>'
                    '<text:list-item>'
                    '<text:p>spam</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>ham</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>eggs</text:p>'
                    '</text:list-item>'
                    '</text:list>')
        # TODO use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 11
0
    def test_insert_after(self):
        breakfast = odf_create_list()
        breakfast.append_item(u'spam')
        ham = odf_create_list_item(u'ham')
        breakfast.append_item(ham)
        eggs = odf_create_list_item(u'eggs')
        breakfast.insert_item(eggs, after=ham)

        expected = ('<text:list>'
                      '<text:list-item>'
                        '<text:p>spam</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:p>ham</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:p>eggs</text:p>'
                      '</text:list-item>'
                    '</text:list>')
        # TODO use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 12
0
    def test_insert_before(self):
        breakfast = odf_create_list()
        breakfast.append_item(u"spam")
        eggs = odf_create_list_item(u"eggs")
        breakfast.append_item(eggs)
        ham = odf_create_list_item(u"ham")
        breakfast.insert_item(ham, before=eggs)

        expected = (
            "<text:list>"
            "<text:list-item>"
            "<text:p>spam</text:p>"
            "</text:list-item>"
            "<text:list-item>"
            "<text:p>ham</text:p>"
            "</text:list-item>"
            "<text:list-item>"
            "<text:p>eggs</text:p>"
            "</text:list-item>"
            "</text:list>"
        )
        # TODO use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 13
0
    def test_get_formatted_text(self):
        # Create the items
        spam = odf_create_list_item('In this picture, there are 47 people;\n'
                                    'none of them can be seen.')
        ham = odf_create_list_item('In this film, we hope to show you the\n'
                                   'value of not being seen.\n')
        eggs = odf_create_list_item('Here is Mr. Bagthorpe of London, '
                                    'SE14.\n')
        foo = odf_create_list_item('He cannot be seen.')
        bar = odf_create_list_item('Now I am going to ask him to stand up.')
        baz = odf_create_list_item('Mr. Bagthorpe, will you stand up please?')
        # Create the lists
        how_not_to_be_seen1 = odf_create_list()
        how_not_to_be_seen2 = odf_create_list()
        how_not_to_be_seen3 = odf_create_list()
        # Fill the lists
        # First list
        how_not_to_be_seen1.append_item(spam)
        # Second list
        how_not_to_be_seen2.append_item(ham)
        how_not_to_be_seen2.append_item(eggs)
        how_not_to_be_seen2.append_item(foo)
        # Third list
        how_not_to_be_seen3.append_item(bar)
        how_not_to_be_seen3.append_item(baz)
        # Create the final nested list (how_not_to_be_seen1)
        spam.append(how_not_to_be_seen2)
        foo.append(how_not_to_be_seen3)

        # Initialize an empty fake context
        context = {
            'document': None,
            'footnotes': [],
            'endnotes': [],
            'annotations': [],
            'rst_mode': False
        }
        expected = ('- In this picture, there are 47 people;\n'
                    '  none of them can be seen.\n'
                    '  \n'
                    '  - In this film, we hope to show you the\n'
                    '    value of not being seen.\n'
                    '  - Here is Mr. Bagthorpe of London, SE14.\n'
                    '  - He cannot be seen.\n'
                    '    \n'
                    '    - Now I am going to ask him to stand up.\n'
                    '    - Mr. Bagthorpe, will you stand up please?\n')
        self.assertEqual(how_not_to_be_seen1.get_formatted_text(context),
                         expected)
Exemplo n.º 14
0
    def test_insert_item(self):
        breakfast = odf_create_list()
        breakfast.insert_item('spam', 1)
        breakfast.insert_item('eggs', 2)
        item = odf_create_list_item('ham')
        breakfast.insert_item(item, -1)

        expected = ('<text:list>'
                    '<text:list-item>'
                    '<text:p>spam</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>ham</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>eggs</text:p>'
                    '</text:list-item>'
                    '</text:list>')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 15
0
    def test_insert_item(self):
        breakfast = odf_create_list()
        breakfast.insert_item(u'spam', 1)
        breakfast.insert_item(u'eggs', 2)
        item = odf_create_list_item(u'ham')
        breakfast.insert_item(item, -1)

        expected = ('<text:list>'
                      '<text:list-item>'
                        '<text:p>spam</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:p>ham</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:p>eggs</text:p>'
                      '</text:list-item>'
                    '</text:list>')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 16
0
    def test_get_formatted_text(self):
        # Create the items
        spam = odf_create_list_item(u'In this picture, there are 47 people;\n'
                                    u'none of them can be seen.')
        ham = odf_create_list_item(u'In this film, we hope to show you the\n'
                                   u'value of not being seen.\n')
        eggs = odf_create_list_item(u'Here is Mr. Bagthorpe of London, '
                                    u'SE14.\n')
        foo = odf_create_list_item(u'He cannot be seen.')
        bar = odf_create_list_item(u'Now I am going to ask him to stand up.')
        baz = odf_create_list_item(u'Mr. Bagthorpe, will you stand up please?')
        # Create the lists
        how_not_to_be_seen1 = odf_create_list()
        how_not_to_be_seen2 = odf_create_list()
        how_not_to_be_seen3 = odf_create_list()
        # Fill the lists
        # First list
        how_not_to_be_seen1.append_item(spam)
        # Second list
        how_not_to_be_seen2.append_item(ham)
        how_not_to_be_seen2.append_item(eggs)
        how_not_to_be_seen2.append_item(foo)
        # Third list
        how_not_to_be_seen3.append_item(bar)
        how_not_to_be_seen3.append_item(baz)
        # Create the final nested list (how_not_to_be_seen1)
        spam.append(how_not_to_be_seen2)
        foo.append(how_not_to_be_seen3)

        # Initialize an empty fake context
        context = {'document': None,
                   'footnotes': [],
                   'endnotes': [],
                   'annotations': [],
                   'rst_mode': False}
        expected = (u'- In this picture, there are 47 people;\n'
                    u'  none of them can be seen.\n'
                    u'  \n'
                    u'  - In this film, we hope to show you the\n'
                    u'    value of not being seen.\n'
                    u'  - Here is Mr. Bagthorpe of London, SE14.\n'
                    u'  - He cannot be seen.\n'
                    u'    \n'
                    u'    - Now I am going to ask him to stand up.\n'
                    u'    - Mr. Bagthorpe, will you stand up please?\n')
        self.assertEqual(how_not_to_be_seen1.get_formatted_text(context),
                         expected)
Exemplo n.º 17
0
    def test_insert_item(self):
        breakfast = odf_create_list()
        breakfast.insert_item(u"spam", 1)
        breakfast.insert_item(u"eggs", 2)
        item = odf_create_list_item(u"ham")
        breakfast.insert_item(item, -1)

        expected = (
            "<text:list>"
            "<text:list-item>"
            "<text:p>spam</text:p>"
            "</text:list-item>"
            "<text:list-item>"
            "<text:p>ham</text:p>"
            "</text:list-item>"
            "<text:list-item>"
            "<text:p>eggs</text:p>"
            "</text:list-item>"
            "</text:list>"
        )
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 18
0
    def test_get_formatted_text(self):
        # Create the items
        spam = odf_create_list_item(u"In this picture, there are 47 people;\n" u"none of them can be seen.")
        ham = odf_create_list_item(u"In this film, we hope to show you the\n" u"value of not being seen.\n")
        eggs = odf_create_list_item(u"Here is Mr. Bagthorpe of London, " u"SE14.\n")
        foo = odf_create_list_item(u"He cannot be seen.")
        bar = odf_create_list_item(u"Now I am going to ask him to stand up.")
        baz = odf_create_list_item(u"Mr. Bagthorpe, will you stand up please?")
        # Create the lists
        how_not_to_be_seen1 = odf_create_list()
        how_not_to_be_seen2 = odf_create_list()
        how_not_to_be_seen3 = odf_create_list()
        # Fill the lists
        # First list
        how_not_to_be_seen1.append_item(spam)
        # Second list
        how_not_to_be_seen2.append_item(ham)
        how_not_to_be_seen2.append_item(eggs)
        how_not_to_be_seen2.append_item(foo)
        # Third list
        how_not_to_be_seen3.append_item(bar)
        how_not_to_be_seen3.append_item(baz)
        # Create the final nested list (how_not_to_be_seen1)
        spam.append_element(how_not_to_be_seen2)
        foo.append_element(how_not_to_be_seen3)

        # Initialize an empty fake context
        context = {"document": None, "footnotes": [], "endnotes": [], "annotations": [], "rst_mode": False}
        expected = (
            u"- In this picture, there are 47 people;\n"
            u"  none of them can be seen.\n"
            u"  - In this film, we hope to show you the\n"
            u"    value of not being seen.\n"
            u"  - Here is Mr. Bagthorpe of London, SE14.\n"
            u"  - He cannot be seen.\n"
            u"    - Now I am going to ask him to stand up.\n"
            u"    - Mr. Bagthorpe, will you stand up please?\n"
        )
        self.assertEqual(how_not_to_be_seen1.get_formatted_text(context), expected)
Exemplo n.º 19
0
    def test_nested_list(self):
        breakfast = odf_create_list()
        spam = odf_create_list_item(u'spam')
        ham = odf_create_list_item(u'ham')
        eggs = odf_create_list_item(u'eggs')
        # First way: a list in an item, right next to a paragraph
        spam.append(odf_create_list([u'thé', u'café', u'chocolat']))
        breakfast.append_item(spam)
        breakfast.append_item(ham)
        breakfast.append_item(eggs)
        # Second way: a list as an item
        breakfast.append_item(breakfast.clone())

        expected = ('<text:list>\n'
                    '  <text:list-item>\n'
                    '    <text:p>spam</text:p>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>th&#233;</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>caf&#233;</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>chocolat</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>ham</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>eggs</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>spam</text:p>\n'
                    '        <text:list>\n'
                    '          <text:list-item>\n'
                    '            <text:p>th&#233;</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>caf&#233;</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>chocolat</text:p>\n'
                    '          </text:list-item>\n'
                    '        </text:list>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>ham</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>eggs</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '</text:list>\n')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(pretty=True), expected)
Exemplo n.º 20
0
body.append(toc)

# Add Paragraph
paragraph = odf_create_paragraph(u'lpOD generated Document')
body.append(paragraph)

# Add Heading
heading = odf_create_heading(1, text=u'Lists')
body.append(heading)

#
# A list
#
my_list = odf_create_list([u'chocolat', u'café'])

item = odf_create_list_item(u'Du thé')
item.append(odf_create_list([u'thé vert', u'thé rouge']))
my_list.append_item(item)

# insert item by position
my_list.insert_item(u'Chicorée', position=1)

# insert item by relative position
the = my_list.get_item(content=u'thé')
my_list.insert_item(u'Chicorée', before=the)
my_list.insert_item(u'Chicorée', after=the)

body.append(my_list)

#
# Footnote with odf_create_note of class "footnote" and insert_note
    commercial = odf_new_document('text')
    body = commercial.get_body()
    catalog = make_catalog()

    title1 = odf_create_heading(1, u"Basic commercial document")
    body.append(title1)
    title11 = odf_create_heading(2, u"Available products")
    body.append(title11)
    paragraph = odf_create_paragraph(u"Here the list:")
    body.append(paragraph)

    # List of products in a list :
    product_list = odf_create_list()
    body.append(product_list)
    for product in catalog:
        item = odf_create_list_item(u"%-10s, price: %.2f €" % (
                                            product.name, product.price))
        product_list.append(item)

    title12 = odf_create_heading(2, u"Your command")
    body.append(title12)

    command = {0 : 1, 1 : 12, 2 : 3, 4 : 5 }

    # A table in the text document :
    table = odf_create_table(u"Table")
    body.append(table)
    row = odf_create_row()
    row.set_values([u"Product", u"Price", u"Quantity", u"Amount"])
    table.set_row("A1", row)
    # or: table.set_row(0, row)
    row_number = 0
# -*- coding: UTF-8 -*-
from lpod.document import odf_new_document
from lpod.list import odf_create_list

document = odf_new_document('text')
body = document.get_body()

my_list = odf_create_list([u'chocolat', u'café'])
body.append(my_list)

from lpod.list import odf_create_list_item

item = odf_create_list_item(u"thé")
my_list.append(item)

#A sublist is simply a list as an item of another list

item.append( odf_create_list( [u"thé vert", u"thé rouge"] ) )

print body.serialize(True)
Exemplo n.º 23
0
 def test_create_item(self):
     item = odf_create_list_item()
     expected = '<text:list-item/>'
     self.assertEqual(item.serialize(), expected)
Exemplo n.º 24
0
 def test_create_item(self):
     item = odf_create_list_item()
     expected = '<text:list-item/>'
     self.assertEqual(item.serialize(), expected)
Exemplo n.º 25
0
# Import the list item factory module
from lpod.list import odf_create_list_item

# Create the document
my_document = odf_new_document('text')
body = my_document.get_body()

# Adding List
my_list = odf_create_list([u'Arthur', u'Ford', u'Trillian'])
# The list factory accepts a Python list of unicode strings and list items.

# The list can be written even though we will modify it afterwards:
body.append(my_list)

# Adding more List Item to the list, using the factory
item = odf_create_list_item(u'Marvin')
my_list.append_item(item)


if not os.path.exists('test_output'):
    os.mkdir('test_output')

output = os.path.join('test_output', 'my_document_with_list.odt')

# And finally save the document.
my_document.save(target=output, pretty=True)

# it should contain only :
print my_document.get_formatted_text()
# - Arthur
# - Ford
Exemplo n.º 26
0
 def list_item(self, text):
     item = odf_create_list_item()
     for elem in wrap_spans(text.get()):
         item.append(elem)
     return ODFPartialTree.from_metrics_provider([item], self)
# -*- coding: UTF-8 -*-
from lpod.document import odf_new_document
from lpod.list import odf_create_list

document = odf_new_document('text')
body = document.get_body()

my_list = odf_create_list([u'chocolat', u'café'])
body.append(my_list)

from lpod.list import odf_create_list_item

item = odf_create_list_item(u"thé")
my_list.append(item)

#A sublist is simply a list as an item of another list

item.append(odf_create_list([u"thé vert", u"thé rouge"]))

print body.serialize(True)
Exemplo n.º 28
0
    def test_nested_list(self):
        breakfast = odf_create_list()
        spam = odf_create_list_item('spam')
        ham = odf_create_list_item('ham')
        eggs = odf_create_list_item('eggs')
        # First way: a list in an item, right next to a paragraph
        spam.append(odf_create_list(['thé', 'café', 'chocolat']))
        breakfast.append_item(spam)
        breakfast.append_item(ham)
        breakfast.append_item(eggs)
        # Second way: a list as an item
        breakfast.append_item(breakfast.clone())

        expected = ('<text:list>\n'
                    '  <text:list-item>\n'
                    '    <text:p>spam</text:p>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>th&#233;</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>caf&#233;</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>chocolat</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>ham</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>eggs</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>spam</text:p>\n'
                    '        <text:list>\n'
                    '          <text:list-item>\n'
                    '            <text:p>th&#233;</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>caf&#233;</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>chocolat</text:p>\n'
                    '          </text:list-item>\n'
                    '        </text:list>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>ham</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>eggs</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '</text:list>\n')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(pretty=True), expected)
Exemplo n.º 29
0
 def list_item(self, text):
     item = odf_create_list_item()
     for elem in wrap_spans(text.get()):
         item.append(elem)
     return ODFPartialTree.from_metrics_provider([item], self)
Exemplo n.º 30
0
body.append(toc)

# Add Paragraph
paragraph = odf_create_paragraph(u'lpOD generated Document')
body.append(paragraph)

# Add Heading
heading = odf_create_heading(1, text=u'Lists')
body.append(heading)

#
# A list
#
my_list = odf_create_list([u'chocolat', u'café'])

item = odf_create_list_item(u'Du thé')
item.append(odf_create_list([u'thé vert', u'thé rouge']))
my_list.append_item(item)

# insert item by position
my_list.insert_item(u'Chicorée', position=1)

# insert item by relative position
the = my_list.get_item(content=u'thé')
my_list.insert_item(u'Chicorée', before=the)
my_list.insert_item(u'Chicorée', after=the)

body.append(my_list)

#
# Footnote with odf_create_note of class "footnote" and insert_note