Commit 92a9c1ff authored by Bartek Górny's avatar Bartek Górny

filename stored as source_reference; setting properties from a parsed filename...

filename stored as source_reference; setting properties from a parsed filename using regexp from preferences;

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9479 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d3aba301
...@@ -158,7 +158,7 @@ class DMSFile(XMLObject,File): ...@@ -158,7 +158,7 @@ class DMSFile(XMLObject,File):
edit=File.edit edit=File.edit
searchable_attrs=('title','description','id','reference','version', searchable_attrs=('title','description','id','reference','version',
'short_title','keywords','subject','original_filename','source_project_title') 'short_title','keywords','subject','source_reference','source_project_title')
### Content indexing methods ### Content indexing methods
security.declareProtected(Permissions.View, 'getSearchableText') security.declareProtected(Permissions.View, 'getSearchableText')
...@@ -195,6 +195,20 @@ class DMSFile(XMLObject,File): ...@@ -195,6 +195,20 @@ class DMSFile(XMLObject,File):
self.content_type=content_type self.content_type=content_type
return content_type return content_type
security.declareProtected(Permissions.ModifyPortalContent, 'setPropertiesFromFilename')
def setPropertiesFromFilename(self,fname):
rx_parse=re.compile(self.portal_preferences.getPreferredDmsFilenameRegexp())
if rx_parse is None:
self.setReference(fname)
return
m=rx_parse.match(fname)
if m is None:
self.setReference(fname)
return
for k,v in m.groupdict().items():
self.setProperty(k,v)
# BG copied from File in case # BG copied from File in case
index_html = CMFFile.index_html index_html = CMFFile.index_html
......
...@@ -219,7 +219,7 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -219,7 +219,7 @@ class OOoDocument(DMSFile, CachingMixin):
""" """
sp=self._mkProxy() sp=self._mkProxy()
#self.log('_convert',enc(self._unpackData(self.data))[:500]) #self.log('_convert',enc(self._unpackData(self.data))[:500])
kw=sp.run_convert(self.getOriginalFilename(),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
text_data=self.extractTextContent() text_data=self.extractTextContent()
...@@ -266,7 +266,7 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -266,7 +266,7 @@ class OOoDocument(DMSFile, CachingMixin):
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.setMimeType(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): def getOOfile(self):
...@@ -285,8 +285,6 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -285,8 +285,6 @@ class OOoDocument(DMSFile, CachingMixin):
""" """
Checks whether we have an initial file Checks whether we have an initial file
""" """
print 'IS INSTANCE'
print isinstance(self,object)
_marker=[] _marker=[]
if getattr(self,'data',_marker) is not _marker: # XXX - use propertysheet accessors if getattr(self,'data',_marker) is not _marker: # XXX - use propertysheet accessors
return getattr(self,'data') is not None return getattr(self,'data') is not None
...@@ -458,7 +456,7 @@ class OOoDocument(DMSFile, CachingMixin): ...@@ -458,7 +456,7 @@ class OOoDocument(DMSFile, CachingMixin):
""" """
# real version: # real version:
sp=self._mkProxy() sp=self._mkProxy()
kw=sp.run_generate(self.getOriginalFilename(),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) #self.log('_makeFile',mime)
return kw['mime'],Pdata(dec(kw['data'])) return kw['mime'],Pdata(dec(kw['data']))
......
...@@ -31,10 +31,6 @@ class DMSFile: ...@@ -31,10 +31,6 @@ class DMSFile:
""" """
_properties = ( _properties = (
{ 'id' : 'original_filename',
'description' : 'name of the uploaded file',
'type' : 'string',
'mode' : '' },
) )
_categories = ('destination','similar','predecessor','successor','source_project','publication_section','classification', _categories = ('destination','similar','predecessor','successor','source_project','publication_section','classification',
......
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