[Checkins] SVN: Products.CMFTopic/trunk/Products/CMFTopic/ code cleanup:
Yvo Schubbe
cvs-admin at zope.org
Tue Apr 24 10:36:36 UTC 2012
Log message for revision 125267:
code cleanup:
- replaced has_key
- replaced oldstyle errors
- PEP 8
Changed:
U Products.CMFTopic/trunk/Products/CMFTopic/DateCriteria.py
U Products.CMFTopic/trunk/Products/CMFTopic/Topic.py
-=-
Modified: Products.CMFTopic/trunk/Products/CMFTopic/DateCriteria.py
===================================================================
--- Products.CMFTopic/trunk/Products/CMFTopic/DateCriteria.py 2012-04-24 10:36:19 UTC (rev 125266)
+++ Products.CMFTopic/trunk/Products/CMFTopic/DateCriteria.py 2012-04-24 10:36:32 UTC (rev 125267)
@@ -27,7 +27,7 @@
_as_of = DateTime # Allow for controlled value when testing
-class FriendlyDateCriterion( AbstractCriterion ):
+class FriendlyDateCriterion(AbstractCriterion):
"""
Put a friendly interface on date range searches, like
@@ -40,22 +40,21 @@
security = ClassSecurityInfo()
- _editableAttributes = ( 'value', 'operation', 'daterange' )
+ _editableAttributes = ('value', 'operation', 'daterange')
- _defaultDateOptions = ( ( 0, 'Now' )
- , ( 1, '1 Day' )
- , ( 2, '2 Days' )
- , ( 5, '5 Days' )
- , ( 7, '1 Week' )
- , ( 14, '2 Weeks' )
- , ( 31, '1 Month' )
- , ( 31*3, '3 Months' )
- , ( 31*6, '6 Months' )
- , ( 365, '1 Year' )
- , ( 365*2, '2 years' )
- )
+ _defaultDateOptions = ((0, 'Now'),
+ (1, '1 Day'),
+ (2, '2 Days'),
+ (5, '5 Days'),
+ (7, '1 Week'),
+ (14, '2 Weeks'),
+ (31, '1 Month'),
+ (31 * 3, '3 Months'),
+ (31 * 6, '6 Months'),
+ (365, '1 Year'),
+ (365 * 2, '2 years'))
- def __init__( self, id, field ):
+ def __init__(self, id, field):
self.id = id
self.field = field
@@ -63,50 +62,46 @@
self.operation = 'min'
self.daterange = 'old'
- security.declarePublic( 'defaultDateOptions' )
- def defaultDateOptions( self ):
+ security.declarePublic('defaultDateOptions')
+ def defaultDateOptions(self):
"""
Return a list of default values and labels for date options.
"""
return self._defaultDateOptions
- security.declareProtected( ChangeTopics, 'getEditForm' )
- def getEditForm( self ):
+ security.declareProtected(ChangeTopics, 'getEditForm')
+ def getEditForm(self):
"""
Return the name of the skin method used by Topic to edit
criteria of this type.
"""
return 'friendlydatec_editform'
- security.declareProtected( ChangeTopics, 'edit' )
- def edit( self
- , value=None
- , operation='min'
- , daterange='old'
- ):
+ security.declareProtected(ChangeTopics, 'edit')
+ def edit(self, value=None, operation='min', daterange='old'):
"""
Update the values to match against.
"""
- if value in ( None, '' ):
+ if value in (None, ''):
self.value = None
else:
try:
- self.value = int( value )
+ self.value = int(value)
except:
- raise ValueError, 'Supplied value should be an int'
+ raise ValueError('Supplied value should be an int')
- if operation in ( 'min', 'max', 'within_day' ):
+ if operation in ('min', 'max', 'within_day'):
self.operation = operation
else:
- raise ValueError, 'Operation type not in set {min,max,within_day}'
+ raise ValueError('Operation type not in set {min,max,within_day}')
- if daterange in ( 'old', 'ahead' ):
+ if daterange in ('old', 'ahead'):
self.daterange = daterange
else:
- raise ValueError, 'Date range not in set {old,ahead}'
+ raise ValueError('Date range not in set {old,ahead}')
security.declareProtected(View, 'getCriteriaItems')
- def getCriteriaItems( self ):
+ def getCriteriaItems(self):
"""
Return a sequence of items to be used to build the catalog query.
"""
@@ -135,23 +130,21 @@
if operation == 'within_day':
# When items within a day are requested, the range is between
# the earliest and latest time of that particular day
- range = ( date.earliestTime(), date.latestTime() )
- return ( ( field, {'query': range, 'range': 'min:max'} ), )
+ range = (date.earliestTime(), date.latestTime())
+ return ((field, {'query': range, 'range': 'min:max'}),)
elif operation == 'min':
if value != 0:
if self.daterange == 'old':
date_range = (date, now)
- return ( ( field, { 'query': date_range
- , 'range': 'min:max'
- } ), )
+ return ((field, {'query': date_range,
+ 'range': 'min:max'}),)
else:
- return ( ( field, { 'query': date.earliestTime()
- , 'range': operation
- } ), )
+ return ((field, {'query': date.earliestTime(),
+ 'range': operation}),)
else:
# Value 0 means "Now", so get everything from now on
- return ( ( field, {'query': date,'range': operation } ), )
+ return ((field, {'query': date, 'range': operation}),)
elif operation == 'max':
if value != 0:
@@ -159,12 +152,11 @@
return ((field, {'query': date, 'range': operation}),)
else:
date_range = (now, date.latestTime())
- return ( ( field, { 'query': date_range
- , 'range': 'min:max'
- } ), )
+ return ((field, {'query': date_range,
+ 'range': 'min:max'}),)
else:
# Value is 0, meaning "Now", get everything before "Now"
- return ( ( field, {'query': date, 'range': operation} ), )
+ return ((field, {'query': date, 'range': operation}),)
else:
return ()
@@ -172,4 +164,4 @@
# Register as a criteria type with the Topic class
-Topic._criteriaTypes.append( FriendlyDateCriterion )
+Topic._criteriaTypes.append(FriendlyDateCriterion)
Modified: Products.CMFTopic/trunk/Products/CMFTopic/Topic.py
===================================================================
--- Products.CMFTopic/trunk/Products/CMFTopic/Topic.py 2012-04-24 10:36:19 UTC (rev 125266)
+++ Products.CMFTopic/trunk/Products/CMFTopic/Topic.py 2012-04-24 10:36:32 UTC (rev 125267)
@@ -32,13 +32,13 @@
def addTopic(self, id, title='', REQUEST=None):
""" Create an empty topic.
"""
- topic = Topic( id )
+ topic = Topic(id)
topic.id = id
topic.title = title
self._setObject(id, topic, suppress_events=True)
if REQUEST is not None:
- REQUEST['RESPONSE'].redirect( 'manage_main' )
+ REQUEST['RESPONSE'].redirect('manage_main')
class Topic(SkinnedFolder):
@@ -61,7 +61,7 @@
def listCriteria(self):
""" Return a list of our criteria objects.
"""
- return self.objectValues( self._criteria_metatype_ids() )
+ return self.objectValues(self._criteria_metatype_ids())
security.declareProtected(ChangeTopics, 'listCriteriaTypes')
def listCriteriaTypes(self):
@@ -70,7 +70,7 @@
out = []
for ct in self._criteriaTypes:
- out.append( { 'name': ct.meta_type } )
+ out.append({'name': ct.meta_type})
return out
@@ -79,7 +79,7 @@
""" Return a list of available fields for new criteria.
"""
ctool = getUtility(ICatalogTool)
- currentfields = map( lambda x: x.Field(), self.listCriteria() )
+ currentfields = map(lambda x: x.Field(), self.listCriteria())
availfields = filter(
lambda field, cf=currentfields: field not in cf,
ctool.indexes()
@@ -90,7 +90,7 @@
def listSubtopics(self):
""" Return a list of our subtopics.
"""
- return self.objectValues( self.meta_type )
+ return self.objectValues(self.meta_type)
security.declareProtected(ChangeTopics, 'edit')
def edit(self, acquireCriteria, title=None, description=None):
@@ -118,8 +118,8 @@
try:
# Tracker 290 asks to allow combinations, like this:
# parent = aq_parent( self )
- parent = aq_parent( aq_inner( self ) )
- result.update( parent.buildQuery() )
+ parent = aq_parent(aq_inner(self))
+ result.update(parent.buildQuery())
except: # oh well, can't find parent, or it isn't a Topic.
pass
@@ -127,7 +127,7 @@
for criterion in self.listCriteria():
for key, value in criterion.getCriteriaItems():
- result[ key ] = value
+ result[key] = value
return result
@@ -149,8 +149,8 @@
syndication tool.
"""
syn_tool = getUtility(ISyndicationTool)
- limit = syn_tool.getMaxItems( self )
- brains = self.queryCatalog( sort_limit=limit )[ :limit ]
+ limit = syn_tool.getMaxItems(self)
+ brains = self.queryCatalog(sort_limit=limit)[:limit]
return [ brain.getObject() for brain in brains ]
### Criteria adding/editing/deleting
@@ -164,32 +164,32 @@
for ct in self._criteriaTypes:
if criterion_type == ct.meta_type:
- crit = ct( newid, field )
+ crit = ct(newid, field)
if crit is None:
# No criteria type matched passed in value
- raise NameError, 'Unknown Criterion Type: %s' % criterion_type
+ raise NameError('Unknown Criterion Type: %s' % criterion_type)
- self._setObject( newid, crit )
+ self._setObject(newid, crit)
security.declareProtected(ChangeTopics, 'deleteCriterion')
def deleteCriterion(self, criterion_id):
""" Delete selected criterion.
"""
- if type( criterion_id ) is type( '' ):
- self._delObject( criterion_id )
- elif type( criterion_id ) in ( type( () ), type( [] ) ):
+ if type(criterion_id) is type(''):
+ self._delObject(criterion_id)
+ elif type(criterion_id) in (type(()), type([])):
for cid in criterion_id:
- self._delObject( cid )
+ self._delObject(cid)
security.declareProtected(View, 'getCriterion')
def getCriterion(self, criterion_id):
""" Get the criterion object.
"""
try:
- return self._getOb( 'crit__%s' % criterion_id )
+ return self._getOb('crit__%s' % criterion_id)
except AttributeError:
- return self._getOb( criterion_id )
+ return self._getOb(criterion_id)
security.declareProtected(AddTopics, 'addSubtopic')
def addSubtopic(self, id):
@@ -197,7 +197,7 @@
"""
ti = self.getTypeInfo()
ti.constructInstance(self, id)
- return self._getOb( id )
+ return self._getOb(id)
#
# Helper methods
@@ -208,9 +208,9 @@
result = []
for mt in self._criteriaTypes:
- result.append( mt.meta_type )
+ result.append(mt.meta_type)
- return tuple( result )
+ return tuple(result)
InitializeClass(Topic)
More information about the checkins
mailing list