diff --git a/castle/cms/syndication.py b/castle/cms/syndication.py index 67691b565..bd9ec8e01 100644 --- a/castle/cms/syndication.py +++ b/castle/cms/syndication.py @@ -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 @@ -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 diff --git a/castle/cms/tests/test_files.py b/castle/cms/tests/test_files.py index 6728f7e50..62a7354a8 100644 --- a/castle/cms/tests/test_files.py +++ b/castle/cms/tests/test_files.py @@ -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) @@ -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))