Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
miknevinas committed Oct 4, 2024
2 parents e4e2e6d + 86a6758 commit dda18ea
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
21 changes: 20 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
Changelog
=========

3.0.0b142 (unreleased)
3.0.0b145 (unreleased)
----------------------

- Nothing changed yet.


3.0.0b144 (2024-09-24)
----------------------

- add initial support for explicit asynchronous paste, intended for large objects
or large quantities of objects


3.0.0b143 (2024-09-19)
----------------------

- Fix bug while swapping file in UploadNamedFileWidget


3.0.0b142 (2024-09-18)
----------------------

- Fix for s3 stored files included in feed item xml


3.0.0b141 (2024-07-12)
----------------------

Expand Down
31 changes: 27 additions & 4 deletions castle/cms/syndication.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from castle.cms.files.aws import uploaded
from castle.cms.theming import contentpanel_xpath
from castle.cms.utils import has_image
from lxml.html import tostring
Expand Down Expand Up @@ -49,17 +50,39 @@ def _init(self):
except TypeError:
pass

@property
def in_aws(self):
return uploaded(self.context)

@property
def has_local_file(self):
return self.file is not None and not self.in_aws

@property
def has_enclosure(self):
return self.in_aws or self.has_local_file

@property
def file_length(self):
if self.has_enclosure:
if self.in_aws:
try:
return self.file.getSize()
except POSKeyError:
return self.context.file.original_size
except Exception: # nosec B110
pass
except SystemError:
if self.has_local_file:
try:
return self.file.getSize()
except Exception: # nosec B110
pass
return 0

@property
def file_type(self):
if self.in_aws:
return self.context.file.original_content_type
elif self.has_local_file:
return self.file.contentType

@property
def has_image(self):
return self.image is not None
Expand Down
10 changes: 10 additions & 0 deletions castle/cms/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ def test_move_file_private(self):
self.assertTrue(hasattr(fileOb.file, 'original_size'))
self.assertTrue(hasattr(fileOb.file, 'original_content_type'))

# after move, it should still have values in original attributes
# which should have the same values as the original attributes
self.assertEqual(fileOb.file.file_length, fileOb.file.original_size)
self.assertEqual(fileOb.file.file_type, fileOb.file.original_content_type)

# after move, there should be annotations on the object
annotations = IAnnotations(fileOb)
url = annotations[aws.STORAGE_KEY].get('url', None)
Expand Down Expand Up @@ -177,6 +182,11 @@ def test_move_file_public(self):
self.assertFalse(hasattr(fileOb.file, 'original_size'))
self.assertFalse(hasattr(fileOb.file, 'original_content_type'))

# after move, it should still have values in original attributes
# which should have the same values as the original attributes
self.assertEqual(fileOb.file.file_length, fileOb.file.original_size)
self.assertEqual(fileOb.file.file_type, fileOb.file.original_content_type)

# before move, there should be no annotations
annotations = IAnnotations(fileOb)
self.assertIsNone(annotations.get(aws.STORAGE_KEY, None))
Expand Down
14 changes: 14 additions & 0 deletions castle/cms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,20 @@ class UploadNamedFileWidget(NamedFileWidget):
klass = NamedFileWidget.klass + ' pat-upload-update'
replacement = False

@property
def file_content_type(self):
try:
return super(UploadNamedFileWidget, self).file_content_type
except Exception:
return None

@property
def file_icon(self):
try:
return super(UploadNamedFileWidget, self).file_icon
except Exception:
return None

@property
def pattern_options(self):
return json.dumps({
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def read(*rnames):
name='castle.cms',
description='CastleCMS Plone distribution main package',
long_description_content_type='text/x-rst',
version='3.0.0b142.dev0',
version='3.0.0b145.dev0',
long_description='%s\n%s' % (
read('README.rst'),
read('CHANGES.md')
Expand Down

0 comments on commit dda18ea

Please sign in to comment.