class CreatorSubstitution(BaseSubstitution):
    adapts(IComment)

    category = _(u'Discussion Item')
    description = _(u'Creator')

    def safe_call(self):
        return self.context.Creator()
class TextSubstitution(BaseSubstitution):
    adapts(IComment)

    category = _(u'Discussion Item')
    description = _(u'Text')

    def safe_call(self):
        return self.context.getText(targetMimetype='text/plain')
class ModifiedSubstitution(DateSubstitution):
    adapts(IComment)

    category = _(u'Discussion Item')
    description = _(u'Modified')

    def safe_call(self):
        return self.formatDate(self.context.modification_date)
Example #4
0
    def __call__(self, deact=0):
        context = aq_inner(self.context)
        adapted = IMarkerInterfaces(context)
        if not deact:
            adapted.update(add=[IBlog], remove=[])
            self.prepare_blog()
            message = _('Blog enabled correctly')
            notify(BlogEnabled(context))
            IStatusMessage(self.request).add(message)
        else:
            adapted.update(add=[], remove=[IBlog])
            notify(BlogDisabled(context))
            message = _('Blog disabled correctly')
            IStatusMessage(self.request).add(message)

        return self.request.response.redirect(context.absolute_url())
Example #5
0
class BlogExtender(object):
    adapts(IBlog)
    implements(ISchemaExtender)

    fields = [
        MyImageField("image",
                     required=True,
                     languageIndependent=True,
                     max_size=(225, 55),
                     sizes={
                         'mini': (200, 200),
                         'thumb': (128, 128),
                         'tile': (64, 64),
                         'icon': (32, 32),
                         'listing': (16, 16),
                     },
                     widget=atapi.ImageWidget(
                         label=_(u'Small image'),
                         description=_(u'Upload your small image here. '),
                         show_content_type=False)),
        MySecondImageField(
            "header_image",
            required=False,
            languageIndependent=True,
            max_size=(870, 150),
            sizes={
                'large': (768, 768),
                'preview': (400, 400),
                'mini': (200, 200),
                'thumb': (128, 128),
                'tile': (64, 64),
                'icon': (32, 32),
                'listing': (16, 16),
            },
            widget=atapi.ImageWidget(
                label=_(u'Header image'),
                description=_(u'Upload the image for the header of your blog'),
                show_content_type=False)),
        MyLinesField(
            "email",
            required=True,
            widget=atapi.LinesWidget(
                label=_(u'E-mail'),
                description=
                _('E-mail addresses where you will receive the replies of your posts. One per line.'
                  ))),
        MyStringField2(
            "feedburner_posts",
            required=False,
            widget=atapi.StringWidget(
                label=_(u"FeedBurner address for your blog posts"),
                description=
                _("If you are using FeedBurner to manage your RSS feeds, enter here the address of your posts' feed"
                  ))),
        MyStringField3(
            "feedburner_comments",
            required=False,
            widget=atapi.StringWidget(
                label=_(u"FeedBurner address for your blog comments"),
                description=
                _("If you are using FeedBurner to manage your RSS feeds, enter here the address of your comments' feed"
                  ))),
    ]

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

    def getFields(self):
        return self.fields
class TitleSubstitution(BaseTitleSubstitution):
    adapts(IComment)

    category = _(u'Discussion Item')
    description = _(u'Title')
class UrlSubstitution(BaseUrlSubstitution):
    adapts(IComment)

    category = _(u'Discussion Item')
    description = _(u'URL')
Example #8
0
    def prepare_blog(self):
        context = aq_inner(self.context)
        lang = context.Language()
        if 'images' not in context.keys():
            images = _createObjectByType('Folder',
                                context,
                                id='images',
                                title=translate(_(u'Images and files'),
                                                domain='cs.blogextender',
                                                target_language=lang,
                                    ),
                )
            images.setConstrainTypesMode(ENABLED)
            images.setLocallyAllowedTypes(['Image', 'File'])
            images.setExcludeFromNav(True)
            images.reindexObject()
            wstate = getMultiAdapter((images, self.request),
                name=u'plone_context_state').workflow_state()
            if wstate == 'private':
                try:
                    pw = getToolByName(context, 'portal_workflow')
                    pw.doActionFor(images, 'publish')
                except:
                    from logging import getLogger
                    log = getLogger(__name__)
                    log.info('Cannot publish %s' % images.Title())

        if 'replies' not in context.keys():
            replies = _createObjectByType('Collection',
                                context,
                                id='replies',
                                title=_(u'Latest replies'),
                )
            query = [{'i': 'portal_type',
                      'o': 'plone.app.querystring.operation.selection.is',
                      'v': ['Discussion Item']
                      },
                     {'i': 'review_state',
                      'o': 'plone.app.querystring.operation.selection.is',
                      'v': ['published']
                      },
                     {'i': 'path',
                      'o': 'plone.app.querystring.operation.string.path',
                      'v': '/'.join(context.getPhysicalPath())
                      }
                      ]
            replies.setQuery(query)
            replies.setExcludeFromNav(True)
            replies.reindexObject()
            wstate = getMultiAdapter((replies, self.request),
                name=u'plone_context_state').workflow_state()
            if wstate == 'private':
                try:
                    pw = getToolByName(context, 'portal_workflow')
                    pw.doActionFor(replies, 'publish')
                except:
                    from logging import getLogger
                    log = getLogger(__name__)
                    log.info('Cannot publish %s' % replies.Title())
            replies.reindexObject()

        else:
            replies = context.get('replies')

        context.setConstrainTypesMode(ENABLED)
        context.setLocallyAllowedTypes(['News Item'])

        # block portlets
        left_manager = getUtility(IPortletManager,
                                  name='plone.leftcolumn',
                                  context=context,
                                  )
        right_manager = getUtility(IPortletManager,
                                  name='plone.rightcolumn',
                                  context=context,
                                  )
        left_blacklist = getMultiAdapter((context, left_manager),
                                        ILocalPortletAssignmentManager)

        right_blacklist = getMultiAdapter((context, right_manager),
                                        ILocalPortletAssignmentManager)

        left_blacklist.setBlacklistStatus(CONTEXT_CATEGORY, True)
        right_blacklist.setBlacklistStatus(CONTEXT_CATEGORY, True)

        # add portlets
        right_mapping = getMultiAdapter((context, right_manager),
                                        IPortletAssignmentMapping)

        biportlet = BIAssignment()
        purl = getToolByName(context, 'portal_url')
        navportlet = NavAssignment(root='/'.join(purl.getRelativeContentPath(context)))
        archiveportlet = ArAssignment()
        ngcollection = NGAssignment(
            header=translate(_(u'Latest comments'),
                            domain='cs.blogextender',
                            target_language=lang
                            ),
            target_collection='/'.join(replies.getPhysicalPath()[2:]),
            limit=10,
            show_more=False,
            show_dates=True,
            template='cs.blogextender.browser-portlet-templates:comments_template.pt'
            )

        right_mapping[str(uuid.uuid1())] = biportlet
        right_mapping[str(uuid.uuid1())] = navportlet
        right_mapping[str(uuid.uuid1())] = ngcollection
        right_mapping[str(uuid.uuid1())] = archiveportlet