Exemple #1
0
    def get_heading_counters_latex(self):
        if self.context != self.layout.context:
            # Only set the heading counters when exporting this chapter
            # directly. Otherwise it is not the first content.
            return ''

        counters = (
            'chapter',
            'section',
            'subsection',
            'subsubsection',
            'paragraph',
            'subparagraph',
        )

        helper = BookHelper()
        heading_numbers = helper.get_chapter_level(self.context)
        latex = []

        if heading_numbers[-1] == 1:
            del heading_numbers[-1]
        else:
            heading_numbers[-1] -= 1

        for level, num in enumerate(heading_numbers):
            latex.append(r'\setcounter{%s}{%s}' % (counters[level], num))

        if latex:
            latex.append('')

        return '\n'.join(latex)
 def export_table(self):
     context = aq_inner(self.context)
     file_ = StringIO()
     writer = csv.DictWriter(file_, self.active_columns,
                             dialect='excel', delimiter=';')
     first_column = self.active_columns[0]
     first_row = dict([(first_column, self.context.absolute_url())])
     writer.writerow(first_row)
     for row in context.data:
         writer.writerow(dict([
                     (col, row[col])
                     for col
                     in self.active_columns]))
     file_.seek(0)
     self.request.RESPONSE.setHeader(
         'Content-Type', 'text/csv; charset=utf-8')
     # we use all parent-ids (seperated by "_") as filename.
     # the user should be able to find the table later..
     # since we do not have enough charactors on windows, we need to use
     # a special numbering for generating the filename:
     # bookid.1.3.2.tableid.csv
     # for the chapters instead of the IDs the position-in-parent is used
     filename = [
         '%s.csv' % self.context.id,
         ]
     obj = aq_parent(aq_inner(self.context))
     filename.insert(0, BookHelper().get_chapter_level_string(obj))
     filename = '.'.join(filename)
     # set the request and send the file
     self.request.RESPONSE.setHeader('Content-disposition',
                                     'attachment; filename=%s' % filename)
     return file_.read()
    def test_generated_title_result_is_consistent(self):
        self.mock_inject_settings(self.textblock1, hideFromTOC=True)
        self.replay()

        self.assertTrue(self.textblock1.Schema().getField('hideFromTOC').get(
            self.textblock1))

        self.assertTrue(self.textblock1.Schema().getField('hideFromTOC').get(
            self.textblock1))

        self.assertTrue(self.textblock1.Schema().getField('hideFromTOC').get(
            self.textblock1))

        self.assertEqual(BookHelper()(self.textblock1), '<h4>Textblock1</h4>')

        self.assertEqual(BookHelper()(self.textblock1), '<h4>Textblock1</h4>')
Exemple #4
0
class SimpleLayoutListingViewlet(viewlets.SimpleLayoutListingViewlet):

    render = ViewPageTemplateFile('listing.pt')
    helper = BookHelper()

    def get_valid_parent_h_tags(self):
        return self.helper.generate_valid_hierarchy_h_tags(self.context)
Exemple #5
0
 def get_dynamic_title(self):
     return BookHelper()(self.context)
Exemple #6
0
 def get_dynamic_title(self):
     return BookHelper()(self.context, linked=True)
    def setUp(self):
        """ Setup test environment

        book
        |
        --- chapter1
        |
        --- chapter2
            |
            ---chapter3
            |  |
            |  ---chapter5
            |  |
            |  ---image
            |  |
            |  ---textblock1
            |  |
            |  ---textblock2
            |
            ---chapter4
        """
        super(TestUnitBookHelper, self).setUp()

        self._injection = {}

        # Helper object
        self.helper = BookHelper()

        #  Siteroot
        self.root = self.create_dummy()
        directlyProvides(self.root, IPloneSiteRoot)

        #  Book
        self.book = self.create_dummy()
        directlyProvides(self.book, [IBook, IFolderish])
        self.book = self.mocker.proxy(self.book, spec=False, count=False)
        self.expect(self.book.__parent__).result(self.root)
        self.expect(self.book.Title()).result('Book')
        self.mock_inject_settings(self.book)

        # Children of book
        self.chapter1 = self.create_dummy()
        directlyProvides(self.chapter1, IFolderish)
        self.chapter1 = self.mocker.proxy(self.chapter1,
                                          spec=False,
                                          count=False)
        self.expect(self.chapter1.__parent__).result(self.book)
        self.expect(self.chapter1.Title()).result('Chapter1')
        self.expect(self.chapter1.portal_type).result('Chapter')
        self.mock_inject_settings(self.chapter1)

        self.chapter2 = self.create_dummy()
        directlyProvides(self.chapter2, IFolderish)
        self.chapter2 = self.mocker.proxy(self.chapter2,
                                          spec=False,
                                          count=False)
        self.expect(self.chapter2.__parent__).result(self.book)
        self.expect(self.chapter2.Title()).result('Chapter2')
        self.expect(self.chapter2.portal_type).result('Chapter')
        self.mock_inject_settings(self.chapter2)

        #  Children of chapter 2
        self.chapter3 = self.create_dummy()
        directlyProvides(self.chapter3, IFolderish)
        self.chapter3 = self.mocker.proxy(self.chapter3,
                                          spec=False,
                                          count=False)
        self.expect(self.chapter3.__parent__).result(self.chapter2)
        self.expect(self.chapter3.Title()).result('Chapter3')
        self.expect(self.chapter3.portal_type).result('Chapter')
        self.mock_inject_settings(self.chapter3)

        self.chapter4 = self.create_dummy()
        directlyProvides(self.chapter4, IFolderish)
        self.chapter4 = self.mocker.proxy(self.chapter4,
                                          spec=False,
                                          count=False)
        self.expect(self.chapter4.__parent__).result(self.chapter2)
        self.expect(self.chapter4.Title()).result('Chapter4')
        self.expect(self.chapter4.portal_type).result('Chapter')
        self.mock_inject_settings(self.chapter4)

        #  Children of chapter 3
        self.chapter5 = self.create_dummy()
        directlyProvides(self.chapter5, IFolderish)
        self.chapter5 = self.mocker.proxy(self.chapter5,
                                          spec=False,
                                          count=False)
        self.expect(self.chapter5.__parent__).result(self.chapter3)
        self.expect(self.chapter5.Title()).result('Chapter5')
        self.expect(self.chapter5.portal_type).result('Chapter')
        self.mock_inject_settings(self.chapter5)

        self.image = self.mocker.mock(count=False)
        self.expect(self.image.__parent__).result(self.chapter3)
        self.expect(self.image.Title()).result('Image')
        self.expect(self.image.portal_type).result('Image')
        self.mock_inject_settings(self.image)

        self.textblock1 = self.mocker.mock(count=False)
        self.expect(self.textblock1.__parent__).result(self.chapter3)
        self.expect(self.textblock1.showTitle).result(True)
        self.expect(self.textblock1.Title()).result('Textblock1')
        self.expect(self.textblock1.title_or_id()).result('Textblock1')
        self.expect(self.textblock1.portal_type).result('Textblock')
        self.mock_inject_settings(self.textblock1, hideFromTOC=False)

        self.textblock2 = self.mocker.mock(count=False)
        self.expect(self.textblock2.__parent__).result(self.chapter3)
        self.expect(self.textblock2.__inner__).result(self.textblock2)
        self.expect(self.textblock2.showTitle).result(True)
        self.expect(self.textblock2.Title()).result('Textblock2')
        self.expect(self.textblock2.title_or_id()).result('Textblock2')
        self.expect(self.textblock2.portal_type).result('Textblock')
        self.mock_inject_settings(self.textblock2, hideFromTOC=False)

        # Folderish content
        self.expect(self.book.contentValues()).result(
            [self.chapter1, self.chapter2])
        self.expect(self.chapter1.contentValues()).result([])
        self.expect(self.chapter2.contentValues()).result(
            [self.chapter3, self.chapter4])
        self.expect(self.chapter3.contentValues()).result(
            [self.chapter5, self.image, self.textblock1, self.textblock2])
        self.expect(self.chapter4.contentValues()).result([])
        self.expect(self.chapter5.contentValues()).result([])