Skip to content

Commit

Permalink
Corrigi code analysis
Browse files Browse the repository at this point in the history
Corrigi P001 (flake8-plone-api).
Foi necessário adicionar plone.api como dependência.
  • Loading branch information
idgserpro committed Sep 13, 2016
1 parent d3dbf67 commit caa250e
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 56 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Alterações
1.1rc2 (unreleased)
^^^^^^^^^^^^^^^^^^^

- Adiciona plone.api como dependência.
[idgserpro]

- Adicionando opção de link no título do cabeçalho do HeaderTile (closes `#157`).
[caduvieira]

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'collective.polls',
'collective.prettydate',
'five.grok',
'plone.api',
'plone.app.blocks',
'plone.app.dexterity [grok, relations]',
'plone.app.iterate',
Expand Down Expand Up @@ -90,6 +91,7 @@
'collective.cover[test]',
'mock',
'five.pt',
'plone.api',
'plone.app.robotframework',
'plone.app.testing [robot] >=4.2.2',
'plone.browserlayer',
Expand Down
2 changes: 1 addition & 1 deletion src/brasil/gov/tiles/tests/test_albuns_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_get_albuns(self):
self.tile.populate_with_object(gal_albuns)
self.assertEqual(self.tile.get_albuns(), [])

gal_albuns.invokeFactory('Folder', 'galeria-de-fotos')
api.content.create(gal_albuns, 'Folder', 'galeria-de-fotos')
gal_fotos = gal_albuns['galeria-de-fotos']
with api.env.adopt_roles(['Manager']):
api.content.transition(obj=gal_fotos, transition='publish')
Expand Down
2 changes: 1 addition & 1 deletion src/brasil/gov/tiles/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_default_configuration(self):

def test_accepted_content_types(self):
registry = getUtility(IRegistry)
settings = registry.forInterface(ICoverSettings)
settings = registry.forInterface(ICoverSettings) # noqa
self.assertEqual(
self.tile.accepted_ct(),
settings.searchable_content_types
Expand Down
2 changes: 1 addition & 1 deletion src/brasil/gov/tiles/tests/test_carousel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_folder_tile_render(self):
def test_accepted_content_types(self):
# Using the same from ListTile since CarouselTile(ListTile)
registry = getUtility(IRegistry)
settings = registry.forInterface(ICoverSettings)
settings = registry.forInterface(ICoverSettings) # noqa
self.assertEqual(
self.tile.accepted_ct(),
settings.searchable_content_types
Expand Down
10 changes: 5 additions & 5 deletions src/brasil/gov/tiles/tests/test_destaque_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from brasil.gov.tiles.tiles.destaque import IDestaqueTile
from collective.cover.controlpanel import ICoverSettings
from collective.cover.tests.base import TestTileMixin
from plone import api
from plone.registry.interfaces import IRegistry
from plone.uuid.interfaces import IUUID
from zope.component import getMultiAdapter
from zope.component import getUtility

Expand Down Expand Up @@ -58,7 +58,7 @@ def test_crud(self):

# next, we replace the destaque of objects with a different one
obj3 = self.portal['my-news-item']
tile.replace_with_objects([IUUID(obj3, None)])
tile.replace_with_objects([api.content.get_uuid(obj3)])
# tile's data attributed is cached so we should re-instantiate the tile
tile = getMultiAdapter(
(self.cover, self.request),
Expand Down Expand Up @@ -86,8 +86,8 @@ def test_populate_with_uuids(self):
# now we add a couple of objects to the destaque
obj1 = self.portal['my-document']
obj2 = self.portal['my-image']
self.tile.populate_with_uuids([IUUID(obj1, None),
IUUID(obj2, None)])
self.tile.populate_with_uuids([api.content.get_uuid(obj1),
api.content.get_uuid(obj2)])

# tile's data attributed is cached so we should re-instantiate the tile
tile = getMultiAdapter(
Expand All @@ -101,7 +101,7 @@ def test_populate_with_uuids(self):

def test_accepted_content_types(self):
registry = getUtility(IRegistry)
settings = registry.forInterface(ICoverSettings)
settings = registry.forInterface(ICoverSettings) # noqa
self.assertEqual(
self.tile.accepted_ct(),
settings.searchable_content_types
Expand Down
2 changes: 1 addition & 1 deletion src/brasil/gov/tiles/tests/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_default_configuration(self):

def test_accepted_content_types(self):
registry = getUtility(IRegistry)
settings = registry.forInterface(ICoverSettings)
settings = registry.forInterface(ICoverSettings) # noqa
self.assertEqual(
self.tile.accepted_ct(),
settings.searchable_content_types
Expand Down
11 changes: 5 additions & 6 deletions src/brasil/gov/tiles/tiles/albuns.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from collective.cover.tiles.base import IPersistentCoverTile
from collective.cover.tiles.base import PersistentCoverTile
from collective.cover.tiles.configuration_view import IDefaultConfigureForm
from plone import api
from plone.app.uuid.utils import uuidToObject
from plone.directives import form
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema

Expand Down Expand Up @@ -66,7 +65,7 @@ def populate_with_object(self, obj):
title = _(u'Gallery albums')
link_url = obj.absolute_url()
link_text = _(u'Access all Albums')
uuid = IUUID(obj, None)
uuid = api.content.get_uuid(obj)
data_mgr = ITileDataManager(self)
data_mgr.set({
'title': title,
Expand All @@ -92,7 +91,7 @@ def get_albuns(self):
if uuid:
obj = uuidToObject(uuid)
if obj:
catalog = getToolByName(self.context, 'portal_catalog')
catalog = api.portal.get_tool('portal_catalog')

# Procuro todas subpastas na pasta do album
path = '/'.join(obj.getPhysicalPath())
Expand All @@ -113,7 +112,7 @@ def get_albuns(self):
return albuns

def scale(self, item):
catalog = getToolByName(self.context, 'portal_catalog')
catalog = api.portal.get_tool('portal_catalog')
path = '/'.join(item.getPhysicalPath())
brains = catalog(Type=['Image', 'Folder'],
path={'query': path,
Expand All @@ -131,7 +130,7 @@ def scale(self, item):
}

def thumbnail(self, item):
catalog = getToolByName(self.context, 'portal_catalog')
catalog = api.portal.get_tool('portal_catalog')
path = '/'.join(item.getPhysicalPath())
brains = catalog(Type=['Image', 'Folder'],
path={'query': path,
Expand Down
6 changes: 3 additions & 3 deletions src/brasil/gov/tiles/tiles/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from brasil.gov.tiles import _ as _
from collective.cover.tiles.base import IPersistentCoverTile
from collective.cover.tiles.base import PersistentCoverTile
from plone import api
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema

Expand Down Expand Up @@ -57,7 +57,7 @@ def populate_with_object(self, obj):
else:
url = obj.absolute_url()
content_type = ''
uuid = IUUID(obj)
uuid = api.content.get_uuid(obj)
data_mgr = ITileDataManager(self)
data_mgr.set({'title': title,
'description': description,
Expand All @@ -73,7 +73,7 @@ def accepted_ct(self):
return ['Audio']

def get_uid(self, obj):
return IUUID(obj)
return api.content.get_uuid(obj)

def init_js(self):
return """
Expand Down
6 changes: 3 additions & 3 deletions src/brasil/gov/tiles/tiles/audiogallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from brasil.gov.tiles import _ as _
from brasil.gov.tiles.tiles.list import IListTile
from brasil.gov.tiles.tiles.list import ListTile
from plone import api
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema

Expand Down Expand Up @@ -49,7 +49,7 @@ def populate_with_object(self, obj):

self.set_limit()
header = obj.Title() # use collection's title as header
uuid = IUUID(obj, None)
uuid = api.content.get_uuid(obj)
data_mgr = ITileDataManager(self)

old_data = data_mgr.get()
Expand All @@ -63,7 +63,7 @@ def accepted_ct(self):
return ['Collection', 'Folder']

def get_uid(self, obj):
return IUUID(obj)
return api.content.get_uuid(obj)

def get_elements(self, obj):
results = []
Expand Down
4 changes: 2 additions & 2 deletions src/brasil/gov/tiles/tiles/banner_rotativo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from brasil.gov.tiles.tiles.list import IListTile
from brasil.gov.tiles.tiles.list import ListTile
from collective.cover.tiles.configuration_view import IDefaultConfigureForm
from plone import api
from plone.autoform import directives as form
from plone.memoize import view
from plone.namedfile.field import NamedBlobImage as NamedImage
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema
from zope.interface import implementer
Expand Down Expand Up @@ -89,7 +89,7 @@ def populate_with_object(self, obj):
if not self._has_image_field(obj):
return
self.set_limit()
uuid = IUUID(obj, None)
uuid = api.content.get_uuid(obj)
title = obj.Title()
description = obj.Description()
rights = obj.Rights()
Expand Down
13 changes: 7 additions & 6 deletions src/brasil/gov/tiles/tiles/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
from collective.cover.tiles.base import IPersistentCoverTile
from collective.cover.tiles.base import PersistentCoverTile
from collective.cover.tiles.configuration_view import IDefaultConfigureForm
from plone import api
from plone.autoform import directives as form
from plone.memoize import view
from plone.memoize.instance import memoizedproperty
from plone.namedfile.field import NamedBlobImage as NamedImage
from plone.registry.interfaces import IRegistry
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import safe_unicode
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema
Expand Down Expand Up @@ -89,7 +88,7 @@ class BasicTile(PersistentCoverTile):

@memoizedproperty
def brain(self):
catalog = getToolByName(self.context, 'portal_catalog')
catalog = api.portal.get_tool('portal_catalog')
uuid = self.data.get('uuid')
result = catalog(UID=uuid) if uuid is not None else []
assert len(result) <= 1
Expand Down Expand Up @@ -129,10 +128,12 @@ def populate_with_object(self, obj):
data = {
'title': safe_unicode(obj.Title()),
'description': safe_unicode(obj.Description()),
'uuid': IUUID(obj, None), # XXX: can we get None here? see below
# XXX: can we get None here? see below
'uuid': api.content.get_uuid(obj),
'date': True,
'subjects': True,
'image_description': safe_unicode(obj.Description()) or safe_unicode(obj.Title()),
'image_description': safe_unicode(obj.Description()) or
safe_unicode(obj.Title()),
}

# TODO: if a Dexterity object does not have the IReferenceable
Expand All @@ -153,7 +154,7 @@ def accepted_ct(self):
please memoize if you're doing some very expensive calculation
"""
registry = getUtility(IRegistry)
settings = registry.forInterface(ICoverSettings)
settings = registry.forInterface(ICoverSettings) # noqa
return settings.searchable_content_types

def getAlt(self):
Expand Down
4 changes: 2 additions & 2 deletions src/brasil/gov/tiles/tiles/carousel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from brasil.gov.tiles.tiles.list import IListTile
from brasil.gov.tiles.tiles.list import ListTile
from collective.cover.widgets.textlinessortable import TextLinesSortableFieldWidget
from plone import api
from plone.autoform import directives as form
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema
from zope.interface import implementer
Expand Down Expand Up @@ -42,7 +42,7 @@ def populate_with_object(self, obj):
if not self._has_image_field(obj):
return
self.set_limit()
uuid = IUUID(obj, None)
uuid = api.content.get_uuid(obj)
data_mgr = ITileDataManager(self)

old_data = data_mgr.get()
Expand Down
4 changes: 2 additions & 2 deletions src/brasil/gov/tiles/tiles/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from collective.cover.tiles.base import IPersistentCoverTile
from collective.cover.tiles.base import PersistentCoverTile
from collective.cover.tiles.configuration_view import IDefaultConfigureForm
from plone import api
from plone.app.uuid.utils import uuidToObject
from plone.directives import form
from plone.namedfile.field import NamedBlobImage as NamedImage
from plone.tiles.interfaces import ITileDataManager
from plone.tiles.interfaces import ITileType
from plone.uuid.interfaces import IUUID
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema
from zope.component import queryUtility
Expand Down Expand Up @@ -110,7 +110,7 @@ def populate_with_object(self, obj):
if obj.portal_type in self.accepted_ct():
header = obj.Title() # use collection's title as header
footer = _(u'More…') # XXX: can we use field's default?
uuid = IUUID(obj)
uuid = api.content.get_uuid(obj)

data_mgr = ITileDataManager(self)
data_mgr.set({
Expand Down
8 changes: 4 additions & 4 deletions src/brasil/gov/tiles/tiles/destaque.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from collective.cover.interfaces import ICoverUIDsProvider
from collective.cover.tiles.list import IListTile
from collective.cover.tiles.list import ListTile
from plone import api
from plone.memoize import view
from plone.namedfile.field import NamedImage
from plone.registry.interfaces import IRegistry
from plone.uuid.interfaces import IUUID
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema
from zope.component import getUtility
Expand Down Expand Up @@ -58,7 +58,7 @@ class DestaqueTile(ListTile):

# XXX: are we using this function somewhere? remove?
def get_uid(self, obj):
return IUUID(obj, None)
return api.content.get_uuid(obj)

@view.memoize
def accepted_ct(self):
Expand All @@ -71,7 +71,7 @@ def accepted_ct(self):
please memoize if you're doing some very expensive calculation
"""
registry = getUtility(IRegistry)
settings = registry.forInterface(ICoverSettings)
settings = registry.forInterface(ICoverSettings) # noqa
return settings.searchable_content_types

def thumbnail(self, item):
Expand Down Expand Up @@ -113,4 +113,4 @@ def __init__(self, context):
def getUIDs(self):
""" Return a list of UIDs of collection objects.
"""
return [IUUID(self.context)]
return [api.content.get_uuid(self.context)]
4 changes: 2 additions & 2 deletions src/brasil/gov/tiles/tiles/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from brasil.gov.tiles import _ as _
from collective.cover.tiles.base import IPersistentCoverTile
from collective.cover.tiles.base import PersistentCoverTile
from plone import api
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema
from zope.interface import implementer
Expand Down Expand Up @@ -57,7 +57,7 @@ def populate_with_object(self, obj):
link_boolean = False
link_text = title
data_mgr = ITileDataManager(self)
uuid = IUUID(obj)
uuid = api.content.get_uuid(obj)
data_mgr.set({'title': title,
'link_url': url,
'link_text': link_text,
Expand Down
Loading

0 comments on commit caa250e

Please sign in to comment.