Пример #1
0
class DocumentsTab(CatalogListingView):

    types = ['File', 'Image']
    sort_on = 'created'
    show_selects = False
    show_menu = False

    columns = (
        {
            'column': 'Title',
            'column_title': _(u'column_title', default=u'Title'),
            'sort_index': 'sortable_title',
            'transform': helper.linked
        },
        {
            'column': 'documentDate',
            'column_title': _(u'column_date', default=u'date'),
            'transform': helper.readable_date
        },
        {
            'column': 'Creator',
            'column_title': _(u'column_creator', default=u'Creator'),
            'sort_index': 'sortable_creator',
            'transform': helper.readable_author
        },
        {
            'column': 'modified',
            'column_title': _(u'column_modified', default=u'modified'),
            'transform': helper.readable_date
        },
    )
Пример #2
0
 def getAlignmentVocabulary(self):
     return DisplayList((
             ('', _('automatically')),
             ('left', _('left')),
             ('right', _('right')),
             ('center', _('center')),
             ))
Пример #3
0
    def import_table(self):
        column = self.request.get('column', None)
        stream = self.request.get('file', None)
        enforce = self.request.get('enforce', False) and True
        if not stream:
            IStatusMessage(self.request).addStatusMessage(
                _(u'You didn\'t choose a file.'),
                type='error')
        if not column:
            IStatusMessage(self.request).addStatusMessage(
                _(u'You didn\'t choose a column.'),
                type='error')
        if not stream or not column:
            return False
        context = aq_inner(self.context)

        data = stream.read()
        # fix bad excel carriage returns
        data = data.replace('\r\n', '\n').replace('\r', '\n')
        dialect = csv.Sniffer().sniff(data)

        first_row_plain, data = data.split('\n', 1)
        first_row = first_row_plain.strip().split(dialect.delimiter)

        reader = csv.DictReader(StringIO(data),
                                fieldnames=self.active_columns,
                                dialect=dialect)
        rows = list(reader)

        # check the first row (containing the url)
        if not enforce:
            url = first_row[0]
            if url != self.context.absolute_url():
                IStatusMessage(self.request).addStatusMessage(
                    _(u'The file does not seem to belong to this table.'),
                    type='error')
                return False

        # import the data
        data = context.getData()
        for i, row in enumerate(rows):
            # XXX This is very ugly! Perhaps we can also add new feature like
            # add new rows, just modify, or delete all rows and build it new
            if i < int(context.headerRows):
                # do not update header- or footer-rows
                continue
            try:
                data[i][column] = row[column]
            except IndexError:
                break

        context.setData(data)
        context.processForm()
        message = 'Die Spalte wurde erfolgreich importiert'
        IStatusMessage(self.request).addStatusMessage(message, type='info')
        return self.request.RESPONSE.redirect('.')
Пример #4
0
 def getRowFormatVocabulary(self):
     return DisplayList((
             ('', _('Normal')),
             ('bold', _('Bold')),
             ('indent2', _('2mm indent')),
             ('indent10', _('10mm indent')),
             ('indent2 bold', _('2mm ind. + bold')),
             ('indent10 bold', _('10mm ind. + bold')),
             ('noborders', _('Row without line')),
             ('grey', _('Grey font')),
             ('scriptsize', _('Small font')),
             ('fullColspan', _('Strech first line')),
             ))
Пример #5
0
    def get_index_title(self):
        context_language_method = getattr(self.context, 'getLanguage', None)
        if context_language_method:
            language_code = context_language_method()

        else:
            ltool = getToolByName(self.context, 'portal_languages')
            language_code = ltool.getPreferredLanguage()

        return translate(_(u'title_index', default=u'Index'),
                         target_language=language_code)
Пример #6
0
    def get_index_title(self):
        context_language_method = getattr(self.context, 'getLanguage', None)
        if context_language_method:
            language_code = context_language_method()

        else:
            ltool = getToolByName(self.context, 'portal_languages')
            language_code = ltool.getPreferredLanguage()

        return translate(_(u'title_index', default=u'Index'),
                         target_language=language_code)
Пример #7
0
class BooksTab(Tab):

    types = 'Book'
    sort_on = 'sortable_title'
    show_selects = False
    show_menu = False

    columns = (
        {
            'column': 'Title',
            'column_title': _(u'column_title', default=u'Title'),
            'sort_index': 'sortable_title',
            'transform': helper.linked
        },
        {
            'column': 'Creator',
            'column_title': _(u'column_creator', default=u'Creator'),
            'sort_index': 'sortable_creator',
            'transform': helper.readable_author
        },
    )
Пример #8
0
    def _validate_table_width(self, html, match, errors):
        table = TableConverter(None, match, html)
        table.parse()

        for column in table.columns:
            if not column.get_width():
                errors.add(
                    _(u'table_width_validation_warning',
                      u'Please specify the width of the table ' +
                      u'columns / cells.'))
                return errors

        return errors
Пример #9
0
    def _validate_table_width(self, html, match, errors):
        table = TableConverter(None, match, html)
        table.parse()

        for column in table.columns:
            if not column.get_width():
                errors.add(
                    _(
                        u'table_width_validation_warning',
                        u'Please specify the width of the table ' +
                        u'columns / cells.'))
                return errors

        return errors
Пример #10
0
    def _page_label(self, pageref):
        msg = _(u'latex_page_reference',
                default=u'See page ${pageref}',
                mapping={'pageref': pageref})

        context = self.get_context()
        context_language_method = getattr(context, 'getLanguage', None)
        if context_language_method:
            language_code = context_language_method()

        else:
            ltool = getToolByName(context, 'portal_languages')
            language_code = ltool.getPreferredLanguage()

        return translate(msg, target_language=language_code).encode('utf-8')
Пример #11
0
    def _page_label(self, pageref):
        msg = _(u'latex_page_reference',
                default=u'See page ${pageref}',
                mapping={'pageref': pageref})

        context = self.get_context()
        context_language_method = getattr(context, 'getLanguage', None)
        if context_language_method:
            language_code = context_language_method()

        else:
            ltool = getToolByName(context, 'portal_languages')
            language_code = ltool.getPreferredLanguage()

        return translate(msg, target_language=language_code).encode('utf-8')
Пример #12
0
from zope.schema.vocabulary import getVocabularyRegistry


BookSchema = (folder.ATFolderSchema.copy() +
              NextPreviousAwareSchema.copy() +
              atapi.Schema((

            atapi.StringField(
                name='latex_layout',
                required=True,

                vocabulary_factory='ftw.book.layoutsVocabulary',
                default_method='getDefaultLaTeXLayout',

                widget=atapi.SelectionWidget(
                    label=_(u'book_label_layout',
                            default=u'Layout'))),

            atapi.BooleanField(
                name='use_titlepage',
                default=True,

                widget=atapi.BooleanWidget(
                    label=_(u'book_label_use_titlepage',
                            default=u'Embedd a title page'),
                    description=_(u'book_help_use_titlepage',
                                  default=u''))),

            atapi.BooleanField(
                name='use_toc',
                default=True,
Пример #13
0
    from Products.LinguaPlone import public as atapi
else:
    from Products.Archetypes import atapi


htmlblock_schema = ATContentTypeSchema.copy() + \
    textblock.default_schema.copy()

htmlblock_schema['title'].required = False
htmlblock_schema['description'].widget.visible = {'view': 'invisible',
                                                  'edit': 'invisible'}

htmlblock_schema['text'].validators = ()
htmlblock_schema['text'].default_output_type = 'text/html'
htmlblock_schema['text'].widget = atapi.TextAreaWidget(
    label=_(u'label_html', default=u'HTML'),
    description='',
    rows=32,
    cols=70)

finalize(htmlblock_schema)


class HTMLBlock(textblock.TextBlock):
    """HTML block for books.
    """

    security = ClassSecurityInfo()
    implements(IHTMLBlock)
    schema = htmlblock_schema
Пример #14
0
 def getTestVo():
     return (_('a', default = 'a'),)
Пример #15
0
class DefaultBookLayoutExtender(object):
    """Schema extender, adding the layout-specific fields "release", "author"
    and "author_address" to the book when the default layout is selected.
    """

    adapts(IBook)
    implements(ISchemaExtender)

    fields = [
        StringField(name='release',
                    default='',
                    required=False,
                    widget=atapi.StringWidget(label=_(u'book_label_release',
                                                      default=u'Release'), )),
        StringField(name='author',
                    default='',
                    required=False,
                    widget=atapi.StringWidget(label=_(u'book_label_author',
                                                      default=u'Author'), )),
        TextField(name='author_address',
                  default='',
                  required=False,
                  default_content_type='text/plain',
                  allowable_content_types=('text/plain', ),
                  default_output_type='text/plain',
                  widget=atapi.TextAreaWidget(
                      label=_(u'book_label_author_address',
                              default=u'Author Address'), )),
        FileField(name='titlepage_logo',
                  required=False,
                  widget=atapi.FileWidget(
                      label=_(u'book_label_titlepage_logo',
                              default=u'Titlepage logo'),
                      description=_(u'book_help_titlepage_logo',
                                    default=u'Upload an image or a PDF, which '
                                    u'will be displayed on the titlepage'))),
        IntegerField(name='titlepage_logo_width',
                     default=0,
                     required=False,
                     size=3,
                     widget=atapi.IntegerWidget(
                         label=_(u'book_label_titlepage_logo_width',
                                 default=u'Titlepage logo width (%)'),
                         description=_(
                             u'book_help_titlepage_logo_width',
                             default=u'Width of the titlepage logo in '
                             u'percent of the content width.'),
                         size=3,
                         maxlength=3)),
    ]

    def __init__(self, context):
        self.context = context

    def getFields(self):
        # Checking whether the request provides the
        # IDefaultBookLayoutSelectionLayer interface does not work when
        # LinguaPlone is installed.
        # Looks like this method is called before
        # BookTraverse.publishTraverse() marks the request with the interface.

        if self.context.isTemporary():
            return []

        layout_layer_name = getattr(self.context, 'latex_layout', None)
        if layout_layer_name:
            layout_layer = resolve(layout_layer_name)
            if layout_layer == IDefaultBookLayoutSelectionLayer:
                return self.fields
        return []
Пример #16
0
class TextField(ExtensionField, public.TextField):
    pass


class FileField(ExtensionField, public.FileField):
    pass


class IntegerField(ExtensionField, public.IntegerField):
    pass

class IProceedingsLayoutSelectionLayer(Interface):
    """Request layer interface for selecting the proceedings layout.
    """

register_book_layout(IProceedingsLayoutSelectionLayer, _(u'Proceedings layout'))

class ProceedingsLayoutBookExtender(object):
    """Schema extender, adding the layout-specific(for ProccedingsLayout) fields for Book,
    including "edtior".
    """

    adapts(IBook)
    implements(ISchemaExtender)
    fields = [
        StringField(
            name='author',
            default='',
            required=False,
            widget=atapi.StringWidget(
                label = _(u'book_label_editor',default=u'Editor'),
Пример #17
0

class FileField(ExtensionField, public.FileField):
    pass


class IntegerField(ExtensionField, public.IntegerField):
    pass


class IDefaultBookLayoutSelectionLayer(Interface):
    """Request layer interface for selecting the default book layout.
    """

register_book_layout(IDefaultBookLayoutSelectionLayer,
                     _(u'Default layout'))


class DefaultBookLayoutExtender(object):
    """Schema extender, adding the layout-specific fields "release", "author"
    and "author_address" to the book when the default layout is selected.
    """

    adapts(IBook)
    implements(ISchemaExtender)

    fields = [
        StringField(
            name='release',
            default='',
            required=False,
Пример #18
0
from ftw.book.config import PROJECTNAME
from ftw.book.interfaces import IBook
from zope.interface import implements
from zope.schema.vocabulary import getVocabularyRegistry


BookSchema = (folder.ATFolderSchema.copy() +
              NextPreviousAwareSchema.copy() +
              atapi.Schema((

            atapi.IntegerField(
                name='web_toc_depth',
                default=0,
                searchable=False,
                widget=atapi.IntegerWidget(
                    label=_(u'label_web_toc_depth',
                            default=u'Table of contents depth'),
                    description=_(u'help_web_toc_depth', default=u''))),

            atapi.StringField(
                name='latex_layout',
                required=True,

                vocabulary_factory='ftw.book.layoutsVocabulary',
                default_method='getDefaultLaTeXLayout',

                widget=atapi.SelectionWidget(
                    label=_(u'book_label_layout',
                            default=u'Layout'))),

            atapi.BooleanField(
                name='use_titlepage',
Пример #19
0
    # No multilingual support
    from Products.Archetypes import atapi
from ftw.book import _
from ftw.book.config import PROJECTNAME
from ftw.book.interfaces import IBook
from zope.interface import implements
from zope.schema.vocabulary import getVocabularyRegistry

BookSchema = (
    folder.ATFolderSchema.copy() + NextPreviousAwareSchema.copy() +
    atapi.Schema((
        atapi.IntegerField(name='web_toc_depth',
                           default=0,
                           searchable=False,
                           widget=atapi.IntegerWidget(
                               label=_(u'label_web_toc_depth',
                                       default=u'Table of contents depth'),
                               description=_(u'help_web_toc_depth',
                                             default=u''))),
        atapi.StringField(
            name='latex_layout',
            required=True,
            vocabulary_factory='ftw.book.layoutsVocabulary',
            default_method='getDefaultLaTeXLayout',
            widget=atapi.SelectionWidget(
                label=_(u'book_label_layout', default=u'Layout'))),
        atapi.BooleanField(name='use_titlepage',
                           default=True,
                           widget=atapi.BooleanWidget(
                               label=_(u'book_label_use_titlepage',
                                       default=u'Embedd a title page'),
                               description=_(u'book_help_use_titlepage',
Пример #20
0
class LaTeXCodeInjectionExtender(object):
    adapts(ILaTeXCodeInjectionEnabled)
    implements(IOrderableSchemaExtender)

    _fields = []

    add_field(LaTeXCodeField(
            name='preLatexCode',
            schemata='LaTeX',
            default_content_type='text/plain',
            allowable_content_types='text/plain',
            write_permission=ModifyLaTeXInjection,

            widget=atapi.TextAreaWidget(
                label=_(u'pre_latex_code_label',
                        default=u'LaTeX code above content'),
                description=_(u'pre_latex_code_help',
                              default=u''))))

    add_field(LaTeXCodeField(
            name='postLatexCode',
            schemata='LaTeX',
            default_content_type='text/plain',
            allowable_content_types='text/plain',
            write_permission=ModifyLaTeXInjection,

            widget=atapi.TextAreaWidget(
                label=_(u'post_latex_code_label',
                        default=u'LaTeX code beneath content'),
                description=_(u'post_latex_code_help',
                              default=u''))))

    add_field(ExtensionStringField(
            name='preferredColumnLayout',
            schemata='LaTeX',
            default=NO_PREFERRED_LAYOUT,
            write_permission=ModifyLaTeXInjection,
            vocabulary=((NO_PREFERRED_LAYOUT,
                         _('injection_label_no_preferred_column_layout',
                           default='No preferred column layout')),

                        (ONECOLUMN_LAYOUT,
                         _('injection_label_one_column_layout',
                           default='One column layout')),

                        (TWOCOLUMN_LAYOUT,
                         _('injection_label_two_column_layout',
                           default='Two column layout'))),

            widget=atapi.SelectionWidget(
                label=_(u'injection_label_preferred_column_layout',
                        default=u'Preferred layout'),
                description=_(
                    u'injection_help_preferred_column_layout',
                    default=u'When choosing a one or two column layout, the '
                    u'layout will switched for this content and all '
                    u'subsequent contents in the PDF, if necessary. '
                    u'If "no preferred layout" is selected the currently '
                    u'active layout is kept.'))))

    add_field(
        interfaces=[IChapter, ISimpleLayoutBlock],
        field=ExtensionBooleanField(
            name='latexLandscape',
            schemata='LaTeX',
            default=False,
            write_permission=ModifyLaTeXInjection,

            widget=atapi.BooleanWidget(
                label=_(u'injection_label_landscape',
                        default=u'Use landscape'))))

    add_field(
        interfaces=[IChapter, ISimpleLayoutBlock],
        field=ExtensionBooleanField(
            name='preLatexClearpage',
            schemata='LaTeX',
            default=False,
            write_permission=ModifyLaTeXInjection,

            widget=atapi.BooleanWidget(
                label=_(u'injection_label_insert_clearpage_before_content',
                        default=u'Insert page break before this content'))))

    add_field(
        interfaces=[IChapter, ISimpleLayoutBlock],
        field=ExtensionBooleanField(
            name='postLatexClearpage',
            schemata='LaTeX',
            default=False,
            write_permission=ModifyLaTeXInjection,

            widget=atapi.BooleanWidget(
                label=_(u'injection_label_insert_clearpage_after_content',
                        default=u'Insert page break after this content'))))

    add_field(
        interfaces=[IChapter, ISimpleLayoutBlock],
        field=ExtensionBooleanField(
            name='preLatexNewpage',
            schemata='LaTeX',
            default=False,
            write_permission=ModifyLaTeXInjection,

            widget=atapi.BooleanWidget(
                label=_(u'injection_label_insert_newpage_before_content',
                        default=u'Insert column break before this content'),
                description=_(u'This option inserts a column break when '
                              u'two column layout is active.'))))

    add_field(
        # hideFromTOC is only useful when we have a showTitle checkbox too
        condition=hide_from_toc_condition,
        insert_after='showTitle',
        field=ExtensionBooleanField(
            name='hideFromTOC',
            default=False,
            required=False,

            widget=atapi.BooleanWidget(
                label=_(u'injection_label_hide_from_toc',
                        default=u'Hide from table of contents'),
                description=_(u'injection_help_hide_from_toc',
                              default=u'Hides the title from the table of '
                              u'contents and does not number the heading.'))))

    def __init__(self, context):
        self.context = context

    def getFields(self):
        if not self._context_is_within_book():
            return []

        fields = []

        for item in self._fields:
            condition = item.get('condition')
            if condition and not condition(self.context):
                continue

            interfaces = item.get('interfaces')
            if interfaces:
                provided = [iface for iface in interfaces
                            if iface.providedBy(self.context)]
                if len(provided) == 0:
                    continue

            fields.append(item.get('field'))

        return fields

    def getOrder(self, schematas):
        for item in self._fields:
            insert_after = item.get('insert_after')
            if not insert_after:
                continue

            field = item.get('field')
            if field.schemata not in schematas:
                continue

            schemata = schematas[field.schemata]
            if insert_after not in schemata or field.__name__ not in schemata:
                continue

            schemata.remove(field.__name__)
            schemata.insert(schemata.index(insert_after) + 1, field.__name__)

        return schematas

    def _context_is_within_book(self):
        # In some cases REQUEST is no available.
        if not hasattr(self.context, 'REQUEST'):
            return False

        if IWithinBookLayer.providedBy(self.context.REQUEST):
            return True
        return False
Пример #21
0
    from Products.Archetypes import atapi
from Products.Archetypes.public import DisplayList
from ftw.book import _
from ftw.book.config import PROJECTNAME
from ftw.book.interfaces import ITable
from ftw.book.table import generator
from zope.interface import implements
from simplelayout.base.interfaces import ISimpleLayoutBlock
from simplelayout.types.common.content import simplelayout_schemas


MAX_AMOUNT_OF_COLUMNS = 12
MAX_AMOUNT_OF_HEADER_ROWS = 5
MAX_AMOUNT_OF_FOOTER_ROWS = 5
BORDER_LAYOUTS = (
    ('grid', _(u'table_label_gridLayout', default=u'Grid Layout')),
    ('invisible', _(u'table_label_invisible', default=u'No borders')),
    ('fancy_listing', _(u'table_label_fancy_listing',
        default=u'Horizontal borders')),
    )


table_schema = (ATContentTypeSchema.copy() +
                atapi.Schema((

            atapi.BooleanField(
                name='showTitle',
                schemata='default',
                default=False,
                widget=atapi.BooleanWidget(
                    label=_(u'label_show_title', default=u'Show title'),
Пример #22
0

class FileField(ExtensionField, public.FileField):
    pass


class IntegerField(ExtensionField, public.IntegerField):
    pass


class IDefaultBookLayoutSelectionLayer(Interface):
    """Request layer interface for selecting the default book layout.
    """


register_book_layout(IDefaultBookLayoutSelectionLayer, _(u'Default layout'))


class DefaultBookLayoutExtender(object):
    """Schema extender, adding the layout-specific fields "release", "author"
    and "author_address" to the book when the default layout is selected.
    """

    adapts(IBook)
    implements(ISchemaExtender)

    fields = [
        StringField(name='release',
                    default='',
                    required=False,
                    widget=atapi.StringWidget(label=_(u'book_label_release',
Пример #23
0
else:
    from Products.Archetypes import atapi


htmlblock_schema = ATContentTypeSchema.copy() + \
    textblock.default_schema.copy()

htmlblock_schema['title'].required = False
htmlblock_schema['description'].widget.visible = {
    'view': 'invisible',
    'edit': 'invisible'
}

htmlblock_schema['text'].validators = ()
htmlblock_schema['text'].default_output_type = 'text/html'
htmlblock_schema['text'].widget = atapi.TextAreaWidget(label=_(
    u'label_html', default=u'HTML'),
                                                       description='',
                                                       rows=32,
                                                       cols=70)

finalize(htmlblock_schema)


class HTMLBlock(textblock.TextBlock):
    """HTML block for books.
    """

    security = ClassSecurityInfo()
    implements(IHTMLBlock)
    schema = htmlblock_schema
Пример #24
0
 def getIndentVocabulary(self):
     return DisplayList((
             ('', _('no indent')),
             ('indent2', _('2mm')),
             ('indent10', _('10mm')),
             ))