Skip to content

Commit

Permalink
autopep8 -ir
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Sep 27, 2016
1 parent c8a0caf commit bdde644
Show file tree
Hide file tree
Showing 24 changed files with 876 additions and 448 deletions.
58 changes: 39 additions & 19 deletions plone/app/caching/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def update(self):
self.registry = getUtility(IRegistry)
self.settings = self.registry.forInterface(ICacheSettings)
self.ploneSettings = self.registry.forInterface(IPloneCacheSettings)
self.purgingSettings = self.registry.forInterface(ICachePurgingSettings)
self.purgingSettings = self.registry.forInterface(
ICachePurgingSettings)
self.ramCache = queryUtility(IRAMCache)

if self.request.method == 'POST':
Expand Down Expand Up @@ -113,7 +114,8 @@ def publishTraverse(self, request, name):

if self.editGlobal:

operation = queryUtility(ICachingOperationType, name=self.editOperationName)
operation = queryUtility(
ICachingOperationType, name=self.editOperationName)
if operation is None:
raise NotFound(self, operation)

Expand All @@ -127,7 +129,8 @@ def publishTraverse(self, request, name):
if self.editRuleset and self.editOperationName and not self.editRulesetName:
self.editRulesetName = name

operation = queryUtility(ICachingOperationType, name=self.editOperationName)
operation = queryUtility(
ICachingOperationType, name=self.editOperationName)
if operation is None:
raise NotFound(self, self.operationName)

Expand Down Expand Up @@ -255,7 +258,8 @@ def processSave(self):

for domain in domains:
if not _isuri(domain):
self.errors['domain'] = _(u"Invalid URL: ${url}", mapping={'url': domain})
self.errors['domain'] = _(
u"Invalid URL: ${url}", mapping={'url': domain})

# RAM cache settings

Expand All @@ -265,27 +269,32 @@ def processSave(self):
self.errors['ramCacheMaxEntries'] = _(u"An integer is required.")
else:
if ramCacheMaxEntries < 0:
self.errors['ramCacheMaxEntries'] = _(u"A positive number is required.")
self.errors['ramCacheMaxEntries'] = _(
u"A positive number is required.")

try:
ramCacheMaxAge = int(ramCacheMaxAge)
except (ValueError, TypeError,):
self.errors['ramCacheMaxAge'] = _(u"An integer is required.")
else:
if ramCacheMaxAge < 0:
self.errors['ramCacheMaxAge'] = _(u"A positive number is required.")
self.errors['ramCacheMaxAge'] = _(
u"A positive number is required.")

try:
ramCacheCleanupInterval = int(ramCacheCleanupInterval)
except (ValueError, TypeError,):
self.errors['ramCacheCleanupInterval'] = _(u"An integer is required.")
self.errors['ramCacheCleanupInterval'] = _(
u"An integer is required.")
else:
if ramCacheMaxAge < 0:
self.errors['ramCacheCleanupInterval'] = _(u"A positive number is required.")
self.errors['ramCacheCleanupInterval'] = _(
u"A positive number is required.")

# Check for errors
if self.errors:
IStatusMessage(self.request).addStatusMessage(_(u"There were errors."), "error")
IStatusMessage(self.request).addStatusMessage(
_(u"There were errors."), "error")
return

# Save settings
Expand All @@ -301,9 +310,11 @@ def processSave(self):
self.purgingSettings.virtualHosting = virtualHosting
self.purgingSettings.domains = domains

self.ramCache.update(ramCacheMaxEntries, ramCacheMaxAge, ramCacheCleanupInterval)
self.ramCache.update(ramCacheMaxEntries,
ramCacheMaxAge, ramCacheCleanupInterval)

IStatusMessage(self.request).addStatusMessage(_(u"Changes saved."), "info")
IStatusMessage(self.request).addStatusMessage(
_(u"Changes saved."), "info")

# Rule types - used as the index column
@property
Expand Down Expand Up @@ -368,7 +379,8 @@ def contentTypesLookup(self):
types = {}
portal_types = getToolByName(self.context, 'portal_types')
for fti in portal_types.objectValues():
types[fti.id] = dict(title=fti.title or fti.id, description=fti.description)
types[fti.id] = dict(title=fti.title or fti.id,
description=fti.description)
return types

# Sorted lists (e.g. for drop-downs)
Expand All @@ -377,7 +389,8 @@ def contentTypesLookup(self):
@memoize
def operationTypes(self):
operations = [v for k, v in self.operationTypesLookup.items()]
operations.sort(lambda x, y: (cmp(x['sort'], y['sort']) or cmp(x['title'], y['title'])))
operations.sort(lambda x, y: (
cmp(x['sort'], y['sort']) or cmp(x['title'], y['title'])))
return operations

@property
Expand Down Expand Up @@ -463,7 +476,8 @@ def processImport(self):
self.errors['profile'] = _(u"You must select a profile to import.")

if self.errors:
IStatusMessage(self.request).addStatusMessage(_(u"There were errors."), "error")
IStatusMessage(self.request).addStatusMessage(
_(u"There were errors."), "error")
return

portal_setup = getToolByName(self.context, 'portal_setup')
Expand All @@ -477,7 +491,8 @@ def processImport(self):
# Import the new profile
portal_setup.runAllImportStepsFromProfile("profile-%s" % profile)

IStatusMessage(self.request).addStatusMessage(_(u"Import complete."), "info")
IStatusMessage(self.request).addStatusMessage(
_(u"Import complete."), "info")

@property
@memoize
Expand All @@ -490,6 +505,7 @@ def profiles(self):
class Purge(BaseView):
"""The purge control panel
"""

def update(self):
self.purgeLog = []

Expand All @@ -505,7 +521,8 @@ def processPurge(self):
self.errors['urls'] = _(u"No URLs or paths entered.")

if self.errors:
IStatusMessage(self.request).addStatusMessage(_(u"There were errors."), "error")
IStatusMessage(self.request).addStatusMessage(
_(u"There were errors."), "error")
return

purger = getUtility(IPurger)
Expand Down Expand Up @@ -581,11 +598,14 @@ def update(self):
def processPurge(self):

if self.ramCache is None:
IStatusMessage(self.request).addStatusMessage(_(u"RAM cache not installed."), "error")
IStatusMessage(self.request).addStatusMessage(
_(u"RAM cache not installed."), "error")

if self.errors:
IStatusMessage(self.request).addStatusMessage(_(u"There were errors."), "error")
IStatusMessage(self.request).addStatusMessage(
_(u"There were errors."), "error")
return

self.ramCache.invalidateAll()
IStatusMessage(self.request).addStatusMessage(_(u"Cache purged."), "info")
IStatusMessage(self.request).addStatusMessage(
_(u"Cache purged."), "info")
58 changes: 38 additions & 20 deletions plone/app/caching/browser/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class EditForm(form.Form):

template = ViewPageTemplateFile('edit.pt')

# Keep the ZPublisher happy - would normally be done by the ZCML registration
# Keep the ZPublisher happy - would normally be done by the ZCML
# registration
__name__ = 'cache-operation-edit'

def __init__(self, context, request, operationName, operation, rulesetName=None, ruleset=None):
Expand All @@ -70,7 +71,8 @@ def update(self):

self.registry = getUtility(IRegistry)

# If we were using plone.z3cform, this would be done with z2.switch_on()
# If we were using plone.z3cform, this would be done with
# z2.switch_on()
if not IFormLayer.providedBy(self.request):
alsoProvides(self.request, IFormLayer)

Expand All @@ -88,18 +90,22 @@ def update(self):
fieldName = "%s.%s" % (prefix, option)

if self.rulesetName:
rulesetFieldName = "%s.%s.%s" % (prefix, self.rulesetName, option)
rulesetFieldName = "%s.%s.%s" % (
prefix, self.rulesetName, option)

if rulesetFieldName in self.registry.records:
newField = self.cloneField(self.registry.records[rulesetFieldName].field)
newField = self.cloneField(self.registry.records[
rulesetFieldName].field)
newField.__name__ = rulesetFieldName
elif fieldName in self.registry.records:
newField = self.cloneField(self.registry.records[fieldName].field)
newField = self.cloneField(
self.registry.records[fieldName].field)
newField.__name__ = rulesetFieldName

else:
if fieldName in self.registry.records:
newField = self.cloneField(self.registry.records[fieldName].field)
newField = self.cloneField(
self.registry.records[fieldName].field)
newField.__name__ = fieldName

if newField is not None:
Expand Down Expand Up @@ -142,10 +148,12 @@ def getContent(self):
# as necessary in applyChanges()

if self.rulesetName:
rulesetRecordName = "%s.%s.%s" % (prefix, self.rulesetName, option,)
rulesetRecordName = "%s.%s.%s" % (
prefix, self.rulesetName, option,)

if rulesetRecordName in self.registry.records:
context[rulesetRecordName] = self.registry[rulesetRecordName]
context[rulesetRecordName] = self.registry[
rulesetRecordName]
elif recordName in self.registry.records:
context[rulesetRecordName] = self.registry[recordName]

Expand All @@ -171,12 +179,15 @@ def applyChanges(self, data):
# Strip the ruleset name out, leaving the original key - this
# must exist, otherwise getContent() would not have put it in
# the data dictionary
globalKey = self.operation.prefix + key[len(self.operation.prefix) + len(self.rulesetName) + 1:]
globalKey = self.operation.prefix + \
key[len(self.operation.prefix) +
len(self.rulesetName) + 1:]
assert globalKey in self.registry.records

# Create a new record with a FieldRef
field = self.registry.records[globalKey].field
self.registry.records[key] = Record(FieldRef(globalKey, field), value)
self.registry.records[key] = Record(
FieldRef(globalKey, field), value)

else:
self.registry[key] = value
Expand Down Expand Up @@ -205,11 +216,11 @@ def cloneField(self, field):
def title(self):
if self.rulesetName:
return _(u"Edit ${operation} options for Ruleset: ${ruleset}",
mapping={'operation': self.operation.title,
'ruleset': self.ruleset.title})
mapping={'operation': self.operation.title,
'ruleset': self.ruleset.title})
else:
return _(u"Edit ${operation} options",
mapping={'operation': self.operation.title})
mapping={'operation': self.operation.title})

@property
def description(self):
Expand All @@ -224,23 +235,30 @@ def save(self, action):
self.status = self.formErrorsMessage
return
self.applyChanges(data)
IStatusMessage(self.request).addStatusMessage(_(u"Changes saved."), "info")
self.request.response.redirect("%s/@@caching-controlpanel#detailed-settings" % self.context.absolute_url())
IStatusMessage(self.request).addStatusMessage(
_(u"Changes saved."), "info")
self.request.response.redirect(
"%s/@@caching-controlpanel#detailed-settings" % self.context.absolute_url())

@button.buttonAndHandler(_(u"Cancel"), name="cancel")
def cancel(self, action):
IStatusMessage(self.request).addStatusMessage(_(u"Edit cancelled."), type="info")
self.request.response.redirect("%s/@@caching-controlpanel#detailed-settings" % self.context.absolute_url())
IStatusMessage(self.request).addStatusMessage(
_(u"Edit cancelled."), type="info")
self.request.response.redirect(
"%s/@@caching-controlpanel#detailed-settings" % self.context.absolute_url())
return ''

@button.buttonAndHandler(_(u"Delete settings (use defaults)"), name="clear")
def clear(self, action):
for key in self.getContent().keys():
assert key.startswith("%s.%s." % (self.operation.prefix, self.rulesetName,))
assert key.startswith("%s.%s." % (
self.operation.prefix, self.rulesetName,))

if key in self.registry.records:
del self.registry.records[key]

IStatusMessage(self.request).addStatusMessage(_(u"Ruleset-specific settings removed."), type="info")
self.request.response.redirect("%s/@@caching-controlpanel#detailed-settings" % self.context.absolute_url())
IStatusMessage(self.request).addStatusMessage(
_(u"Ruleset-specific settings removed."), type="info")
self.request.response.redirect(
"%s/@@caching-controlpanel#detailed-settings" % self.context.absolute_url())
return ''
46 changes: 26 additions & 20 deletions plone/app/caching/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

_ = zope.i18nmessageid.MessageFactory('plone.app.caching')


class ICacheProfiles(Interface):
"""Marker interface for extension profiles that contain cache settings.
These will primarily include a ``registry.xml`` file to configure cache
Expand All @@ -27,6 +28,7 @@ class ICacheProfiles(Interface):
available for installation in the cache settings control panel.
"""


class IPloneCacheSettings(Interface):
"""Settings stored in the registry.
Expand All @@ -36,32 +38,35 @@ class IPloneCacheSettings(Interface):
"""

templateRulesetMapping = schema.Dict(
title=_(u"Page template/ruleset mapping"),
description=_(u"Maps skin layer page template names to ruleset names"),
key_type=schema.ASCIILine(title=_(u"Page template name")),
value_type=schema.DottedName(title=_(u"Ruleset name")),
)
title=_(u"Page template/ruleset mapping"),
description=_(u"Maps skin layer page template names to ruleset names"),
key_type=schema.ASCIILine(title=_(u"Page template name")),
value_type=schema.DottedName(title=_(u"Ruleset name")),
)

contentTypeRulesetMapping = schema.Dict(
title=_(u"Content type/ruleset mapping"),
description=_(u"Maps content type names to ruleset names"),
key_type=schema.ASCIILine(title=_(u"Content type name")),
value_type=schema.DottedName(title=_(u"Ruleset name")),
)
title=_(u"Content type/ruleset mapping"),
description=_(u"Maps content type names to ruleset names"),
key_type=schema.ASCIILine(title=_(u"Content type name")),
value_type=schema.DottedName(title=_(u"Ruleset name")),
)

purgedContentTypes = schema.Tuple(
title=_(u"Content types to purge"),
description=_(u"List content types which should be purged when modified"),
value_type=schema.ASCIILine(title=_(u"Content type name")),
default=('File', 'Image', 'News Item', ),
)
title=_(u"Content types to purge"),
description=_(
u"List content types which should be purged when modified"),
value_type=schema.ASCIILine(title=_(u"Content type name")),
default=('File', 'Image', 'News Item', ),
)

cacheStopRequestVariables = schema.Tuple(
title=_(u"Request variables that prevent caching"),
description=_(u"Variables in the request that prevent caching if present"),
value_type=schema.ASCIILine(title=_(u"Request variables")),
default=('statusmessages', 'SearchableText',),
)
title=_(u"Request variables that prevent caching"),
description=_(
u"Variables in the request that prevent caching if present"),
value_type=schema.ASCIILine(title=_(u"Request variables")),
default=('statusmessages', 'SearchableText',),
)


class IETagValue(Interface):
"""ETag component builder
Expand All @@ -76,6 +81,7 @@ def __call__():
"""Return the ETag component, as a string.
"""


class IRAMCached(Interface):
"""Marker interface applied to the request if it should be RAM cached.
Expand Down
Loading

0 comments on commit bdde644

Please sign in to comment.