Commit 3b8c1195 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_hr: get correct document's creator

parent d1d8479f
from erp5.component.module.DateUtils import addToDate from cStringIO import StringIO
import zipfile
import re
from DateTime import DateTime from DateTime import DateTime
requester = None requester = None
if not first_name or not last_name: if not first_name or not last_name:
...@@ -22,6 +24,19 @@ if link: ...@@ -22,6 +24,19 @@ if link:
if requester.default_link.getUrlString() != link: if requester.default_link.getUrlString() != link:
requester.default_link.edit(url_string=link) requester.default_link.edit(url_string=link)
def getGenerator(text_document):
zipbuffer = StringIO(str(text_document.getData()))
zipfileobj = zipfile.ZipFile(zipbuffer)
try:
meta = zipfileobj.read('meta.xml')
generator_list = re.findall('<meta:generator>.*?</meta:generator>', meta)
if generator_list:
generator = generator_list[0]
return generator[len('<meta:generator>') : len(generator) - len('</meta:generator>')]
return ''
except KeyError:
return ''
position_application = context.position_application_module.newContent( position_application = context.position_application_module.newContent(
portal_type='Position Application', portal_type='Position Application',
destination_decision_value = requester, destination_decision_value = requester,
...@@ -86,6 +101,17 @@ for line in listbox: ...@@ -86,6 +101,17 @@ for line in listbox:
} }
document = context.Base_contribute(**document_kw) document = context.Base_contribute(**document_kw)
content_information = document.getContentInformation() content_information = document.getContentInformation()
# text is converted by cloudooo, so creator is changed to LibreOffice
# check content type
if document.getPortalType() == 'Text':
content_type = document.getContentTypeFromContent()
if content_type.endswith('msword'):
content_information['Creator'] = 'Microsoft Word'
else:
generator = getGenerator(document)
if generator:
content_information['Creator'] = generator
creator = content_information.pop('Creator', content_information.pop('Generator', None)) creator = content_information.pop('Creator', content_information.pop('Generator', None))
document_type = line['document_type'] document_type = line['document_type']
description=document_type description=document_type
......
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