Commit 2ef1dd35 authored by Ivan Tyagov's avatar Ivan Tyagov

Search for documents which reference us only if our reference itself is

following format defined in system preference level.
parent a4011582
...@@ -58,7 +58,8 @@ and make sure we get latest/most relevant version\n ...@@ -58,7 +58,8 @@ and make sure we get latest/most relevant version\n
should be reimplemented in SQL some sunny day.\n should be reimplemented in SQL some sunny day.\n
"""\n """\n
reference = context.getReference()\n reference = context.getReference()\n
if reference is None:\n if reference is None or not context.isSearchableReference():\n
# empty or not following format preference\n
return ()\n return ()\n
\n \n
return context.Base_zGetImplicitPredecessorValueList(reference=reference)\n return context.Base_zGetImplicitPredecessorValueList(reference=reference)\n
......
1269 1270
\ No newline at end of file \ No newline at end of file
...@@ -317,6 +317,22 @@ class Document(DocumentExtensibleTraversableMixin, XMLObject, UrlMixin, ...@@ -317,6 +317,22 @@ class Document(DocumentExtensibleTraversableMixin, XMLObject, UrlMixin,
preferences. preferences.
""" """
text = self.getSearchableText() # XXX getSearchableText or asText ? text = self.getSearchableText() # XXX getSearchableText or asText ?
return self._getSearchableReferenceList(text)
security.declareProtected(Permissions.AccessContentsInformation, 'getSearchableReferenceList')
def isSearchableReference(self):
"""
Determine if current document's reference can be used for searching - i.e. follows
certain defined at system level preferences format.
"""
reference = self.getReference()
return len(self._getSearchableReferenceList(reference))
def _getSearchableReferenceList(self, text):
"""
Extract all reference alike strings from text using for that a
regular expression defined at system level preferences.
"""
regexp = self.portal_preferences.getPreferredDocumentReferenceRegularExpression() regexp = self.portal_preferences.getPreferredDocumentReferenceRegularExpression()
try: try:
rx_search = re.compile(regexp) rx_search = re.compile(regexp)
......
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