Permalink
Browse files

pep8/pyflakes

  • Loading branch information...
1 parent 84460d2 commit 983e9a3f7c29f68c4b2d0e68f553f8cf71157e5b @hvelarde hvelarde committed Apr 11, 2012
View
4 src/collective/twitter/portlets/Extensions/Install.py
@@ -1,5 +1,8 @@
+# -*- coding: utf-8 -*-
+
from Products.CMFCore.utils import getToolByName
+
def install(portal, reinstall=False):
setup_tool = getToolByName(portal, 'portal_setup')
qi = getToolByName(portal, 'portal_quickinstaller')
@@ -9,6 +12,7 @@ def install(portal, reinstall=False):
setup_tool.runAllImportStepsFromProfile('profile-collective.twitter.portlets:default')
return "Ran all uninstall steps."
+
def uninstall(portal, reinstall=False):
if not reinstall:
setup_tool = getToolByName(portal, 'portal_setup')
View
2 src/collective/twitter/portlets/testing.py
@@ -5,6 +5,7 @@
from plone.app.testing import IntegrationTesting
from plone.app.testing import FunctionalTesting
+
class Fixture(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE,)
@@ -18,7 +19,6 @@ def setUpPloneSite(self, portal):
# Install into Plone site using portal_setup
self.applyProfile(portal, 'collective.twitter.portlets:default')
-
FIXTURE = Fixture()
INTEGRATION_TESTING = IntegrationTesting(
bases=(FIXTURE,),
View
44 src/collective/twitter/portlets/tests/test_profile_portlet.py
@@ -1,8 +1,12 @@
+# -*- coding: utf-8 -*-
+
import unittest2 as unittest
-from collective.twitter.portlets.testing import INTEGRATION_TESTING
+from zope.component import getMultiAdapter
+from zope.component import getUtility
-from zope.component import getUtility, getMultiAdapter
+from plone.app.testing import TEST_USER_ID
+from plone.app.testing import setRoles
from plone.portlets.interfaces import IPortletType
from plone.portlets.interfaces import IPortletManager
@@ -13,9 +17,8 @@
from plone.app.portlets.storage import PortletAssignmentMapping
from collective.twitter.portlets import twprofile
+from collective.twitter.portlets.testing import INTEGRATION_TESTING
-from plone.app.testing import TEST_USER_ID
-from plone.app.testing import setRoles
class PortletTest(unittest.TestCase):
@@ -35,10 +38,10 @@ def test_portlet_type_registered(self):
def test_interfaces(self):
# TODO: Pass any keyword arguments to the Assignment constructor
- portlet = twprofile.Assignment(tw_account = u"test",
- tw_user = u"Test",
- show_avatars = False,
- max_results = 20)
+ portlet = twprofile.Assignment(tw_account=u"test",
+ tw_user=u"Test",
+ show_avatars=False,
+ max_results=20)
self.failUnless(IPortletAssignment.providedBy(portlet))
self.failUnless(IPortletDataProvider.providedBy(portlet.data))
@@ -71,10 +74,10 @@ def test_invoke_edit_view(self):
mapping = PortletAssignmentMapping()
request = self.request
- mapping['foo'] = twprofile.Assignment(tw_account = u"test",
- tw_user = u"Test",
- show_avatars = False,
- max_results = 20)
+ mapping['foo'] = twprofile.Assignment(tw_account=u"test",
+ tw_user=u"Test",
+ show_avatars=False,
+ max_results=20)
editview = getMultiAdapter((mapping['foo'], request), name='edit')
self.failUnless(isinstance(editview, twprofile.EditForm))
@@ -87,17 +90,16 @@ def test_obtain_renderer(self):
context=self.portal)
# TODO: Pass any keyword arguments to the Assignment constructor
- assignment = twprofile.Assignment(tw_account = u"test",
- tw_user = u"Test",
- show_avatars = False,
- max_results = 20)
+ assignment = twprofile.Assignment(tw_account=u"test",
+ tw_user=u"Test",
+ show_avatars=False,
+ max_results=20)
renderer = getMultiAdapter(
(context, request, view, manager, assignment), IPortletRenderer)
self.failUnless(isinstance(renderer, twprofile.Renderer))
-
class RenderTest(unittest.TestCase):
layer = INTEGRATION_TESTING
@@ -124,10 +126,10 @@ def renderer(self, context=None, request=None, view=None, manager=None,
def test_render(self):
# TODO: Pass any keyword arguments to the Assignment constructor.
r = self.renderer(context=self.portal,
- assignment=twprofile.Assignment(tw_account = u"test",
- tw_user = u"Test",
- show_avatars = False,
- max_results = 20))
+ assignment=twprofile.Assignment(tw_account=u"test",
+ tw_user=u"Test",
+ show_avatars=False,
+ max_results=20))
r = r.__of__(self.portal)
r.update()
#output = r.render()
View
44 src/collective/twitter/portlets/tests/test_search_portlet.py
@@ -1,8 +1,12 @@
+# -*- coding: utf-8 -*-
+
import unittest2 as unittest
-from collective.twitter.portlets.testing import INTEGRATION_TESTING
+from zope.component import getMultiAdapter
+from zope.component import getUtility
-from zope.component import getUtility, getMultiAdapter
+from plone.app.testing import TEST_USER_ID
+from plone.app.testing import setRoles
from plone.portlets.interfaces import IPortletType
from plone.portlets.interfaces import IPortletManager
@@ -13,9 +17,8 @@
from plone.app.portlets.storage import PortletAssignmentMapping
from collective.twitter.portlets import twsearch
+from collective.twitter.portlets.testing import INTEGRATION_TESTING
-from plone.app.testing import TEST_USER_ID
-from plone.app.testing import setRoles
class PortletTest(unittest.TestCase):
@@ -35,10 +38,10 @@ def test_portlet_type_registered(self):
def test_interfaces(self):
# TODO: Pass any keyword arguments to the Assignment constructor
- portlet = twsearch.Assignment(tw_account = u"test",
- search_string = u"Test",
- show_avatars = False,
- max_results = 20)
+ portlet = twsearch.Assignment(tw_account=u"test",
+ search_string=u"Test",
+ show_avatars=False,
+ max_results=20)
self.failUnless(IPortletAssignment.providedBy(portlet))
self.failUnless(IPortletDataProvider.providedBy(portlet.data))
@@ -71,10 +74,10 @@ def test_invoke_edit_view(self):
mapping = PortletAssignmentMapping()
request = self.request
- mapping['foo'] = twsearch.Assignment(tw_account = u"test",
- search_string = u"Test",
- show_avatars = False,
- max_results = 20)
+ mapping['foo'] = twsearch.Assignment(tw_account=u"test",
+ search_string=u"Test",
+ show_avatars=False,
+ max_results=20)
editview = getMultiAdapter((mapping['foo'], request), name='edit')
self.failUnless(isinstance(editview, twsearch.EditForm))
@@ -87,17 +90,16 @@ def test_obtain_renderer(self):
context=self.portal)
# TODO: Pass any keyword arguments to the Assignment constructor
- assignment = twsearch.Assignment(tw_account = u"test",
- search_string = u"Test",
- show_avatars = False,
- max_results = 20)
+ assignment = twsearch.Assignment(tw_account=u"test",
+ search_string=u"Test",
+ show_avatars=False,
+ max_results=20)
renderer = getMultiAdapter(
(context, request, view, manager, assignment), IPortletRenderer)
self.failUnless(isinstance(renderer, twsearch.Renderer))
-
class RenderTest(unittest.TestCase):
layer = INTEGRATION_TESTING
@@ -124,10 +126,10 @@ def renderer(self, context=None, request=None, view=None, manager=None,
def test_render(self):
# TODO: Pass any keyword arguments to the Assignment constructor.
r = self.renderer(context=self.portal,
- assignment=twsearch.Assignment(tw_account = u"test",
- search_string = u"Test",
- show_avatars = False,
- max_results = 20))
+ assignment=twsearch.Assignment(tw_account=u"test",
+ search_string=u"Test",
+ show_avatars=False,
+ max_results=20))
r = r.__of__(self.portal)
r.update()
#output = r.render()
View
5 src/collective/twitter/portlets/tests/test_setup.py
@@ -8,6 +8,7 @@
from collective.twitter.portlets.config import PROJECTNAME
from collective.twitter.portlets.testing import INTEGRATION_TESTING
+
class InstallTest(unittest.TestCase):
layer = INTEGRATION_TESTING
@@ -17,7 +18,7 @@ def setUp(self):
def test_installed(self):
qi = getattr(self.portal, 'portal_quickinstaller')
- self.failUnless(qi.isProductInstalled(PROJECTNAME))
+ self.assertTrue(qi.isProductInstalled(PROJECTNAME))
class UninstallTest(unittest.TestCase):
@@ -31,7 +32,7 @@ def setUp(self):
self.qi.uninstallProducts(products=[PROJECTNAME])
def test_uninstalled(self):
- self.failIf(self.qi.isProductInstalled(PROJECTNAME))
+ self.assertFalse(self.qi.isProductInstalled(PROJECTNAME))
def test_suite():
View
50 src/collective/twitter/portlets/twprofile.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
from zope.interface import implements
from zope.interface import alsoProvides
@@ -31,6 +33,7 @@
logger = logging.getLogger(PROJECTNAME)
+
def TwitterAccounts(context):
registry = getUtility(IRegistry)
accounts = registry['collective.twitter.accounts']
@@ -79,7 +82,7 @@ class ITwitterProfilePortlet(IPortletDataProvider):
description=_(u"Show people's avatars."),
required=False)
- max_results = schema.Int(title=_(u'Maximum results'),
+ max_results = schema.Int(title=_(u'Maximum results'),
description=_(u"The maximum results number."),
required=True,
default=5)
@@ -129,7 +132,6 @@ def title(self):
return _(u"Twitter profile Portlet")
-
class Renderer(base.Renderer):
"""Portlet renderer.
@@ -140,7 +142,6 @@ class Renderer(base.Renderer):
render = ViewPageTemplateFile('twprofile.pt')
-
def getHeader(self):
"""
Returns the header for the portlet
@@ -167,37 +168,36 @@ def getSearchResults(self):
if account:
logger.info("Got a valid account.")
- logger.info("consumer_key = %s"%account.get('consumer_key'))
- logger.info("consumer_secret = %s"%account.get('consumer_secret'))
- logger.info("access_token_key = %s"%account.get('oauth_token'))
- logger.info("access_token_secret = %s"%account.get('oauth_token_secret'))
+ logger.info("consumer_key = %s" % account.get('consumer_key'))
+ logger.info("consumer_secret = %s" % account.get('consumer_secret'))
+ logger.info("access_token_key = %s" % account.get('oauth_token'))
+ logger.info("access_token_secret = %s" % account.get('oauth_token_secret'))
- tw = twitter.Api(consumer_key = account.get('consumer_key'),
- consumer_secret = account.get('consumer_secret'),
- access_token_key = account.get('oauth_token'),
- access_token_secret = account.get('oauth_token_secret'),)
+ tw = twitter.Api(consumer_key=account.get('consumer_key'),
+ consumer_secret=account.get('consumer_secret'),
+ access_token_key=account.get('oauth_token'),
+ access_token_secret=account.get('oauth_token_secret'),)
tw_user = self.data.tw_user
max_results = self.data.max_results
try:
results = tw.GetUserTimeline(tw_user, count=max_results)
- logger.info("%s results obtained."%len(results))
+ logger.info("%s results obtained." % len(results))
except Exception, e:
- logger.info("Something went wrong: %s."%e)
+ logger.info("Something went wrong: %s." % e)
results = []
return results
-
def getTweet(self, result):
# We need to make URLs, hastags and users clickable.
- URL_TEMPLATE ="""
+ URL_TEMPLATE = """
<a href="%s" target="blank_">%s</a>
"""
- HASHTAG_TEMPLATE ="""
+ HASHTAG_TEMPLATE = """
<a href="http://twitter.com/#!/search?q=%s" target="blank_">%s</a>
"""
- USER_TEMPLATE ="""
+ USER_TEMPLATE = """
<a href="http://twitter.com/#!/%s" target="blank_">%s</a>
"""
@@ -208,26 +208,26 @@ def getTweet(self, result):
for index, word in enumerate(split_text):
if word.startswith('@'):
# This is a user
- split_text[index] = USER_TEMPLATE%(word[1:],word)
+ split_text[index] = USER_TEMPLATE % (word[1:], word)
elif word.startswith('#'):
# This is a hashtag
- split_text[index] = HASHTAG_TEMPLATE%("%23"+word[1:],word)
+ split_text[index] = HASHTAG_TEMPLATE % ("%23" + word[1:], word)
elif word.startswith('http'):
# This is a hashtag
- split_text[index] = URL_TEMPLATE%(word,word)
+ split_text[index] = URL_TEMPLATE % (word, word)
- return "<p>%s</p>"%' '.join(split_text)
+ return "<p>%s</p>" % ' '.join(split_text)
def getTweetUrl(self, result):
return "https://twitter.com/%s/status/%s" % \
(result.user.screen_name, result.id)
-
+
def getReplyTweetUrl(self, result):
return "https://twitter.com/intent/tweet?in_reply_to=%s" % result.id
-
+
def getReTweetUrl(self, result):
return "https://twitter.com/intent/retweet?tweet_id=%s" % result.id
-
+
def getFavTweetUrl(self, result):
return "https://twitter.com/intent/favorite?tweet_id=%s" % result.id
@@ -241,6 +241,7 @@ def getDate(self, result):
return date
+
class AddForm(base.AddForm):
"""Portlet add form.
@@ -253,6 +254,7 @@ class AddForm(base.AddForm):
def create(self, data):
return Assignment(**data)
+
class EditForm(base.EditForm):
"""Portlet edit form.
View
81 src/collective/twitter/portlets/twsearch.py
@@ -1,36 +1,36 @@
-from zope.interface import implements
-from zope.interface import alsoProvides
+# -*- coding: utf-8 -*-
-from plone.portlets.interfaces import IPortletDataProvider
-from plone.app.portlets.portlets import base
+import DateTime
+import logging
+import twitter
+
+from time import time
from zope import schema
+
from zope.component import getUtility
-from Products.CMFCore.utils import getToolByName
+from zope.interface import implements
+from zope.interface import alsoProvides
from zope.formlib import form
+from zope.schema.interfaces import IContextSourceBinder
from zope.schema.vocabulary import SimpleVocabulary
+from zope.security import checkPermission
+
+from plone.app.portlets.portlets import base
+from plone.memoize import ram
+from plone.portlets.interfaces import IPortletDataProvider
+from plone.registry.interfaces import IRegistry
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
-from plone.registry.interfaces import IRegistry
-from zope.schema.interfaces import IContextSourceBinder
from collective.prettydate.interfaces import IPrettyDate
-from zope.security import checkPermission
-
-from collective.twitter.portlets.config import PROJECTNAME
from collective.twitter.portlets import _
-
-from plone.memoize import ram
-from time import time
-
-import DateTime
-import twitter
-import hashlib
-import logging
+from collective.twitter.portlets.config import PROJECTNAME
logger = logging.getLogger(PROJECTNAME)
+
def TwitterAccounts(context):
registry = getUtility(IRegistry)
accounts = registry['collective.twitter.accounts']
@@ -79,7 +79,7 @@ class ITwitterSearchPortlet(IPortletDataProvider):
description=_(u"Show people's avatars."),
required=False)
- max_results = schema.Int(title=_(u'Maximum results'),
+ max_results = schema.Int(title=_(u'Maximum results'),
description=_(u"The maximum results number."),
required=True,
default=20)
@@ -129,7 +129,6 @@ def title(self):
return _(u"Twitter search Portlet")
-
class Renderer(base.Renderer):
"""Portlet renderer.
@@ -140,7 +139,6 @@ class Renderer(base.Renderer):
render = ViewPageTemplateFile('twsearch.pt')
-
def getHeader(self):
"""
Returns the header for the portlet
@@ -162,47 +160,45 @@ def getSearchResults(self):
registry = getUtility(IRegistry)
accounts = registry.get('collective.twitter.accounts', [])
- ploneutils = getToolByName(self.context, 'plone_utils')
-
account = accounts.get(self.data.tw_account, {})
results = []
if account:
logger.info("Got a valid account.")
- logger.info("consumer_key = %s"%account.get('consumer_key'))
- logger.info("consumer_secret = %s"%account.get('consumer_secret'))
- logger.info("access_token_key = %s"%account.get('oauth_token'))
- logger.info("access_token_secret = %s"%account.get('oauth_token_secret'))
+ logger.info("consumer_key = %s" % account.get('consumer_key'))
+ logger.info("consumer_secret = %s" % account.get('consumer_secret'))
+ logger.info("access_token_key = %s" % account.get('oauth_token'))
+ logger.info("access_token_secret = %s" % account.get('oauth_token_secret'))
- tw = twitter.Api(consumer_key = account.get('consumer_key'),
- consumer_secret = account.get('consumer_secret'),
- access_token_key = account.get('oauth_token'),
- access_token_secret = account.get('oauth_token_secret'),)
+ tw = twitter.Api(consumer_key=account.get('consumer_key'),
+ consumer_secret=account.get('consumer_secret'),
+ access_token_key=account.get('oauth_token'),
+ access_token_secret=account.get('oauth_token_secret'),)
search_str = self.data.search_string
max_results = self.data.max_results
try:
results = tw.GetSearch(search_str, per_page=max_results)
- logger.info("%s results obtained."%len(results))
+ logger.info("%s results obtained." % len(results))
except Exception, e:
- logger.info("Something went wrong: %s."%e)
+ logger.info("Something went wrong: %s." % e)
results = []
return results
-
def getTweet(self, result):
# The API includes the username in the tweet's text, we need to
# remove it here. Also, we need to make URLs, hastags and users,
# clickable.
- URL_TEMPLATE ="""
+
+ URL_TEMPLATE = """
<a href="%s" target="blank_">%s</a>
"""
- HASHTAG_TEMPLATE ="""
+ HASHTAG_TEMPLATE = """
<a href="http://twitter.com/#!/search?q=%s" target="blank_">%s</a>
"""
- USER_TEMPLATE ="""
+ USER_TEMPLATE = """
<a href="http://twitter.com/#!/%s" target="blank_">%s</a>
"""
@@ -216,15 +212,15 @@ def getTweet(self, result):
for index, word in enumerate(split_text):
if word.startswith('@'):
# This is a user
- split_text[index] = USER_TEMPLATE%(word[1:],word)
+ split_text[index] = USER_TEMPLATE % (word[1:], word)
elif word.startswith('#'):
# This is a hashtag
- split_text[index] = HASHTAG_TEMPLATE%("%23"+word[1:],word)
+ split_text[index] = HASHTAG_TEMPLATE % ("%23" + word[1:], word)
elif word.startswith('http'):
# This is a hashtag
- split_text[index] = URL_TEMPLATE%(word,word)
+ split_text[index] = URL_TEMPLATE % (word, word)
- return "<p>%s</p>"%' '.join(split_text)
+ return "<p>%s</p>" % ' '.join(split_text)
def getTweetUrl(self, result):
return "https://twitter.com/%s/status/%s" % \
@@ -239,7 +235,6 @@ def getReTweetUrl(self, result):
def getFavTweetUrl(self, result):
return "https://twitter.com/intent/favorite?tweet_id=%s" % result.id
-
def getDate(self, result):
if self.data.pretty_date:
# Returns human readable date for the tweet
@@ -250,6 +245,7 @@ def getDate(self, result):
return date
+
class AddForm(base.AddForm):
"""Portlet add form.
@@ -262,6 +258,7 @@ class AddForm(base.AddForm):
def create(self, data):
return Assignment(**data)
+
class EditForm(base.EditForm):
"""Portlet edit form.

0 comments on commit 983e9a3

Please sign in to comment.