Commit 62bb685c authored by Bartek Górny's avatar Bartek Górny

made function naming consistent; quit mime type in favour of content type;...

made function naming consistent; quit mime type in favour of content type; renamed old lines and logs;

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10551 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 68154868
...@@ -47,7 +47,6 @@ dec=base64.decodestring ...@@ -47,7 +47,6 @@ dec=base64.decodestring
class ConvertionError(Exception):pass class ConvertionError(Exception):pass
#class OOoDocument(File):
class OOoDocument(DMSFile, CachingMixin): class OOoDocument(DMSFile, CachingMixin):
""" """
A file document able to convert OOo compatible files to A file document able to convert OOo compatible files to
...@@ -114,10 +113,7 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -114,10 +113,7 @@ class OOoDocument(DMSFile, CachingMixin):
searchable_attrs=DMSFile.searchable_attrs+('text_content',) # XXX - good idea - should'n this be made more general ? searchable_attrs=DMSFile.searchable_attrs+('text_content',) # XXX - good idea - should'n this be made more general ?
def _getServerCoordinates(self): # XXX - Naming - should be _getServerCoordinate or _getServerCoordinateList def _getServerCoordinate(self):
# the reason why plural is not so good is because one never
# knows is plural returns a count (ie. the server has 3 coordinates)
# or if plural returns a list
""" """
Returns OOo conversion server data from Returns OOo conversion server data from
preferences preferences
...@@ -130,7 +126,7 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -130,7 +126,7 @@ class OOoDocument(DMSFile, CachingMixin):
return adr,nr return adr,nr
def _mkProxy(self): def _mkProxy(self):
sp=xmlrpclib.ServerProxy('http://%s:%d' % self._getServerCoordinates(),allow_none=True) sp=xmlrpclib.ServerProxy('http://%s:%d' % self._getServerCoordinate(),allow_none=True)
return sp return sp
def returnMessage(self,msg,code=0): def returnMessage(self,msg,code=0):
...@@ -148,13 +144,12 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -148,13 +144,12 @@ class OOoDocument(DMSFile, CachingMixin):
communicates with the conversion server communicates with the conversion server
and gets converted file as well as metadata and gets converted file as well as metadata
""" """
if force==0 and self.hasOOfile(): if force==0 and self.hasOOFile():
return self.returnMessage('OOo file is up do date',1) return self.returnMessage('OOo file is up do date',1)
try: try:
self._convert() self._convert()
except xmlrpclib.Fault,e: except xmlrpclib.Fault,e:
return self.returnMessage('Problem: %s' % str(e),2) return self.returnMessage('Problem: %s' % str(e),2)
#self.setLastConvertTime(DateTime())
return self.returnMessage('converted') return self.returnMessage('converted')
security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList') security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList')
...@@ -167,15 +162,15 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -167,15 +162,15 @@ class OOoDocument(DMSFile, CachingMixin):
XXX - what does this mean? I don't understand XXX - what does this mean? I don't understand
""" """
# Caching method implementation # Caching method implementation
def cached_getTargetFormatItemList(mimetype): def cached_getTargetFormatItemList(content_type):
sp=self._mkProxy() sp=self._mkProxy()
allowed=sp.getAllowedTargets(mimetype) allowed=sp.getAllowedTargets(content_type)
return [[y,x] for x,y in allowed] # have to reverse tuple order return [[y,x] for x,y in allowed] # have to reverse tuple order
cached_getTargetFormatItemList = CachingMethod(cached_getTargetFormatItemList, cached_getTargetFormatItemList = CachingMethod(cached_getTargetFormatItemList,
id = "OOoDocument_getTargetFormatItemList" ) id = "OOoDocument_getTargetFormatItemList" )
return cached_getTargetFormatItemList(self.getMimeType()) return cached_getTargetFormatItemList(self.getContentType())
security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList') security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList')
...@@ -191,7 +186,7 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -191,7 +186,7 @@ class OOoDocument(DMSFile, CachingMixin):
self.clearCache() self.clearCache()
self.oo_data=None self.oo_data=None
m=self.returnMessage('new') m=self.returnMessage('new')
self.setStatusMessage(str(m[1])) self.setExternalProcessingStatusMessage(str(m[1]))
security.declareProtected(Permissions.ModifyPortalContent,'isAllowed') security.declareProtected(Permissions.ModifyPortalContent,'isAllowed')
def isAllowed(self, format): def isAllowed(self, format):
...@@ -200,9 +195,8 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -200,9 +195,8 @@ class OOoDocument(DMSFile, CachingMixin):
into the specified format. into the specified format.
""" """
if not self.hasOOfile(): return False if not self.hasOOFile(): return False
allowed=self.getTargetFormatItemList() allowed=self.getTargetFormatItemList()
#self.log('allowed',allowed)
if allowed is None: return False if allowed is None: return False
return (format in [x[1] for x in allowed]) return (format in [x[1] for x in allowed])
...@@ -213,10 +207,8 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -213,10 +207,8 @@ class OOoDocument(DMSFile, CachingMixin):
based on the values provided by the user. This is implemented based on the values provided by the user. This is implemented
through the invocation of the conversion server. through the invocation of the conversion server.
""" """
#self.log('editMetadata',newmeta)
sp=self._mkProxy() sp=self._mkProxy()
kw=sp.run_setmetadata(self.getTitle(),enc(self._unpackData(self.oo_data)),newmeta) kw=sp.run_setmetadata(self.getTitle(),enc(self._unpackData(self.oo_data)),newmeta)
#self.log('res editMetadata',meta)
self.oo_data=Pdata(dec(kw['data'])) self.oo_data=Pdata(dec(kw['data']))
self._setMetaData(kw['meta']) self._setMetaData(kw['meta'])
return True # XXX why return ? - why not? return True # XXX why return ? - why not?
...@@ -229,7 +221,6 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -229,7 +221,6 @@ class OOoDocument(DMSFile, CachingMixin):
on the object. Update metadata information. on the object. Update metadata information.
""" """
sp=self._mkProxy() sp=self._mkProxy()
#self.log('_convert',enc(self._unpackData(self.data))[:500])
kw=sp.run_convert(self.getSourceReference(),enc(self._unpackData(self.data))) kw=sp.run_convert(self.getSourceReference(),enc(self._unpackData(self.data)))
self.oo_data=Pdata(dec(kw['data'])) self.oo_data=Pdata(dec(kw['data']))
# now we get text content # now we get text content
...@@ -266,21 +257,18 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -266,21 +257,18 @@ class OOoDocument(DMSFile, CachingMixin):
(user fields are so useful actually...) (user fields are so useful actually...)
XXX - I think it does (BG) XXX - I think it does (BG)
""" """
#self.log('meta',meta)
for k,v in meta.items(): for k,v in meta.items():
meta[k]=v.encode('utf-8') meta[k]=v.encode('utf-8')
#self.log('meta',meta)
self.setTitle(meta.get('title','')) self.setTitle(meta.get('title',''))
self.setSubject(meta.get('keywords','').split()) self.setSubject(meta.get('keywords','').split())
self.setDescription(meta.get('description','')) self.setDescription(meta.get('description',''))
#self.setLanguage(meta.get('language','')) #self.setLanguage(meta.get('language',''))
if meta.get('MIMEType',False): if meta.get('MIMEType',False):
self.setMimeType(meta['MIMEType']) self.setContentType(meta['MIMEType'])
#self.setReference(meta.get('reference','')) #self.setReference(meta.get('reference',''))
#security.declareProtected(Permissions.View,'getOOfile') security.declareProtected(Permissions.View,'getOOFile')
def getOOfile(self): # We must be consistent - OOoDocument and OOoFile is OK def getOOFile(self):
# XXX OODocument and OOFile is OK
""" """
Return the converted OOo document. Return the converted OOo document.
...@@ -291,9 +279,8 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -291,9 +279,8 @@ class OOoDocument(DMSFile, CachingMixin):
data=self.oo_data data=self.oo_data
return data return data
security.declareProtected(Permissions.View,'hasOOfile') security.declareProtected(Permissions.View,'hasOOFile')
def hasOOfile(self): # We must be consistent - OOoDocument and OOoFile is OK def hasOOFile(self):
# XXX OODocument and OOFile is OK
""" """
Checks whether we have an OOo converted file Checks whether we have an OOo converted file
""" """
...@@ -418,7 +405,7 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -418,7 +405,7 @@ class OOoDocument(DMSFile, CachingMixin):
if REQUEST is not None: if REQUEST is not None:
return self.returnMessage(errstr) return self.returnMessage(errstr)
raise ConvertionError(errstr) raise ConvertionError(errstr)
if not self.hasOOfile(): if not self.hasOOFile():
if REQUEST is not None: if REQUEST is not None:
return self.returnMessage('needs conversion') return self.returnMessage('needs conversion')
raise ConvertionError('needs conversion') raise ConvertionError('needs conversion')
...@@ -448,7 +435,6 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -448,7 +435,6 @@ class OOoDocument(DMSFile, CachingMixin):
# real version: # real version:
sp=self._mkProxy() sp=self._mkProxy()
kw=sp.run_generate(self.getSourceReference(),enc(self._unpackData(self.oo_data)),None,format) kw=sp.run_generate(self.getSourceReference(),enc(self._unpackData(self.oo_data)),None,format)
#self.log('_makeFile',mime)
return kw['mime'],Pdata(dec(kw['data'])) return kw['mime'],Pdata(dec(kw['data']))
# make sure to call the right edit methods # make sure to call the right edit methods
......
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