<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </value>
        </item>
        <item>
            <key> <string>_bind_names</string> </key>
            <value>
              <object>
                <klass>
                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
                </klass>
                <tuple/>
                <state>
                  <dictionary>
                    <item>
                        <key> <string>_asgns</string> </key>
                        <value>
                          <dictionary>
                            <item>
                                <key> <string>name_container</string> </key>
                                <value> <string>container</string> </value>
                            </item>
                            <item>
                                <key> <string>name_context</string> </key>
                                <value> <string>context</string> </value>
                            </item>
                            <item>
                                <key> <string>name_m_self</string> </key>
                                <value> <string>script</string> </value>
                            </item>
                            <item>
                                <key> <string>name_subpath</string> </key>
                                <value> <string>traverse_subpath</string> </value>
                            </item>
                          </dictionary>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>_body</string> </key>
            <value> <string>order = state_change[\'object\']\n
portal = order.getPortalObject()\n
\n
setup_service_relative_url = order.portal_preferences.getPreferredInstanceSetupResource()\n
isTransitionPossible = portal.portal_workflow.isTransitionPossible\n
\n
for order_line in order.getMovementList():\n
  if order_line.getResource() == setup_service_relative_url:\n
    computer_partition = order_line.getAggregateValue(portal_type="Computer Partition")\n
    if computer_partition is None:\n
      software_release = order_line.getAggregateValue(portal_type="Software Release")\n
      software_instance = order_line.getAggregateValue(portal_type="Software Instance")\n
\n
      computer_partition = None\n
     \n
      # XXX Duplicated from request method...\n
\n
      query_kw = {\n
        \'software_release_url\': software_release.getUrlString(),\n
        \'portal_type\': \'Computer Partition\',\n
#         \'relative_url\': \'computer_module/20110126-E2AE/%\',\n
        \'free_for_request\': 1,\n
      }\n
\n
      result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n
      offset = max(0, result_count-1)\n
\n
      for computer_partition_candidate in portal.portal_catalog(\n
                                               limit=(random.randint(0, offset), 50), **query_kw):\n
        computer_partition_candidate = computer_partition_candidate.getObject()\n
        # Check if the computer partition can be marked as busy (done by an interaction workflow on sale packing list level)\n
        if isTransitionPossible(computer_partition_candidate, \'mark_busy\'):\n
          computer_partition = computer_partition_candidate\n
          break\n
\n
      if computer_partition is None:\n
        raise ValueError(\'It was not possible to find free Computer Partition\')\n
\n
      # lock computer partition\n
      computer_partition.serialize()\n
      computer_partition.markBusy()\n
\n
      order_line.edit(\n
        aggregate_list=order_line.getAggregateList()+[computer_partition.getRelativeUrl()])\n
</string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>state_change, **kw</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>Delivery_assignComputerPartition</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
