Commit 274ea0b4 authored by Jérome Perrin's avatar Jérome Perrin

small style changes


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34768 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a98a72b9
...@@ -784,13 +784,15 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -784,13 +784,15 @@ 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', None) catalog = getToolByName(self, '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'),)
) )
if version: kw['version'] = version if version:
if language: kw['language'] = language kw['version'] = version
if language:
kw['language'] = language
return catalog(**kw) return catalog(**kw)
security.declareProtected(Permissions.AccessContentsInformation, 'isVersionUnique') security.declareProtected(Permissions.AccessContentsInformation, 'isVersionUnique')
...@@ -801,8 +803,8 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -801,8 +803,8 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
document has no reference. document has no reference.
""" """
if not self.getReference(): if not self.getReference():
return 1 return True
catalog = getToolByName(self, 'portal_catalog', None) catalog = getToolByName(self, '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(),
...@@ -865,21 +867,22 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -865,21 +867,22 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S
finishIngestion. finishIngestion.
""" """
document = self document = self
catalog = getToolByName(self, 'portal_catalog', None) catalog = getToolByName(self, '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(),
reference=self.getReference(), reference=self.getReference(),
where_expression=SQLQuery("validation_state NOT IN ('cancelled', 'deleted')")) where_expression=SQLQuery("validation_state NOT IN ('cancelled', 'deleted')"))
if self.getVersion(): kw['version'] = self.getVersion() if self.getVersion():
if self.getLanguage(): kw['language'] = self.getLanguage() kw['version'] = self.getVersion()
if self.getLanguage():
kw['language'] = self.getLanguage()
document_list = catalog.unrestrictedSearchResults(**kw) document_list = catalog.unrestrictedSearchResults(**kw)
existing_document = None existing_document = None
# Select the first one which is not self and which # Select the first one which is not self and which
# shares the same coordinates # shares the same coordinates
document_list = list(document_list) document_list = list(document_list)
document_list.sort(key=lambda x: x.getId()) document_list.sort(key=lambda x: x.getId())
#LOG('[DMS] Existing documents for %s' %self.getSourceReference(), INFO, len(document_list))
for o in document_list: for o in document_list:
if o.getRelativeUrl() != self.getRelativeUrl() and\ if o.getRelativeUrl() != self.getRelativeUrl() and\
o.getVersion() == self.getVersion() and\ o.getVersion() == self.getVersion() and\
...@@ -910,10 +913,10 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -910,10 +913,10 @@ 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', None) catalog = getToolByName(self, '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',))
if version is not None: if version is not None:
kw['version'] = version kw['version'] = version
return map(lambda o:o.getLanguage(), catalog(**kw)) return map(lambda o:o.getLanguage(), catalog(**kw))
...@@ -932,7 +935,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, CachedConvertableMixin, S ...@@ -932,7 +935,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', None) catalog = getToolByName(self, '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?
......
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