Skip to content

Commit

Permalink
Issue 18 - Use a behavior to enable VLibras News API (#22)
Browse files Browse the repository at this point in the history
* Use a behavior to enable VLibras News API

* Refactor

* Treat unpublish item

* Remove item just when confirm button in request

* Add more tests
  • Loading branch information
rodfersou authored and hvelarde committed Sep 6, 2016
1 parent 0a98ef0 commit b679581
Show file tree
Hide file tree
Showing 21 changed files with 379 additions and 235 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
1.0b1 (unreleased)
^^^^^^^^^^^^^^^^^^

- The implementation was rewritten as a behavior.
No upgrade step is available, you must uninstall the previous version and install the new one.
[rodfersou, hvelarde]

- Fix button translation.
[rodfersou]

Expand Down
33 changes: 28 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Integração do VLibras News API no Plone
Introdução
-----------

Este pacote integra no Plone o VLibras News API,
um serviço desenvolvido pelo `Laboratório de Aplicações de Video Digital <http://lavid.ufpb.br/>`_ para gerar vídeo de `LIBRAS <http://vlibras.gov.br/>`_ .
O VLibras News API é um serviço desenvolvido pelo `Laboratório de Aplicações de Video Digital <http://lavid.ufpb.br/>`_ para gerar traduções para `LIBRAS <http://vlibras.gov.br/>`_ em forma de vídeos armazenados no YouTube.

Este pacote suporta somente tipos de conteúdo Dexterity.
Este pacote é uma integração do VLibras News API no Plone,
atraves de um behavior para tipos de conteúdo Dexterity.

Estado deste pacote
-------------------
Expand Down Expand Up @@ -44,9 +44,32 @@ Para habilitar a instalação deste produto em um ambiente que utilize o buildou

3. Reinicie o Plone

4. Acesse o painel de controle e instale o produto **.gov.br: Tradução de Português para Libras**.
4. Acesse o painel de controle e instale o produto **.gov.br: Tradução de Português para LIBRAS**.

Uso
---

TBD.
Após instalar o pacote é preciso ir na 'Configuração do Site',
selecionar 'VLibras News API' nas 'Configurações de Complementos',
e informar o token de acesso.

Para ativar o behavior é necessário ir em 'Tipos de conteúdo Dexterity',
selecionar o tipo de conteúdo que será processado,
e habilitar o behavior 'VLibras News'.

Um novo campo de só leitura será disponibilizado para armazenar o endereço do vídeo com a tradução a LIBRAS do conteúdo processado.

Como funciona
-------------

Quando um usuário publicar um objeto de um tipo de conteúdo com o behavior habilitado,
uma requisição é feita na API para criar um vídeo com a tradução do conteúdo para LIBRAS.

A partir desse momento a API é consultada periodicamente para conhecer o estado do processamento do vídeo.
Quando o vídeo ficar pronto para visualização, um viewlet disponibiliza um player para assistir o video.

Caso o conteúdo for modificado,
o vídeo anterior é retirado e uma nova requisição é feita para criar um novo vídeo com a tradução do conteúdo atualizado para LIBRAS.

Caso o conteúdo for excluido,
uma requisição é feita para excluir também o vídeo com a tradução do conteúdo para LIBRAS.
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ eggs = ${test:eggs}
[versions]
# use latest version of coverage
coverage =
flake8-coding = 1.2.2
16 changes: 10 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@
include_package_data=True,
zip_safe=False,
install_requires=[
'lxml',
'plone.api',
'plone.app.imaging',
'plone.app.layout',
'plone.app.registry',
'plone.app.upgrade',
'plone.directives.form',
'plone.transformchain',
'plone.autoform',
'plone.behavior',
'plone.dexterity',
'plone.memoize',
'plone.supermodel',
'Products.CMFPlone >=4.3',
'Products.GenericSetup',
'repoze.xmliter',
'requests',
'setuptools',
'zope.component',
'zope.i18nmessageid',
'zope.interface',
'zope.schema',
Expand All @@ -59,8 +60,11 @@
'test': [
'AccessControl',
'httmock',
'mock',
'plone.app.contenttypes',
'plone.app.robotframework',
'plone.app.testing [robot]',
'plone.app.textfield',
'plone.browserlayer',
'plone.registry',
'plone.testing',
Expand Down
26 changes: 26 additions & 0 deletions src/brasil/gov/vlibrasnews/behaviors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from brasil.gov.vlibrasnews import _
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel import model
from zope import schema
from zope.interface import provider


@provider(IFormFieldProvider)
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.
"""

video_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
)
17 changes: 17 additions & 0 deletions src/brasil/gov/vlibrasnews/behaviors.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="brasil.gov.vlibrasnews">

<include package="plone.behavior" file="meta.zcml" />

<plone:behavior
title="VLibras News"
description="Enables the integration with VLibras News API."
provides="brasil.gov.vlibrasnews.behaviors.IVLibrasNews"
for="plone.dexterity.interfaces.IDexterityContent"
i18n:attributes="title; description"
/>

</configure>
2 changes: 1 addition & 1 deletion src/brasil/gov/vlibrasnews/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
name="brasil.gov.vlibrasnews.vlibrasnews"
manager="plone.app.layout.viewlets.interfaces.IBelowContentTitle"
class=".vlibrasnews.VLibrasNewsViewlet"
template="templates/vlibrasnews.pt"
template="vlibrasnews.pt"
permission="zope2.View"
layer="brasil.gov.vlibrasnews.interfaces.IVLibrasNewsLayer"
/>
Expand Down
22 changes: 9 additions & 13 deletions src/brasil/gov/vlibrasnews/browser/vlibrasnews.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Viewlets used on the package."""
from brasil.gov.vlibrasnews.exc import NotProcessingError
from brasil.gov.vlibrasnews.interfaces import IVLibrasNewsSettings
from brasil.gov.vlibrasnews.behaviors import IVLibrasNews
from brasil.gov.vlibrasnews.subscribers import get_video_url
from plone import api
from plone.app.layout.viewlets.common import ViewletBase
Expand All @@ -15,29 +14,26 @@ class VLibrasNewsViewlet(ViewletBase):

@property
def enabled(self):
record = IVLibrasNewsSettings.__identifier__ + '.enabled_content_types'
enabled_content_types = api.portal.get_registry_record(record)
if self.context.portal_type not in enabled_content_types:
if not IVLibrasNews.providedBy(self.context):
return False
if self.context.video_url is None:
return False

is_ready = self.state == 'ready'
return is_ready or not api.user.is_anonymous()

@property
def state(self):
try:
video_url = self.video_url
except NotProcessingError:
return 'notprocessing'

video_url = self.video_url
if video_url is None:
return 'notprocessing'
elif video_url == '':
return 'processing'

return 'ready'

@ram.cache(lambda method, self, context: (time() // 60, context))
def _get_video_url(self, context):
return get_video_url(context)
get_video_url(context)
return getattr(context, 'video_url', None)

@property
def video_url(self):
Expand Down
6 changes: 0 additions & 6 deletions src/brasil/gov/vlibrasnews/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@
POST_URL = 'http://150.165.204.81:3000/publish'
REPOST_URL = 'http://150.165.204.81:3000/publish/{0}'
VIDEO_URL = 'http://150.165.204.81:3000/videos/{0}'

# by default, all standard content types will be enabled
DEFAULT_ENABLED_CONTENT_TYPES = [
'Document',
'News Item'
]
5 changes: 2 additions & 3 deletions src/brasil/gov/vlibrasnews/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

<five:registerPackage package="." />

<include package="plone.app.dexterity" />
<include package="plone.directives.form" file="meta.zcml" />
<include package="plone.directives.form" />
<include package="Products.CMFCore" file="permissions.zcml" />

<include package=".browser" />

<include file="behaviors.zcml" />
<include file="profiles.zcml" />
<include file="subscribers.zcml" />

Expand Down
10 changes: 0 additions & 10 deletions src/brasil/gov/vlibrasnews/exc.py

This file was deleted.

15 changes: 2 additions & 13 deletions src/brasil/gov/vlibrasnews/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from brasil.gov.vlibrasnews import _
from brasil.gov.vlibrasnews.config import DEFAULT_ENABLED_CONTENT_TYPES
from plone.directives import form
from plone.supermodel import model
from zope import schema
from zope.interface import Interface

Expand All @@ -11,7 +10,7 @@ class IVLibrasNewsLayer(Interface):
"""A layer specific for this add-on product."""


class IVLibrasNewsSettings(form.Schema):
class IVLibrasNewsSettings(model.Schema):

"""Schema for the control panel form."""

Expand All @@ -21,13 +20,3 @@ class IVLibrasNewsSettings(form.Schema):
default='',
required=True,
)

enabled_content_types = schema.List(
title=_(u'Enabled Content Types'),
description=_(u'Only objects of these content types will display vlibras icon.'),
required=False,
default=DEFAULT_ENABLED_CONTENT_TYPES,
# we are going to list only the main content types in the widget
value_type=schema.Choice(
vocabulary=u'plone.app.vocabularies.ReallyUserFriendlyTypes'),
)
2 changes: 1 addition & 1 deletion src/brasil/gov/vlibrasnews/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name="default"
title="brasil.gov.vlibrasnews"
directory="profiles/default"
description="Plone integration with VLibras News API, a service to generate LIBRAS video."
description="Plone integration with VLibras News API, a service to generate a translation to LIBRAS."
provides="Products.GenericSetup.interfaces.EXTENSION"
i18n:attributes="title; description"
/>
Expand Down

0 comments on commit b679581

Please sign in to comment.