Skip to content

Commit

Permalink
Mudando 'skos' para 'vcge' #20
Browse files Browse the repository at this point in the history
  • Loading branch information
caduvieira committed Sep 1, 2015
1 parent 60321a2 commit 7b42b0f
Show file tree
Hide file tree
Showing 27 changed files with 229 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/brasil/gov/vcge/at/extender.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class VCGEExtender(object):
layer = IVCGEInstalado

fields = [
ExtensionLinesField("skos",
ExtensionLinesField("vcge",
schemata="categorization",
vocabulary_factory='brasil.gov.vcge',
enforceVocabulary=True,
Expand Down
8 changes: 4 additions & 4 deletions src/brasil/gov/vcge/browser/viewlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ def update(self):
ps = self.context.restrictedTraverse('@@plone_portal_state')
self.nav_root_url = ps.navigation_root().absolute_url()

def skos(self):
def vcge(self):
''' Retorna lista de itens selecionados neste conteudo
'''
context = aq_base(aq_inner(self.context))
uris = []
if hasattr(context, 'skos'):
uris = self.context.skos or []
if hasattr(context, 'vcge'):
uris = self.context.vcge or []
name = 'brasil.gov.vcge'
util = queryUtility(IVocabularyFactory, name)
vcge = util(self.context)
skos = []
for uri in uris:
title = vcge.by_token[uri].title
params = urlencode({'skos:list': uri})
params = urlencode({'vcge:list': uri})
skos.append({'id': uri,
'title': title,
'url': '%s/@@search?%s' % (self.nav_root_url,
Expand Down
4 changes: 3 additions & 1 deletion src/brasil/gov/vcge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class HiddenProducts(object):
def getNonInstallableProducts(self):
return [
'brasil.gov.vcge.upgrades.v2000',
'brasil.gov.vcge.upgrades.v2001',
]


Expand All @@ -27,5 +28,6 @@ class HiddenProfiles(object):
def getNonInstallableProfiles(self):
return [
'brasil.gov.vcge:uninstall',
'brasil.gov.vcge.upgrades.v2000:default'
'brasil.gov.vcge.upgrades.v2000:default',
'brasil.gov.vcge.upgrades.v2001:default',
]
16 changes: 8 additions & 8 deletions src/brasil/gov/vcge/contentrules/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IVCGEAction(Interface):
u"Selecionar esta opção ignora "
u"os termos do campo a seguir."))

skos = Set(title=_(u'VCGE'),
vcge = Set(title=_(u'VCGE'),
description=_(u'Termos a serem aplicados ao conteúdo.'),
required=False,
value_type=Choice(vocabulary=VOCAB))
Expand All @@ -48,17 +48,17 @@ class VCGEAction(SimpleItem):

element = 'brasil.gov.vcge.actions.VCGE'
same_as_parent = False
skos = []
vcge = []

@property
def summary(self):
same_as_parent = self.same_as_parent
skos = self.skos
vcge = self.vcge
if same_as_parent:
msg = _(u"Aplica termos da pasta no conteúdo.")
else:
msg = _(u"Aplica os termos ${skos}",
mapping=dict(skos=", ".join(skos)))
msg = _(u"Aplica os termos ${vcge}",
mapping=dict(vcge=", ".join(vcge)))
return msg


Expand All @@ -79,15 +79,15 @@ def __call__(self):
'''
obj = self.event.object
same_as_parent = self.element.same_as_parent
skos = self.element.skos
vcge = self.element.vcge
if not (utils.vcge_available(obj)):
return False
if same_as_parent:
parent = aq_parent(obj)
if not (utils.vcge_available(parent)):
return False
skos = utils.vcge_for_object(parent)
return utils.set_vcge(obj, skos)
vcge = utils.vcge_for_object(parent)
return utils.set_vcge(obj, vcge)


class VCGEAddForm(AddForm):
Expand Down
20 changes: 10 additions & 10 deletions src/brasil/gov/vcge/contentrules/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IVCGECondition(Interface):
desta condicao.
"""

skos = Set(title=_(u'VCGE'),
vcge = Set(title=_(u'VCGE'),
description=_(u'Termos a serem procurados. Deixe em branco '
u'para selecionar conteúdos sem nenhum termo VCGE '
u'aplicado.'),
Expand All @@ -42,17 +42,17 @@ class VCGECondition(SimpleItem):
"""
implements(IVCGECondition, IRuleElementData)

skos = []
vcge = []
element = "brasil.gov.vcge.conditions.VCGE"

@property
def summary(self):
skos = self.skos
if not skos:
vcge = self.vcge
if not vcge:
msg = _(u"Nenhum termo selecionado")
else:
msg = _(u"VCGE contém ${skos}",
mapping=dict(skos=" or ".join(skos)))
msg = _(u"VCGE contém ${vcge}",
mapping=dict(vcge=" or ".join(vcge)))
return msg


Expand All @@ -69,16 +69,16 @@ def __init__(self, context, element, event):
self.event = event

def __call__(self):
expected = self.element.skos
expected = self.element.vcge
obj = aq_inner(self.event.object)

if not (utils.vcge_available(obj)):
return False

skos = utils.vcge_for_object(obj)
vcge = utils.vcge_for_object(obj)
if not expected:
return not (expected or skos)
intersection = set(expected).intersection(skos)
return not (expected or vcge)
intersection = set(expected).intersection(vcge)
return intersection and True or False


Expand Down
16 changes: 8 additions & 8 deletions src/brasil/gov/vcge/contentrules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ def vcge_available(obj):
""" Valida se o objeto tem o atributo de
armazenamento do VCGE
"""
return hasattr(aq_base(obj), 'skos')
return hasattr(aq_base(obj), 'vcge')


def vcge_for_object(obj):
""" Retorna valores armazenados no atributo
VCGE de um objeto
"""
skos = []
if hasattr(aq_base(obj), 'skos'):
skos = obj.skos
return skos
vcge = []
if hasattr(aq_base(obj), 'vcge'):
vcge = obj.vcge
return vcge


def set_vcge(obj, skos):
def set_vcge(obj, vcge):
""" Armazena valores no atributo
VCGE de um objeto
"""
if hasattr(aq_base(obj), 'skos'):
obj.skos = skos
if hasattr(aq_base(obj), 'vcge'):
obj.vcge = vcge
return True
24 changes: 12 additions & 12 deletions src/brasil/gov/vcge/dx/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ class IVCGE(model.Schema):
# categorization fieldset
model.fieldset(
'categorization',
fields=['skos'],
fields=['vcge'],
)

form.widget(skos=SkosFieldWidget)
skos = schema.Tuple(
form.widget(vcge=SkosFieldWidget)
vcge = schema.Tuple(
title=_(u'VCGE'),
description=_(u'vcge_desc'),
required=False,
value_type=schema.Choice(vocabulary='brasil.gov.vcge'),
)

form.order_after(skos='subjects')
form.order_after(vcge='subjects')

form.omitted('skos')
form.no_omit(IEditForm, 'skos')
form.no_omit(IAddForm, 'skos')
form.omitted('vcge')
form.no_omit(IEditForm, 'vcge')
form.no_omit(IAddForm, 'vcge')


# Mark these interfaces as form field providers
Expand All @@ -44,9 +44,9 @@ class VCGE(object):
def __init__(self, context):
self.context = context

def _get_skos(self):
return self.context.skos
def _get_vcge(self):
return self.context.vcge

def _set_skos(self, value):
self.context.skos = value
skos = property(_get_skos, _set_skos)
def _set_vcge(self, value):
self.context.vcge = value
vcge = property(_get_vcge, _set_vcge)
2 changes: 1 addition & 1 deletion src/brasil/gov/vcge/dx/skos_input.pt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<label class='plain'>
<input type='checkbox'
tal:attributes="value item/value"
name='form.widgets.IVCGE.skos'
name='form.widgets.IVCGE.vcge'
checked='checked' />
<span tal:replace="item/title" />
</label><br />
Expand Down
4 changes: 2 additions & 2 deletions src/brasil/gov/vcge/dx/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def render(self):
@property
def existing(self):
value = None
if base_hasattr(self.context, 'skos'):
value = getattr(self.context, 'skos')
if base_hasattr(self.context, 'vcge'):
value = getattr(self.context, 'vcge')
if not value:
value = []
terms = self.vocab()
Expand Down
6 changes: 3 additions & 3 deletions src/brasil/gov/vcge/profiles/default/catalog.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<object name="portal_catalog" meta_type="Plone Catalog Tool">
<index name="skos" meta_type="KeywordIndex">
<indexed_attr value="skos"/>
<index name="vcge" meta_type="KeywordIndex">
<indexed_attr value="vcge"/>
</index>

<column value="skos"/>
<column value="vcge"/>
</object>
2 changes: 1 addition & 1 deletion src/brasil/gov/vcge/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>2000</version>
<version>2001</version>
<dependencies>
<dependency>profile-raptus.autocompletewidget:default</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions src/brasil/gov/vcge/profiles/default/registry.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="brasil.gov.vcge">
<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.skos">
prefix="plone.app.querystring.field.vcge">
<value key="title" i18n:translate="">VCGE</value>
<value key="description" i18n:translate="">Vocabulario Controlado do Governo Eletronico</value>
<value key="enabled">True</value>
Expand All @@ -13,4 +13,4 @@
<value key="vocabulary">brasil.gov.vcge</value>
<value key="group" i18n:translate="">Metadata</value>
</records>
</registry>
</registry>
32 changes: 16 additions & 16 deletions src/brasil/gov/vcge/tests/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class Dummy(object):
dummy = Dummy()
return VCGE(dummy)

def test_skos_setter(self):
def test_vcge_setter(self):
b = self._makeOne()
token = 'http://vocab.e.gov.br/id/governo#cultura'
b.skos = token
self.assertEqual(token, b.context.skos)
b.vcge = token
self.assertEqual(token, b.context.vcge)

def test_skos_getter(self):
def test_vcge_getter(self):
b = self._makeOne()
token = 'http://vocab.e.gov.br/id/governo#cultura'
b.context.skos = token
self.assertEqual(token, b.skos)
b.context.vcge = token
self.assertEqual(token, b.vcge)


class TestBehavior(unittest.TestCase):
Expand All @@ -63,7 +63,7 @@ def setUpContent(self):
portal = self.portal
oId = portal.invokeFactory('folder', 'content')
o = IVCGE(portal[oId])
o.skos = [token, ]
o.vcge = [token, ]
self.content = portal[oId]

def setUp(self):
Expand All @@ -86,7 +86,7 @@ def test_behavior_applied(self):

def test_content_information(self):
content = self.content
self.assertEquals(content.skos, [self.token, ])
self.assertEquals(content.vcge, [self.token, ])


class TestViewlet(unittest.TestCase):
Expand All @@ -103,7 +103,7 @@ def setUpContent(self):
portal = self.portal
oId = portal.invokeFactory('folder', 'content')
o = portal[oId]
o.skos = [token, ]
o.vcge = [token, ]
self.content = o

def setUp(self):
Expand All @@ -126,21 +126,21 @@ def test_rel(self):
rel = viewlet.rel()
self.assertEquals(rel, u'dc:subject foaf:primaryTopic')

def test_skos(self):
def test_vcge(self):
content = self.content
viewlet = VCGEViewlet(content, self.request, None, None)
viewlet.update()
skos = viewlet.skos()
self.assertEquals(len(skos), 1)
term = skos[0]
vcge = viewlet.vcge()
self.assertEquals(len(vcge), 1)
term = vcge[0]
self.assertEquals(term.get('title'), u'Cultura')

def test_skos_not_existent(self):
def test_vcge_not_existent(self):
''' Testa o que acontece quando nao temos o Extender
aplicado a um tipo de conteudo (neste caso o proprio portal)
'''
portal = self.portal
viewlet = VCGEViewlet(portal, self.request, None, None)
viewlet.update()
skos = viewlet.skos()
self.assertEquals(len(skos), 0)
vcge = viewlet.vcge()
self.assertEquals(len(vcge), 0)
4 changes: 2 additions & 2 deletions src/brasil/gov/vcge/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestCatalogSetup(BaseTestCase):
""" Garante que temos o indice e a coluna criados"""

def test_index(self):
self.assertTrue('skos' in self.ct.Indexes)
self.assertTrue('vcge' in self.ct.Indexes)

def test_column(self):
self.assertTrue('skos' in self.ct.schema())
self.assertTrue('vcge' in self.ct.schema())
2 changes: 1 addition & 1 deletion src/brasil/gov/vcge/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
self.portal = portal
self.registry = getattr(self.portal, 'portal_registry')
self.ct = getattr(self.portal, 'portal_catalog')
self.prefix = 'plone.app.querystring.field.skos'
self.prefix = 'plone.app.querystring.field.vcge'
self.setUpUser()


Expand Down
Loading

0 comments on commit 7b42b0f

Please sign in to comment.