class IVLibrasNewsSettings(model.Schema):
    """Schema for the control panel form."""

    access_token = schema.ASCIILine(
        title=_(u'Access Token'),
        description=_(u'Token to access the VLibras News API service.'),
        default='',
        required=True,
    )
Example #2
0
class IVLibrasNews(model.Schema):
    """VLibras News behavior. Read-only field to store the address of
    the video containing the LIBRAS translation of an item. A `None`
    value indicates content that was present before the installation
    of the feature; this content has no translation available. An empty
    string indicates content being processed.
    """

    translation_url = schema.ASCIILine(
        title=_(u'Video URL'),
        description=
        _(u'The URL of the video containing the LIBRAS translation for this item.'
          ),
        required=False,
        readonly=True,
        default='',  # translation being processed
        missing_value=None,  # no translation available
    )
Example #3
0
# -*- coding: utf-8 -*-
from brasil.gov.vlibrasnews import _
from brasil.gov.vlibrasnews.logger import logger
from plone import api
from requests.exceptions import RequestException
from zope.globalrequest import getRequest

import requests

CREATE_URL = 'http://150.165.204.81:3000/publish'
UPDATE_URL = 'http://150.165.204.81:3000/publish/{0}'
DELETE_URL = GET_URL = 'http://150.165.204.81:3000/videos/{0}'

CREATE_ERROR = _(u'There was an error while creating the LIBRAS translation.')
UPDATE_ERROR = _(u'There was an error while updating the LIBRAS translation.')
DELETE_ERROR = _(u'There was an error while deleting the LIBRAS translation.')
GET_ERROR = _(u'There was an error while getting the LIBRAS translation.')


class VLibrasNewsError(Exception):

    """Exception raised for errors accessing VLibras News API."""

    def __init__(self, msg, log):
        self.msg = msg  # a message to show to end users
        self.log = log  # a message to log as an error


def api_error_handler(func):
    """Decorator to deal with errors accessing VLibras News API."""
Example #4
0
# -*- coding: utf-8 -*-
from brasil.gov.vlibrasnews import _
from brasil.gov.vlibrasnews.logger import logger
from plone import api
from requests.exceptions import RequestException
from zope.globalrequest import getRequest

import requests

CREATE_URL = 'http://150.165.204.81:3000/publish'
UPDATE_URL = 'http://150.165.204.81:3000/publish/{0}'
DELETE_URL = GET_URL = 'http://150.165.204.81:3000/videos/{0}'

CREATE_ERROR = _(u'There was an error while creating the LIBRAS translation.')
UPDATE_ERROR = _(u'There was an error while updating the LIBRAS translation.')
DELETE_ERROR = _(u'There was an error while deleting the LIBRAS translation.')
GET_ERROR = _(u'There was an error while getting the LIBRAS translation.')


class VLibrasNewsError(Exception):
    """Exception raised for errors accessing VLibras News API."""
    def __init__(self, msg, log):
        self.msg = msg  # a message to show to end users
        self.log = log  # a message to log as an error


def api_error_handler(func):
    """Decorator to deal with errors accessing VLibras News API."""
    def func_wrapper(context, event):
        try:
            return func(context, event)
class VLibrasNewsSettingsEditForm(controlpanel.RegistryEditForm):
    """Control panel edit form."""

    schema = IVLibrasNewsSettings
    label = _(u'VLibras News')
    description = _(u'Settings for the VLibras News API integration.')
# -*- coding: utf-8 -*-
from brasil.gov.vlibrasnews import _
from brasil.gov.vlibrasnews.api import api_error_handler
from brasil.gov.vlibrasnews.api import VLibrasNews
from brasil.gov.vlibrasnews.api import VLibrasNewsError
from brasil.gov.vlibrasnews.behaviors import IVLibrasNews
from brasil.gov.vlibrasnews.interfaces import IVLibrasNewsSettings
from brasil.gov.vlibrasnews.logger import logger
from plone import api
from plone.app.textfield.interfaces import ITransformer
from Products.CMFPlone.utils import safe_unicode
from zope.component.interfaces import ComponentLookupError
from zope.globalrequest import getRequest

EMPTY = _(u'None')


# TODO: move exception handling to api_api_error_handler to get rid of this
def _get_token_from_registry():
    """Return the token from the registry and treat exceptions."""
    record = dict(interface=IVLibrasNewsSettings, name='access_token')
    try:
        value = api.portal.get_registry_record(**record)
    except api.exc.InvalidParameterError:  # error?
        logger.error(u'Missing VLibras News API authentication token record')
        return
    except ComponentLookupError:  # package not installed?
        return

    if not value:
        logger.error(u'VLibras News API authentication token is not defined')