Commit e81d427d authored by Sebastien Robin's avatar Sebastien Robin

fixed Document_getStandardFileName, previously it was able to

return something like foo.pdf-001-en instead of foo-001-en.pdf

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35915 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4d9447fe
......@@ -67,16 +67,17 @@ elif context.hasSourceReference():\n
file_name = context.getSourceReference()\n
else:\n
file_name = context.getTitleOrId()\n
if \'.\' in file_name and format:\n
original_extension = None\n
if \'.\' in file_name:\n
# delete actual extension if dot inside string and new format\n
# is provided\n
file_name = \'.\'.join(file_name.split(\'.\')[:-1])\n
file_name, original_extension = file_name.rsplit(\'.\', 1)\n
if context.getVersion():\n
file_name = \'%s-%s\' % (file_name, context.getVersion(),)\n
if context.getLanguage():\n
file_name = \'%s-%s\' % (file_name, context.getLanguage(),)\n
if format:\n
file_name = \'%s.%s\' % (file_name, format,)\n
if format or original_extension:\n
file_name = \'%s.%s\' % (file_name, format or original_extension,)\n
return file_name\n
</string> </value>
</item>
......@@ -118,7 +119,9 @@ return file_name\n
<string>_getattr_</string>
<string>context</string>
<string>file_name</string>
<string>_getitem_</string>
<string>None</string>
<string>original_extension</string>
<string>_getiter_</string>
</tuple>
</value>
</item>
......
......@@ -1235,6 +1235,21 @@ class TestDocument(TestDocumentMixin):
document.edit(file=upload_file)
self.assertEquals('application/pdf', document.getContentType())
def test_Document_getStandardFileName(self):
upload_file = makeFileUpload('metadata.pdf')
document = self.portal.document_module.newContent(portal_type='PDF')
# Here we use edit instead of setFile,
# because only edit method set filename as source_reference.
document.edit(file=upload_file)
self.assertEquals(document.getStandardFileName(), 'metadata.pdf')
self.assertEquals(document.getStandardFileName(format='png'),
'metadata.png')
document.setVersion('001')
document.setLanguage('en')
self.assertEquals(document.getStandardFileName(), 'metadata-001-en.pdf')
self.assertEquals(document.getStandardFileName(format='png'),
'metadata-001-en.png')
def test_CMYKImageTextContent(self):
upload_file = makeFileUpload('cmyk_sample.jpg')
document = self.portal.portal_contributions.newContent(file=upload_file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment