예제 #1
0
 def delete_article(self):
     """Delete an Article from Apple News"""
     adapter = self.get_adapter()
     article_id = adapter.data['id']
     try:
         adapter.delete_article()
     except AppleNewsError as e:
         log('Handled Apple News Error {}: {}'.format(e, e.data))
         if e.code == 404:
             message = _(
                 u'error_article_delete_cleared',
                 default=u'Article was already deleted (${article_id}). '
                         u'Clearing Id.',
                 mapping={u'article_id': article_id}
             )
             IStatusMessage(self.request).addStatusMessage(
                 message, "warning"
             )
         else:
             message = _(
                 u'error_deleting_article',
                 default=u'Error ${error_code} deleting article '
                         u'(${article_id}). See logs for more details.',
                 mapping={u'error_code': six.text_type(e.code or u''),
                          u'article_id': article_id}
             )
             IStatusMessage(self.request).addStatusMessage(message, "error")
     else:
         IStatusMessage(self.request).addStatusMessage(
             _(u'article_deleted',
               default=u"Deleted article with id: ${article_id}",
               mapping={u'article_id': article_id}),
             "info"
         )
예제 #2
0
 def update_article(self):
     """Update an Article in Apple News"""
     CheckAuthenticator(self.request)
     if not _checkPermission('Apple News: Manage News Content',
                             self.context):
         raise Unauthorized
     adapter = self.get_adapter()
     try:
         adapter.update_article()
     except AppleNewsError as e:
         log('Handled Apple News Error {}: {}'.format(e, e.data))
         article_id = adapter.data.get('id', u'')
         if e.code == 409:
             message = _(
                 u'unable_to_update_article_conflicts',
                 default=u'Unable to update article (${article_id}) '
                         u'because it has conflicting changes. '
                         u'Retry again to refresh.',
                 mapping={u'article_id': article_id}
             )
         elif e.code == 418:
             message = _(u'Error article not published')
         else:
             message = _(
                 u'error_updating_article',
                 default=u'Error ${error_code} updating article '
                         u'(${article_id}). See logs for more details.',
                 mapping={u'error_code': six.text_type(e.code) or u'',
                          u'article_id': article_id}
             )
         IStatusMessage(self.request).addStatusMessage(message, "error")
     else:
         article_id = adapter.data.get('id', u'')
         IStatusMessage(self.request).addStatusMessage(
             _(u'updated_article_success',
               default=u"Updated article with id: ${article_id}",
               mapping={u'article_id': article_id}),
             "info"
         )
예제 #3
0
    def create_article(self):
        """Create a new Article in Apple News"""
        CheckAuthenticator(self.request)
        if not _checkPermission('Apple News: Manage News Content',
                                self.context):
            raise Unauthorized
        adapter = self.get_adapter()
        try:
            article_data = adapter.create_article()
        except AppleNewsError as e:
            if e.code == 418:
                IStatusMessage(self.request).addStatusMessage(
                    _(u"Added new article"),
                    "info"
                )
                return
            raise

        IStatusMessage(self.request).addStatusMessage(
            _(u'article_added',
              default=u"Added new article with id: ${article_id}",
              mapping={u'article_id': article_data['data']['id']}),
            "info"
        )
예제 #4
0
class IAppleNewsSettings(Interface):
    """Control Panel Settings Interface"""

    api_key_id = schema.TextLine(title=_(u'Apple News API Key Id'))
    api_key_secret = schema.TextLine(title=_(u'Apple News API Key Secret'))
    channel_id = schema.TextLine(title=_(u'Apple News Channel Id'))
    canonical_url = schema.URI(
        title=_(u'Canonical Site URL'),
        description=_(u'Enter the canonical URL for this website, '
                      u'if it differs from the CMS editing url.'),
        required=False)
    primary_scale = schema.Choice(
        title=_(u'Primary Image Scale'),
        description=_(u'Image scale to use for primary Apple News image.'),
        vocabulary=u'plone.app.vocabularies.ImagesScales',
        default=u'large',
        required=False)
    body_scale = schema.Choice(
        title=_(u'Body Image Scale'),
        description=_(u'Image scale to use for images in text body.'),
        vocabulary=u'plone.app.vocabularies.ImagesScales',
        default=u'large',
        required=True)
    thumb_scale = schema.Choice(
        title=_(u'Thumbnail Scale'),
        description=_(u'Image scale to use for Apple News thumbnail.'),
        vocabulary=u'plone.app.vocabularies.ImagesScales',
        default=u'preview',
        required=True)
    footer_html = schema.Text(
        title=_(u'Footer HTML'),
        description=_(u'Optional custom HTML for article footers'),
        required=False)
    article_customizations = schema.Text(
        title=_(u'Custom Article JSON'),
        description=_(u'Customized Article JSON for e.g. style and layout.'
                      u'Will be merged with default.'),
        constraint=json_constraint,
        required=False)
예제 #5
0
import json
from copy import deepcopy
from zope.component import queryUtility
from plone.registry.interfaces import IRegistry
from .interfaces import IAppleNewsSettings
from .templates import ARTICLE_BASE
from kcrw.plone_apple_news import _

SEP = _(u'list_separator', default=u',')
FINAL_SEP = _(u'final_list_seperator', default=u' and')


def get_settings():
    registry = queryUtility(IRegistry)
    if registry is not None:
        return registry.forInterface(
            IAppleNewsSettings, prefix='kcrw.apple_news',
            check=False
        )
    return {}


def pretty_text_list(entries, context):
    if not entries:
        return u''
    if len(entries) == 1:
        return entries[0]

    sep = context.translate(SEP)
    final_sep = context.translate(FINAL_SEP)
    result = u''