Commit bef3c525 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

use Ticket_getResourceItemList to avoid code duplication.

parent beed75df
...@@ -55,40 +55,7 @@ This script returns the list of items based on the preferred\n ...@@ -55,40 +55,7 @@ This script returns the list of items based on the preferred\n
resources for events. It is intended to be used\n resources for events. It is intended to be used\n
by ListField instances.\n by ListField instances.\n
"""\n """\n
from zExceptions import Unauthorized\n return context.Ticket_getResourceItemList(portal_type=\'Event\')\n
from Products.ERP5Type.Cache import CachingMethod\n
portal = context.getPortalObject()\n
\n
sql_kw = {\'portal_type\': portal.getPortalResourceTypeList(),\n
\'use_uid\': portal.portal_categories.getCategoryUid(portal.portal_preferences.getPreferredEventUse(), base_category=\'use\'),\n
\'validation_state\': \'validated\',\n
\'sort_on\': \'title\'}\n
\n
def getResourceItemList():\n
return [(\'\', \'\')] + [(result.getTitle(), result.getRelativeUrl()) for result in portal.portal_catalog(**sql_kw)]\n
\n
getResourceItemList = CachingMethod(getResourceItemList, \n
id=(script.id, context.Localizer.get_selected_language()), \n
cache_factory=\'erp5_ui_long\')\n
\n
result_list = getResourceItemList()[:]\n
\n
# BBB returns actual value in list field\n
if context.getResource() and context.getResource() not in [result[1] for result in result_list]:\n
try:\n
resource_value = portal.portal_categories.getCategoryValue(context.getResource(), base_category=\'resource\')\n
if resource_value is not None:\n
if resource_value.getPortalType() == \'Category\':\n
category_relative_url = resource_value.getCategoryRelativeUrl()\n
category_title = resource_value.getTranslatedTitle()\n
else:\n
category_relative_url = resource_value.getRelativeUrl()\n
category_title = resource_value.getTitle()\n
result_list.append((category_title, category_relative_url))\n
except Unauthorized:\n
pass\n
\n
return result_list\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
595 596
\ 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