# Script that installs wendelin configurator

import random
import string
import json

request = context.REQUEST
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog

status_code = 0
error_message = "No error."

# check erp5_wendelin_telecom_scalability_test business template is present
configurator = portal.business_configuration_module.wendelin_configuration
if configurator == None or not configurator.contentValues(portal_type='Configuration Save'):
  error_message = "Could not find the wendelin business configuration object. Be sure to have erp5_wendelin_telecom_scalability_test business template installed."
  return json.dumps({"status_code" : 1, "error_message": error_message })

# install configurator if not intalled
if configurator.getSimulationState() == "draft":
  try:
    configurator.buildConfiguration()
  except Exception as e:
    status_code = 1
    error_message = "Error during installation: " + str(e)
    return json.dumps({"status_code" : 1, "error_message": error_message })

return json.dumps({"status_code" : status_code, "error_message": error_message })
