Skip to content

Commit

Permalink
pyflakes
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Sep 20, 2013
1 parent 7f60ebe commit 27bde7d
Show file tree
Hide file tree
Showing 28 changed files with 223 additions and 302 deletions.
18 changes: 8 additions & 10 deletions Products/PloneSoftwareCenter/Extensions/Migrations.py
@@ -1,19 +1,17 @@
from StringIO import StringIO

from Acquisition import aq_base
from DateTime import DateTime
from Products.Archetypes import transaction
from Products.CMFCore.utils import getToolByName

try:
from Products.contentmigration.migrator import InlineFieldActionMigrator, BaseInlineMigrator
from Products.contentmigration.migrator import BaseInlineMigrator
from Products.contentmigration.walker import CustomQueryWalker
haveContentMigrations = True
except ImportError:
haveContentMigrations = False

import types

from StringIO import StringIO
from Products.CMFCore.utils import getToolByName
from Products.Archetypes import transaction
from Products.CMFPlone.utils import safe_hasattr

from Acquisition import aq_base
from DateTime import DateTime

def v1beta7_v1beta8(self, out):
"""Migrate from beta 7 to beta 8
Expand Down
57 changes: 28 additions & 29 deletions Products/PloneSoftwareCenter/Extensions/migrateratings.py
Expand Up @@ -7,40 +7,39 @@


class RatingsMigrator(BaseInlineMigrator):
"""
Migrate PSC Projects from the content ratings product to the twothumbs product
"""
"""
Migrate PSC Projects from the content ratings product to the twothumbs product
"""

src_portal_type = src_meta_type = 'PSCProject'
src_portal_type = src_meta_type = 'PSCProject'

def migrate_ratings(self):
def migrate_ratings(self):

"""
contentratings and twothumbs both use annotations. Just want to move
one to another. Here we say anything >= 3 rating is a thumbs up
"""
"""
contentratings and twothumbs both use annotations. Just want to move
one to another. Here we say anything >= 3 rating is a thumbs up
"""

from cioppino.twothumbs import rate as thumbrate
from cioppino.twothumbs import rate as thumbrate

transaction.begin()
item = self.obj
annotations = IAnnotations(item)
if annotations:
if annotations.has_key('contentratings.userrating.psc_stars'):
ratings = annotations['contentratings.userrating.psc_stars'].all_user_ratings()
annotations = thumbrate.setupAnnotations(item)
for rating in ratings:
userid = rating.userid
value = rating._rating
transaction.begin()
item = self.obj
annotations = IAnnotations(item)
if annotations:
if 'contentratings.userrating.psc_stars' in annotations:
ratings = annotations['contentratings.userrating.psc_stars'].all_user_ratings()
annotations = thumbrate.setupAnnotations(item)
for rating in ratings:

if rating >= 3.0:
thumbrate.loveIt(item, rating.userid)
else:
thumbrate.hateIt(item,rating.userid)
if rating >= 3.0:
thumbrate.loveIt(item, rating.userid)
else:
thumbrate.hateIt(item, rating.userid)

# we need to reindex th object anyways
item.reindexObject()
transaction.commit()

# we need to reindex th object anyways
item.reindexObject()
transaction.commit()

def migrate(self):
out = StringIO()
Expand All @@ -49,9 +48,9 @@ def migrate(self):
portal_url = getToolByName(self, 'portal_url')
portal = portal_url.getPortalObject()


# Migrate release count variable
walker = CustomQueryWalker(portal, RatingsMigrator, query = {'portal_type':'PSCProject'})
walker = CustomQueryWalker(portal, RatingsMigrator,
query = {'portal_type': 'PSCProject'})
transaction.savepoint(optimistic=True)
print >> out, "Switching from contentratings to twothumbs.."
walker.go(out=out)
Expand Down
19 changes: 7 additions & 12 deletions Products/PloneSoftwareCenter/__init__.py
@@ -1,20 +1,14 @@
"""
$Id$
"""

from Products.CMFCore.utils import ContentInit
from Products.CMFCore.DirectoryView import registerDirectory

from Products.Archetypes.atapi import listTypes, process_types
from Products.CMFCore import permissions as cmf_permissions
from Products.CMFCore.DirectoryView import registerDirectory
from Products.CMFCore.utils import ContentInit
from Products.validation import validation
from zope.i18nmessageid import MessageFactory

from Products.PloneSoftwareCenter import config
from Products.PloneSoftwareCenter import permissions as psc_permissions
from Products.CMFCore import permissions

from Products.validation import validation
from Products.PloneSoftwareCenter import validators

from zope.i18nmessageid import MessageFactory
PSCMessageFactory = MessageFactory('plonesoftwarecenter')

validation.register(validators.ProjectIdValidator('isNonConflictingProjectId'))
Expand All @@ -26,6 +20,7 @@
def initialize(context):
# Kick content registration and sys.modules mangling
from Products.PloneSoftwareCenter import content
content # pyflakes

allTypes = listTypes(config.PROJECTNAME)

Expand Down Expand Up @@ -76,7 +71,7 @@ def initialize(context):
ContentInit(
config.PROJECTNAME + ' Project Content',
content_types=tuple(member_content_types),
permission=permissions.AddPortalContent,
permission=cmf_permissions.AddPortalContent,
extra_constructors=tuple(member_constructors),
fti=ftis,
).initialize(context)
13 changes: 7 additions & 6 deletions Products/PloneSoftwareCenter/browser/category.py
@@ -1,6 +1,6 @@
from Products.Five.browser import BrowserView
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from Acquisition import aq_inner


class CategoryView(BrowserView):

Expand All @@ -21,10 +21,11 @@ def get_products(self, category, version, sort_on, SearchableText=None):
if sort_on == 'featured':
featured = True
sort_on = 'positive_ratings'
contentFilter = {'SearchableText': SearchableText,
'portal_type': 'PSCProject',
'sort_on' : sort_on,
'sort_order': 'reverse'}
contentFilter = {
'SearchableText': SearchableText,
'portal_type': 'PSCProject',
'sort_on': sort_on,
'sort_order': 'reverse'}

if version != 'any':
contentFilter['getCompatibility'] = version
Expand Down
7 changes: 4 additions & 3 deletions Products/PloneSoftwareCenter/browser/docfolder.py
@@ -1,6 +1,6 @@
from Products.Five.browser import BrowserView
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from Acquisition import aq_inner


class DocFolderView(BrowserView):

Expand Down Expand Up @@ -28,4 +28,5 @@ def non_phc_contents(self):
if not nonPHCTypes:
return []

return self.context.getFolderContents(contentFilter = {'portal_type' : nonPHCTypes})
return self.context.getFolderContents(
contentFilter={'portal_type': nonPHCTypes})
8 changes: 4 additions & 4 deletions Products/PloneSoftwareCenter/browser/downloadablefile.py
@@ -1,8 +1,8 @@
from Products.Five.browser import BrowserView
import re

from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from Acquisition import aq_inner

import re

class DownloadableFileView(BrowserView):

Expand All @@ -24,7 +24,7 @@ def downloadicon_name(self):
(including whitespace) converted to underscores.
"""
return 'platform_%s.gif' % \
re.sub(r'\W', '_', self.context.getPlatform()).lower()
re.sub(r'\W', '_', self.context.getPlatform()).lower()

def file_size(self):
"""Return the file size of the download, or None if unknown.
Expand Down
8 changes: 4 additions & 4 deletions Products/PloneSoftwareCenter/browser/filelink.py
@@ -1,8 +1,8 @@
from Products.Five.browser import BrowserView
import re

from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from Acquisition import aq_inner

import re

class FileLinkView(BrowserView):

Expand All @@ -24,7 +24,7 @@ def downloadicon_name(self):
(including whitespace) converted to underscores.
"""
return 'platform_%s.gif' % \
re.sub(r'\W', '_', self.context.getPlatform()).lower()
re.sub(r'\W', '_', self.context.getPlatform()).lower()

def file_size(self):
"""Return the file size of the download, or None if unknown.
Expand Down
4 changes: 2 additions & 2 deletions Products/PloneSoftwareCenter/browser/improvement.py
@@ -1,6 +1,6 @@
from Products.Five.browser import BrowserView
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from Acquisition import aq_inner


class ImprovementView(BrowserView):

Expand Down

0 comments on commit 27bde7d

Please sign in to comment.