Commit fb18134d authored by Kevin Deldycke's avatar Kevin Deldycke

WebSite_getDocumentValue returns the newest Version of a Document if it

is called with a reference (name parameter).

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9585 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b33b5f0a
...@@ -88,6 +88,9 @@ ...@@ -88,6 +88,9 @@
#\n #\n
# NOTE: portal param probably useless\n # NOTE: portal param probably useless\n
\n \n
# Use the following Variable to determine which\n
# \n
\n
portal_catalog = portal.portal_catalog\n portal_catalog = portal.portal_catalog\n
\n \n
if name is None:\n if name is None:\n
...@@ -100,19 +103,31 @@ if name is None:\n ...@@ -100,19 +103,31 @@ if name is None:\n
\n \n
#If name is not None, it has to be searched for it in the catalog.\n #If name is not None, it has to be searched for it in the catalog.\n
\n \n
# This Function helps do sort different Versions of the same Document.\n
def compareVersion(c1, c2):\n
c1_value = c1.getObject() \n
c2_value = c2.getObject()\n
return cmp(c2_value.getVersion(), c1_value.getVersion()) \n
\n
#from Products.ERP5Type.Cache import CachingMethod\n #from Products.ERP5Type.Cache import CachingMethod\n
def getDocument(name):\n def getDocument(name):\n
# First try to get a published document\n # First try to get a published document\n
matching_document_list = portal_catalog(reference = \'%s\' % name, validation_state=\'published\')\n matching_document_list = portal_catalog(reference = \'%s\' % name, validation_state=\'published\')\n
if len(matching_document_list):\n if len(matching_document_list):\n
matching_document_list=list(matching_document_list)\n
matching_document_list.sort(compareVersion)\n
return matching_document_list[0].getObject()\n return matching_document_list[0].getObject()\n
# Then try to get a validated document (Product)\n # Then try to get a validated document (Product)\n
matching_document_list = portal_catalog(reference = \'%s\' % name, validation_state=\'validated\')\n matching_document_list = portal_catalog(reference = \'%s\' % name, validation_state=\'validated\')\n
if len(matching_document_list):\n if len(matching_document_list):\n
matching_document_list=list(matching_document_list)\n
matching_document_list.sort(compareVersion)\n
return matching_document_list[0].getObject()\n return matching_document_list[0].getObject()\n
# Then try to get any document\n # Then try to get any document\n
matching_document_list = portal_catalog(reference = \'%s\' % name)\n matching_document_list = portal_catalog(reference = \'%s\' % name)\n
if len(matching_document_list):\n if len(matching_document_list):\n
matching_document_list=list(matching_document_list)\n
matching_document_list.sort(compareVersion)\n
return matching_document_list[0].getObject()\n return matching_document_list[0].getObject()\n
return None \n return None \n
\n \n
...@@ -171,6 +186,7 @@ return getDocument(name)\n ...@@ -171,6 +186,7 @@ return getDocument(name)\n
<string>portal_catalog</string> <string>portal_catalog</string>
<string>None</string> <string>None</string>
<string>context</string> <string>context</string>
<string>compareVersion</string>
<string>getDocument</string> <string>getDocument</string>
</tuple> </tuple>
</value> </value>
......
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