Commit 986c3404 authored by Nicolas Delaby's avatar Nicolas Delaby

small refactoring:

  * call getToolByName with portal_object to avoid acquisitions loockup
  * remove calls of clearConversionCache
  * follow naming convention res => result_list, ob => document


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34880 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 079465b5
...@@ -745,7 +745,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -745,7 +745,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
""" """
if not self.getReference(): if not self.getReference():
return self return self
catalog = getToolByName(self, 'portal_catalog') catalog = getToolByName(self.getPortalObject(), 'portal_catalog')
kw = dict(reference=self.getReference(), sort_on=(('version','descending'),)) kw = dict(reference=self.getReference(), sort_on=(('version','descending'),))
if language is not None: if language is not None:
kw['language'] = language kw['language'] = language
...@@ -757,25 +757,26 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -757,25 +757,26 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
# if language was given return it (if there are any docs in this language) # if language was given return it (if there are any docs in this language)
if language is not None: if language is not None:
try: try:
return res[0].getObject() return result_list[0].getObject()
except IndexError: except IndexError:
return None return None
else: else:
first = res[0] first = result_list[0].getObject()
in_original = None in_original = None
for ob in res: for record in result_list:
if ob.getVersion() != first.getVersion(): document = record.getObject()
if document.getVersion() != first.getVersion():
# we are out of the latest version - return in_original or first # we are out of the latest version - return in_original or first
if in_original is not None: if in_original is not None:
return in_original.getObject() return in_original
else: else:
return first.getObject() # this shouldn't happen in real life return first # this shouldn't happen in real life
if ob.getLanguage() == user_language: if document.getLanguage() == user_language:
# we found it in the user language # we found it in the user language
return ob.getObject() return document
if ob.getLanguage() == original_language: if document.getLanguage() == original_language:
# this is in original language # this is in original language
in_original = ob in_original = document
# this is the only doc in this version # this is the only doc in this version
return self return self
...@@ -785,7 +786,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -785,7 +786,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
Returns a list of documents with same reference, same portal_type Returns a list of documents with same reference, same portal_type
but different version and given language or any language if not given. but different version and given language or any language if not given.
""" """
catalog = getToolByName(self, 'portal_catalog') catalog = getToolByName(self.getPortalObject(), 'portal_catalog')
kw = dict(portal_type=self.getPortalType(), kw = dict(portal_type=self.getPortalType(),
reference=self.getReference(), reference=self.getReference(),
sort_on=(('version', 'descending', 'SIGNED'),) sort_on=(('version', 'descending', 'SIGNED'),)
...@@ -805,7 +806,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -805,7 +806,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
""" """
if not self.getReference(): if not self.getReference():
return True return True
catalog = getToolByName(self, 'portal_catalog') catalog = getToolByName(self.getPortalObject(), 'portal_catalog')
self_count = catalog.unrestrictedCountResults(portal_type=self.getPortalDocumentTypeList(), self_count = catalog.unrestrictedCountResults(portal_type=self.getPortalDocumentTypeList(),
reference=self.getReference(), reference=self.getReference(),
version=self.getVersion(), version=self.getVersion(),
...@@ -830,13 +831,13 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -830,13 +831,13 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
in order to be consistent with the property sheet in order to be consistent with the property sheet
definition. definition.
""" """
getInfoFor = getToolByName(self, 'portal_workflow').getInfoFor getInfoFor = getToolByName(self.getPortalObject(),
'portal_workflow').getInfoFor
revision = len(getInfoFor(self, 'history', (), 'edit_workflow')) revision = len(getInfoFor(self, 'history', (), 'edit_workflow'))
# XXX Also look at processing_status_workflow for compatibility. # XXX Also look at processing_status_workflow for compatibility.
for history_item in getInfoFor(self, 'history', (), revision += len([history_item for history_item in\
'processing_status_workflow'): getInfoFor(self, 'history', (), 'processing_status_workflow')\
if history_item.get('action') == 'edit': if history_item.get('action') == 'edit'])
revision += 1
return str(revision) return str(revision)
security.declareProtected(Permissions.AccessContentsInformation, 'getRevisionList') security.declareProtected(Permissions.AccessContentsInformation, 'getRevisionList')
...@@ -868,7 +869,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -868,7 +869,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
finishIngestion. finishIngestion.
""" """
document = self document = self
catalog = getToolByName(self, 'portal_catalog') catalog = getToolByName(self.getPortalObject(), 'portal_catalog')
if self.getReference(): if self.getReference():
# Find all document with same (reference, version, language) # Find all document with same (reference, version, language)
kw = dict(portal_type=self.getPortalDocumentTypeList(), kw = dict(portal_type=self.getPortalDocumentTypeList(),
...@@ -914,7 +915,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -914,7 +915,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
for the current user. for the current user.
""" """
if not self.getReference(): return [] if not self.getReference(): return []
catalog = getToolByName(self, 'portal_catalog') catalog = getToolByName(self.getPortalObject(), 'portal_catalog')
kw = dict(portal_type=self.getPortalType(), kw = dict(portal_type=self.getPortalType(),
reference=self.getReference(), reference=self.getReference(),
group_by=('language',)) group_by=('language',))
...@@ -936,7 +937,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -936,7 +937,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
reference = self.getReference() reference = self.getReference()
if not reference: if not reference:
return return
catalog = getToolByName(self, 'portal_catalog') catalog = getToolByName(self.getPortalObject(), 'portal_catalog')
res = catalog(reference=self.getReference(), sort_on=(('creation_date','ascending'),)) res = catalog(reference=self.getReference(), sort_on=(('creation_date','ascending'),))
# XXX this should be security-unaware - delegate to script with proxy roles # XXX this should be security-unaware - delegate to script with proxy roles
return res[0].getLanguage() # XXX what happens if it is empty? return res[0].getLanguage() # XXX what happens if it is empty?
...@@ -1232,7 +1233,6 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -1232,7 +1233,6 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
return return
try: try:
message = self._convertToBaseFormat() # Call implemetation method message = self._convertToBaseFormat() # Call implemetation method
self.clearConversionCache() # Conversion cache is now invalid
if message is None: if message is None:
# XXX Need to translate. # XXX Need to translate.
message = 'Converted to %s.' % self.getBaseContentType() message = 'Converted to %s.' % self.getBaseContentType()
......
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