Skip to content

Commit

Permalink
Merge pull request #37 from plone/gforcada-patch-1
Browse files Browse the repository at this point in the history
Cleanup code
  • Loading branch information
gforcada authored Dec 20, 2016
2 parents 2b5e5c3 + a5ad845 commit fe49bc3
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 163 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Bug fixes:
- Cleanup: isort, zca decorators, etc.
[jensens]

- Some more cleanup.
[gforcada]

3.2.3 (2016-11-10)
------------------
Expand Down
8 changes: 5 additions & 3 deletions plone/app/iterate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@

try:
import plone.app.stagingbehavior # noqa
logger.error('plone.app.stagingbehavior should NOT be installed with this version '
'of plone.app.iterate. You may experience problems running this configuration. '
'plone.app.iterate now has dexterity suport built-in.')
logger.error(
'plone.app.stagingbehavior should NOT be installed with this version '
'of plone.app.iterate. You may experience problems running this '
'configuration. plone.app.iterate now has dexterity suport built-in.'
)
except ImportError:
pass
6 changes: 1 addition & 5 deletions plone/app/iterate/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
# along with CMFDeployment; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##################################################################
"""
$Id: archiver.py 1824 2007-02-08 17:59:41Z hazmat $
"""

from Products.CMFCore.utils import getToolByName
from zope.component import adapter
from zope.interface import implementer
Expand Down Expand Up @@ -55,5 +51,5 @@ def isVersioned(self):
def isModified(self):
try:
return not self.repository.isUpToDate(self.context)
except:
except Exception:
return False
14 changes: 7 additions & 7 deletions plone/app/iterate/browser/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ class Cancel(BrowserView):
def __call__(self):
context = aq_inner(self.context)

if self.request.form.has_key('form.button.Cancel'):
if 'form.button.Cancel' in self.request.form:
control = getMultiAdapter(
(context, self.request), name=u"iterate_control")
(context, self.request), name=u'iterate_control')
if not control.cancel_allowed():
raise CheckoutException(u"Not a checkout")
raise CheckoutException(u'Not a checkout')

policy = ICheckinCheckoutPolicy(context)
baseline = policy.cancelCheckout()
baseline.reindexObject()

IStatusMessage(self.request).addStatusMessage(
_(u"Checkout cancelled"), type='info')
_(u'Checkout cancelled'), type='info')
view_url = baseline.restrictedTraverse(
"@@plone_context_state").view_url()
'@@plone_context_state').view_url()
self.request.response.redirect(view_url)
elif self.request.form.has_key('form.button.Keep'):
elif 'form.button.Keep' in self.request.form:
view_url = context.restrictedTraverse(
"@@plone_context_state").view_url()
'@@plone_context_state').view_url()
self.request.response.redirect(view_url)
else:
return self.index()
16 changes: 8 additions & 8 deletions plone/app/iterate/browser/checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ class Checkin(BrowserView):
def __call__(self):
context = aq_inner(self.context)

if self.request.form.has_key('form.button.Checkin'):
if 'form.button.Checkin' in self.request.form:
control = getMultiAdapter(
(context, self.request), name=u"iterate_control")
(context, self.request), name=u'iterate_control')
if not control.checkin_allowed():
raise CheckinException(u"Not a checkout")
raise CheckinException(u'Not a checkout')

message = self.request.form.get('checkin_message', "")
message = self.request.form.get('checkin_message', '')

policy = ICheckinCheckoutPolicy(context)
baseline = policy.checkin(message)

IStatusMessage(self.request).addStatusMessage(
_("Checked in"), type='info')
_('Checked in'), type='info')
view_url = baseline.restrictedTraverse(
"@@plone_context_state").view_url()
'@@plone_context_state').view_url()
self.request.response.redirect(view_url)
elif self.request.form.has_key('form.button.Cancel'):
elif 'form.button.Cancel'in self.request.form:
view_url = context.restrictedTraverse(
"@@plone_context_state").view_url()
'@@plone_context_state').view_url()
self.request.response.redirect(view_url)
else:
return self.index()
25 changes: 15 additions & 10 deletions plone/app/iterate/browser/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,25 @@ def __call__(self):
# end up downloading a file
if 'form.button.Checkout' in self.request.form:
control = getMultiAdapter(
(context, self.request), name=u"iterate_control")
(context, self.request), name=u'iterate_control')
if not control.checkout_allowed():
raise CheckoutException(u"Not allowed")
raise CheckoutException(u'Not allowed')

location = self.request.form.get('checkout_location', None)
locator = None
try:
locator = [c['locator']
for c in self.containers() if c['name'] == location][0]
locator = [
c['locator']
for c in self.containers()
if c['name'] == location
][0]
except IndexError:
IStatusMessage(self.request).addStatusMessage(_("Cannot find checkout location"),
type='error')
IStatusMessage(self.request).addStatusMessage(
_('Cannot find checkout location'),
type='error'
)
view_url = context.restrictedTraverse(
"@@plone_context_state").view_url()
'@@plone_context_state').view_url()
self.request.response.redirect(view_url)
return

Expand All @@ -77,13 +82,13 @@ def __call__(self):
context.reindexObject('review_state')

IStatusMessage(self.request).addStatusMessage(
_("Check-out created"), type='info')
_('Check-out created'), type='info')
view_url = wc.restrictedTraverse(
"@@plone_context_state").view_url()
'@@plone_context_state').view_url()
self.request.response.redirect(view_url)
elif 'form.button.Cancel' in self.request.form:
view_url = context.restrictedTraverse(
"@@plone_context_state").view_url()
'@@plone_context_state').view_url()
self.request.response.redirect(view_url)
else:
return self.index()
6 changes: 5 additions & 1 deletion plone/app/iterate/browser/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def checkin_allowed(self):
if original is None:
return False

if not checkPermission(Products.CMFCore.permissions.ModifyPortalContent, original):
can_modify = checkPermission(
Products.CMFCore.permissions.ModifyPortalContent,
original,
)
if not can_modify:
return False

return True
Expand Down
6 changes: 3 additions & 3 deletions plone/app/iterate/browser/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def __call__(self):
self.working_copy = self.context
self.baseline = policy.getBaseline()
else:
raise AttributeError("Invalid Context")
raise AttributeError('Invalid Context')
return self.index()

def diffs(self):
diff = getToolByName(self.context, 'portal_diff')
return diff.createChangeSet(self.baseline,
self.working_copy,
id1="Baseline",
id2="Working Copy")
id1='Baseline',
id2='Working Copy')
18 changes: 12 additions & 6 deletions plone/app/iterate/browser/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def policy(self):
def created(self):
time = self.properties.get(keys.checkout_time, DateTime())
util = getToolByName(self.context, 'translation_service')
return util.ulocalized_time(time, context=self.context, domain='plonelocales')
return util.ulocalized_time(
time,
context=self.context,
domain='plonelocales',
)

@memoize
def creator(self):
Expand All @@ -58,7 +62,7 @@ def creator_url(self):
creator = self.creator()
if creator is not None:
portal_url = getToolByName(self.context, 'portal_url')
return "%s/author/%s" % (portal_url(), creator.getId())
return '{0}/author/{1}'.format(portal_url(), creator.getId())

@memoize
def creator_name(self):
Expand All @@ -69,10 +73,12 @@ def creator_name(self):
# the user and log this.
name = self.properties.get(keys.checkout_user)
if IBaseline.providedBy(self.context):
warning_tpl = "%s is a baseline of a plone.app.iterate checkout by an unknown user id '%s'" # noqa
warning_tpl = '%s is a baseline of a plone.app.iterate checkout ' \
'by an unknown user id "%s"'
else:
# IWorkingCopy.providedBy(self.context)
warning_tpl = "%s is a working copy of a plone.app.iterate checkout by an unknown user id '%s'" # noqa
warning_tpl = '%s is a working copy of a plone.app.iterate ' \
'checkout by an unknown user id "%s"'
logger.warning(warning_tpl, self.context, name)
return name

Expand Down Expand Up @@ -102,7 +108,7 @@ def render(self):
sm.checkPermission(ModifyPortalContent, working_copy)):
return self.index()
else:
return ""
return ''

@memoize
def working_copy(self):
Expand All @@ -124,7 +130,7 @@ def render(self):
sm.checkPermission(CheckoutPermission, baseline)):
return self.index()
else:
return ""
return ''

@memoize
def baseline(self):
Expand Down
4 changes: 2 additions & 2 deletions plone/app/iterate/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HomeFolderLocator(object):
def __init__(self, context):
self.context = context

title = _(u"Home folder")
title = _(u'Home folder')

@property
def available(self):
Expand All @@ -62,7 +62,7 @@ class ParentFolderLocator(object):
def __init__(self, context):
self.context = context

title = _(u"Parent folder")
title = _(u'Parent folder')

@property
def available(self):
Expand Down
10 changes: 5 additions & 5 deletions plone/app/iterate/copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def copyTo(self, container):
self.context,
relationship=WorkingCopyRelation.relationship,
referenceClass=WorkingCopyRelation)
self._handleReferences(self.context, wc, "checkout", wc_ref)
self._handleReferences(self.context, wc, 'checkout', wc_ref)
return wc, wc_ref

def merge(self):
Expand All @@ -67,7 +67,7 @@ def merge(self):
wc_ref = self._deleteWorkingCopyRelation()

# reassemble references on the new baseline
self._handleReferences(baseline, self.context, "checkin", wc_ref)
self._handleReferences(baseline, self.context, 'checkin', wc_ref)

# move the working copy to the baseline container, deleting
# the baseline
Expand All @@ -84,10 +84,10 @@ def _getBaseline(self):
refs = self.context.getRefs(WorkingCopyRelation.relationship)

if not len(refs) == 1:
raise CheckinException("Baseline count mismatch")
raise CheckinException('Baseline count mismatch')

if not refs or refs[0] is None:
raise CheckinException("Baseline has disappeared")
raise CheckinException('Baseline has disappeared')

baseline = refs[0]
return baseline
Expand Down Expand Up @@ -251,7 +251,7 @@ def _handleReferences(self, baseline, wc, mode, wc_ref):
mode_method = getattr(adapter, mode)
mode_method(baseline, wc, references, annotations)

mode = mode + "BackReferences"
mode = mode + 'BackReferences'

# handle backward references
for relationship in baseline.getBRelationships():
Expand Down
12 changes: 6 additions & 6 deletions plone/app/iterate/dexterity/copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

try:
from zope.intid.interfaces import IIntIds
except:
except ImportError:
from zope.app.intid.interfaces import IIntIds


Expand All @@ -48,7 +48,7 @@ def merge(self):
wc_ref = self._deleteWorkingCopyRelation()

# reassemble references on the new baseline
self._handleReferences(baseline, self.context, "checkin", wc_ref)
self._handleReferences(baseline, self.context, 'checkin', wc_ref)

# move the working copy to the baseline container, deleting the
# baseline
Expand All @@ -74,7 +74,7 @@ def _replaceBaseline(self, baseline):
continue
try:
value = field.get(schema(self.context))
except:
except Exception:
value = None

# TODO: We need a way to identify the DCFieldProperty
Expand Down Expand Up @@ -141,10 +141,10 @@ def _get_relation_to_baseline(self):
relations)
# do we have a baseline in our relations?
if relations and not len(relations) == 1:
raise interfaces.CheckinException("Baseline count mismatch")
raise interfaces.CheckinException('Baseline count mismatch')

if not relations or not relations[0]:
raise interfaces.CheckinException("Baseline has disappeared")
raise interfaces.CheckinException('Baseline has disappeared')
return relations[0]

def _getBaseline(self):
Expand All @@ -154,7 +154,7 @@ def _getBaseline(self):
baseline = intids.getObject(relation.from_id)

if not baseline:
raise interfaces.CheckinException("Baseline has disappeared")
raise interfaces.CheckinException('Baseline has disappeared')
return baseline

def checkin(self, checkin_message):
Expand Down
1 change: 0 additions & 1 deletion plone/app/iterate/dexterity/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from plone.app.iterate.interfaces import IIterateAware
from z3c.relationfield.interfaces import IRelationValue
from zope.interface import Attribute


class IStagingRelationValue(IRelationValue):
Expand Down
10 changes: 6 additions & 4 deletions plone/app/iterate/dexterity/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@


@implementer(iterate.interfaces.ICheckinCheckoutPolicy)
class CheckinCheckoutPolicyAdapter(iterate.policy.CheckinCheckoutPolicyAdapter):
class CheckinCheckoutPolicyAdapter(
iterate.policy.CheckinCheckoutPolicyAdapter
):
"""
Dexterity Checkin Checkout Policy
"""
Expand All @@ -22,19 +24,19 @@ def _get_relation_to_baseline(self):

if relations and not len(relations) == 1:
raise iterate.interfaces.CheckinException(
"Baseline count mismatch")
'Baseline count mismatch')

if not relations or not relations[0]:
raise iterate.interfaces.CheckinException(
"Baseline has disappeared")
'Baseline has disappeared')

return relations[0]

def _getBaseline(self):
baseline = get_baseline(self.context)
if not baseline:
raise iterate.interfaces.CheckinException(
"Baseline has disappeared")
'Baseline has disappeared')
return baseline

def checkin(self, checkin_message):
Expand Down
Loading

0 comments on commit fe49bc3

Please sign in to comment.