Commit c9470194 authored by Ivan Tyagov's avatar Ivan Tyagov

Check if text exists before trying to get a random excerpt from it.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25254 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ab68991e
...@@ -66,11 +66,12 @@ is_gadget_mode = context.REQUEST.get(\'is_gadget_mode\', 0)\n ...@@ -66,11 +66,12 @@ is_gadget_mode = context.REQUEST.get(\'is_gadget_mode\', 0)\n
\n \n
def getRandomDocumentTextExcerpt():\n def getRandomDocumentTextExcerpt():\n
# try to get somewhat arbitrary choice of searchable attrs\n # try to get somewhat arbitrary choice of searchable attrs\n
start = min(len(document_text) - 300, 200)\n if isinstance(document_text, str) and document_text!=\'\':\n
if is_gadget_mode:\n start = min(len(document_text) - 300, 200)\n
# in gadget mode less space is available thus show less text\n if is_gadget_mode:\n
max_text_length = 100\n # in gadget mode less space is available thus show less text\n
return \'%s ...\' %document_text[start:start + max_text_length]\n max_text_length = 100\n
return \'%s ...\' %document_text[start:start + max_text_length]\n
\n \n
# get search words from listbox selection\n # get search words from listbox selection\n
argument_names = (\'advanced_search_text\', \n argument_names = (\'advanced_search_text\', \n
...@@ -83,7 +84,6 @@ argument_names = (\'advanced_search_text\', \n ...@@ -83,7 +84,6 @@ argument_names = (\'advanced_search_text\', \n
\n \n
if document_text is None:\n if document_text is None:\n
# convert object to text (if possible)\n # convert object to text (if possible)\n
document_text = \'\'\n
if getattr(context, \'asText\', None) is not None and \\\n if getattr(context, \'asText\', None) is not None and \\\n
getattr(context, \'hasBaseData\', None) is not None:\n getattr(context, \'hasBaseData\', None) is not None:\n
if context.hasBaseData():\n if context.hasBaseData():\n
...@@ -108,7 +108,7 @@ if search_string.strip() == \'\':\n ...@@ -108,7 +108,7 @@ if search_string.strip() == \'\':\n
return getRandomDocumentTextExcerpt()\n return getRandomDocumentTextExcerpt()\n
\n \n
search_argument_list = context.Base_parseSearchString(search_string)\n search_argument_list = context.Base_parseSearchString(search_string)\n
search_words = search_argument_list.get(\'searchabletext\')\n search_words = search_argument_list.get(\'searchabletext\', None)\n
\n \n
if search_words in (\'\', None,):\n if search_words in (\'\', None,):\n
# the searched words are empty (e.g. because we used only parameters \n # the searched words are empty (e.g. because we used only parameters \n
......
950 952
\ No newline at end of file \ No newline at end of file
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