Skip to content

Commit

Permalink
Merge pull request #33 from plone/apply-hotfix-20160419
Browse files Browse the repository at this point in the history
Apply hotfix 20160419
  • Loading branch information
mauritsvanrees committed May 4, 2016
2 parents 4b17647 + c094c82 commit 74af184
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 306 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ New:

Fixes:

- Removed docstrings from some methods to avoid publishing them. From
Products.PloneHotfix20160419. [maurits]

- Fixed AttributeError ``unmarkCreationFlag`` during installation.
This could happen when there was already a Members folder from
``plone.app.contenttypes``. Fixes issue
Expand Down
73 changes: 27 additions & 46 deletions Products/ATContentTypes/content/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ class ATCTMixin(BrowserDefaultMixin):

@security.protected(ModifyPortalContent)
def initializeArchetype(self, **kwargs):
"""called by the generated add* factory in types tool
Overwritten to call edit() instead of update() to have the cmf
compatibility method.
"""
# Called by the generated add* factory in types tool.
#
# Overwritten to call edit() instead of update() to have the cmf
# compatibility method.
try:
self.initializeLayers()
self.markCreationFlag()
Expand All @@ -134,8 +133,7 @@ def initializeArchetype(self, **kwargs):

@security.private
def copyLayoutFromParent(self):
"""Copies the layout from the parent object if it's of the same type.
"""
# Copies the layout from the parent object if it's of the same type.
parent = aq_parent(aq_inner(self))
if parent is not None:
# Only set the layout if we are the same type as out parent object
Expand All @@ -150,9 +148,8 @@ def copyLayoutFromParent(self):

@security.protected(ModifyPortalContent)
def edit(self, *args, **kwargs):
"""Reimplementing edit() to have a compatibility method for the old
cmf edit() method
"""
# Reimplementing edit() to have a compatibility method for the old
# cmf edit() method
initializing = kwargs.get('_initializing_', False)
if initializing:
del kwargs['_initializing_']
Expand All @@ -174,14 +171,12 @@ def edit(self, *args, **kwargs):

@security.private
def cmf_edit(self, *args, **kwargs):
"""Overwrite this method to make AT compatible with the crappy
CMF edit()
"""
# Overwrite this method to make AT compatible with the crappy
# CMF edit()
raise NotImplementedError("cmf_edit method isn't implemented")

def exclude_from_nav(self):
"""Accessor for excludeFromNav field
"""
# Accessor for excludeFromNav field.
field = self.getField('excludeFromNav')
if field is not None:
return field.get(self)
Expand All @@ -190,8 +185,7 @@ def exclude_from_nav(self):

@security.protected(View)
def get_size(self):
"""ZMI / Plone get size method
"""
# ZMI / Plone get size method.
f = self.getPrimaryField()
if f is None:
return 0
Expand All @@ -208,10 +202,8 @@ class ATCTContent(ATCTMixin, BaseContent):
@security.private
def manage_afterPUT(self, data, marshall_data, file, context, mimetype,
filename, REQUEST, RESPONSE):
"""After webdav/ftp PUT method
Set title according to the id on webdav/ftp PUTs.
"""
# After webdav/ftp PUT method.
# Set title according to the id on webdav/ftp PUTs.
id = self.getId()
title = self.Title()
if not title:
Expand Down Expand Up @@ -268,23 +260,20 @@ def index_html(self, REQUEST=None, RESPONSE=None):

@security.protected(View)
def get_data(self):
"""CMF compatibility method
"""
# CMF compatibility method.
data = aq_base(self.getPrimaryField().getAccessor(self)())
return str(getattr(data, 'data', data))

data = ComputedAttribute(get_data, 1)

@security.protected(View)
def size(self):
"""Get size (image_view.pt)
"""
# Get size (image_view.pt).
return self.get_size()

@security.protected(View)
def get_content_type(self):
"""CMF compatibility method
"""
# CMF compatibility method.
f = self.getPrimaryField().getAccessor(self)()
# 'application/octet-stream'
return f and f.getContentType() or 'text/plain'
Expand Down Expand Up @@ -316,8 +305,7 @@ def manage_edit(self, title, content_type, precondition='',
return self.manage_main(self, REQUEST, manage_tabs_message=message)

def _cleanupFilename(self, filename, request=None):
"""Cleans the filename from unwanted or evil chars
"""
# Cleans the filename from unwanted or evil chars.
if filename and not isinstance(filename, unicode):
encoding = self.getCharset()
filename = unicode(filename, encoding)
Expand All @@ -326,10 +314,8 @@ def _cleanupFilename(self, filename, request=None):
return filename and filename.encode(encoding) or None

def _setATCTFileContent(self, value, **kwargs):
"""Set ID based on name of uploaded file, Title.
Or possibly other conditions.
"""
# Set ID based on name of uploaded file, Title.
# Or possibly other conditions.
field = self.getPrimaryField()
# set first then get the filename
field.set(self, value, **kwargs) # set is ok
Expand Down Expand Up @@ -373,8 +359,7 @@ def _should_set_id_to_filename(self, filename, title):

@security.protected(View)
def post_validate(self, REQUEST=None, errors=None):
"""Validates upload file and id
"""
# Validates upload file and id.
id = REQUEST.form.get('id')
field = self.getPrimaryField()
f_name = field.getName()
Expand Down Expand Up @@ -414,11 +399,9 @@ def post_validate(self, REQUEST=None, errors=None):
@security.private
def manage_afterPUT(self, data, marshall_data, file, context, mimetype,
filename, REQUEST, RESPONSE):
"""After webdav/ftp PUT method
Set the title according to the uploaded filename if the title
is empty or set it to the id if no filename is given.
"""
# After webdav/ftp PUT method.
# Set the title according to the uploaded filename if the title
# is empty or set it to the id if no filename is given.
id = self.getId()
title = self.Title()
if not title:
Expand Down Expand Up @@ -449,7 +432,7 @@ class ATCTFolder(ATCTMixin, BaseFolder):

@security.protected(View)
def get_size(self):
"""Returns 1 as folders have no size."""
# Returns 1 as folders have no size.
return 1

InitializeClass(ATCTFolder)
Expand All @@ -469,15 +452,13 @@ def __browser_default__(self, request):

@security.protected(View)
def get_size(self):
"""Returns 1 as folders have no size."""
# Returns 1 as folders have no size.
return 1

@security.private
def manage_afterMKCOL(self, id, result, REQUEST=None, RESPONSE=None):
"""After MKCOL handler
Set title according to the id
"""
# After MKCOL handler.
# Set title according to the id.
# manage_afterMKCOL is called in the context of the parent
# folder, *not* in the context of the new folder!
new = getattr(self, id)
Expand Down
50 changes: 19 additions & 31 deletions Products/ATContentTypes/content/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,24 @@ class ATDocumentBase(ATCTContent, HistoryAwareMixin):

@security.protected(View)
def CookedBody(self, stx_level='ignored'):
"""CMF compatibility method
"""
# CMF compatibility method.
return self.getText()

@security.protected(ModifyPortalContent)
def EditableBody(self):
"""CMF compatibility method
"""
# CMF compatibility method.
return self.getRawText()

@security.protected(ModifyPortalContent)
def setFormat(self, value):
"""CMF compatibility method
The default mutator is overwritten to:
o add a conversion from stupid CMF content type
(e.g. structured-text) to real mime types used by MTR.
o Set format to default format if value is empty
"""
# CMF compatibility method.
#
# The default mutator is overwritten to:
#
# o add a conversion from stupid CMF content type
# (e.g. structured-text) to real mime types used by MTR.
#
# o Set format to default format if value is empty
if not value:
value = zconf.ATDocument.default_content_type
else:
Expand All @@ -110,10 +106,8 @@ def setFormat(self, value):

@security.protected(ModifyPortalContent)
def setText(self, value, **kwargs):
"""Body text mutator
* hook into mxTidy an replace the value with the tidied value
"""
# Body text mutator.
# hook into mxTidy an replace the value with the tidied value
field = self.getField('text')

# When an object is initialized the first time we have to
Expand All @@ -135,8 +129,7 @@ def setText(self, value, **kwargs):

@security.private
def guessMimetypeOfText(self):
"""For ftp/webdav upload: get the mimetype from the id and data
"""
# For ftp/webdav upload: get the mimetype from the id and data.
mtr = getToolByName(self, 'mimetypes_registry')
id = self.getId()
data = self.getRawText()
Expand All @@ -159,9 +152,8 @@ def guessMimetypeOfText(self):

@security.private
def getTidyOutput(self, field):
"""Get the tidied output for a specific field from the request
if available
"""
# Get the tidied output for a specific field from the request
# if available.
request = getattr(self, 'REQUEST', None)
if request is not None and isinstance(request, HTTPRequest):
tidyAttribute = '%s_tidier_data' % field.getName()
Expand All @@ -177,9 +169,8 @@ def _notifyOfCopyTo(self, container, op=0):

@security.private
def manage_afterAdd(self, item, container):
"""Fix text when created througt webdav
Guess the right mimetype from the id/data
"""
# Fix text when created through webdav.
# Guess the right mimetype from the id/data.
ATCTContent.manage_afterAdd(self, item, container)
field = self.getField('text')

Expand All @@ -205,11 +196,8 @@ def cmf_edit(self, text_format, text, file='', safety_belt='', **kwargs):
@security.private
def manage_afterPUT(self, data, marshall_data, file, context, mimetype,
filename, REQUEST, RESPONSE):
"""After webdav/ftp PUT method
Set title according to the id on webdav/ftp PUTs.
"""

# After webdav/ftp PUT method.
# Set title according to the id on webdav/ftp PUTs.
if '' == data:
file.seek(0)
content = file.read(65536)
Expand Down
6 changes: 2 additions & 4 deletions Products/ATContentTypes/content/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,8 @@ def cmf_edit(

@security.protected(View)
def post_validate(self, REQUEST=None, errors=None):
"""Validates start and end date
End date must be after start date
"""
# Validates start and end date.
# End date must be after start date.
if 'startDate' in errors or 'endDate' in errors:
# No point in validating bad input
return
Expand Down
9 changes: 3 additions & 6 deletions Products/ATContentTypes/content/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def index_html(self, REQUEST=None, RESPONSE=None):

@security.protected(ModifyPortalContent)
def setFile(self, value, **kwargs):
"""Set id to uploaded id
"""
# Set id to uploaded id.
self._setATCTFileContent(value, **kwargs)

def __str__(self):
Expand All @@ -105,8 +104,7 @@ def __str__(self):

@security.public
def getIcon(self, relative_to_portal=0):
"""Calculate the icon using the mime type of the file
"""
# Calculate the icon using the mime type of the file.
field = self.getField('file')
if not field or not self.get_size():
# field is empty
Expand Down Expand Up @@ -144,8 +142,7 @@ def getIcon(self, relative_to_portal=0):

@security.protected(View)
def icon(self):
"""for ZMI
"""
# for ZMI
return self.getIcon()

@security.private
Expand Down
7 changes: 3 additions & 4 deletions Products/ATContentTypes/content/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ class ObsoleteATFolder(ATCTOrderedFolder):

@security.protected(View)
def getNextPreviousParentValue(self):
"""If the parent node is also an IATFolder and has next/previous
navigation enabled, then let this folder have it enabled by
default as well.
"""
# If the parent node is also an IATFolder and has next/previous
# navigation enabled, then let this folder have it enabled by
# default as well.
parent = self.__parent__
if IATFolder.providedBy(parent):
return parent.getNextPreviousEnabled()
Expand Down
15 changes: 6 additions & 9 deletions Products/ATContentTypes/content/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,22 @@ def exportImage(self, format, width, height):

@security.protected(ModifyPortalContent)
def setImage(self, value, refresh_exif=True, **kwargs):
"""Set ID to uploaded file name if Title is empty."""
# Set ID to uploaded file name if Title is empty.
# set exif first because rotation might screw up the exif data
# the exif methods can handle str, Pdata, OFSImage and file
# like objects
self.getEXIF(value, refresh=refresh_exif)
self._setATCTFileContent(value, **kwargs)

def _should_set_id_to_filename(self, filename, title):
"""If title is blank, have the caller set my ID to the file's name."""
# If title is blank, have the caller set my ID to the file's name.
# When the title is blank, sometimes the filename is returned as the
# title.
return filename == title or not title

@security.protected(View)
def tag(self, **kwargs):
"""Generate image tag using the api of the ImageField
"""
# Generate image tag using the api of the ImageField.
return self.getField('image').tag(self, **kwargs)

def __str__(self):
Expand All @@ -116,11 +115,9 @@ def __str__(self):

@security.protected(View)
def get_size(self):
"""ZMI / Plone get size method
BBB: ImageField.get_size() returns the size of the original image + all
scales but we want only the size of the original image.
"""
# ZMI / Plone get size method.
# BBB: ImageField.get_size() returns the size of the original image +
# all scales but we want only the size of the original image.
img = self.getImage()
if not getattr(aq_base(img), 'get_size', False):
return 0
Expand Down
Loading

0 comments on commit 74af184

Please sign in to comment.