Commit 984b96b4 authored by Xiaowu Zhang's avatar Xiaowu Zhang

ERP5Configurator&erp5_configurator: add check/fix existing site action

parent 8673af68
REQUEST = context.REQUEST
erp5_site_id = context.getPortalObject().getId()
js_string = """
// Initialisation
window.onload = init;
function getNewXMLHTTP() {
try {
return new XMLHttpRequest();
} catch(e) {
try {
var aObj = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
var aObj = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
return false;
}
}
}
return aObj;
}
function checkClientInstallation() {
time_out = window.setTimeout( "checkClientInstallation()", 5000 );
var xhr_object = null;
xhr_object = getNewXMLHTTP();
xhr_object.onreadystatechange = function()
{
var status = document.getElementById('client_installation_status');
if(xhr_object.readyState == 4)
{
if(xhr_object.status == 200)
{
status.innerHTML = xhr_object.responseText;
}
else
status.innerHTML = "Error code " + xhr_object.status;
};
}
active_process_id = document.querySelector('input[name="active_process_id"]').getAttribute('value')
xhr_object.open( "GET",
"portal_configurator/getCheckingStatusReport?active_process_id=" + active_process_id,
true);
//xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr_object.setRequestHeader("Content-Type", "text/html");
xhr_object.setRequestHeader("Cache-Control", "no-cache" )
xhr_object.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" )
xhr_object.send(null);
}
function init() {
checkClientInstallation();
}
"""
return js_string
<?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>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ConfiguratorTool_generateCheckingJavaScript</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Generate JavaScript code which will query wizard to get installation status</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<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_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ConfiguratorTool_viewCheckingResultRenderer</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<div>
<tal:block tal:condition="python: options.get('active_process_id') is not None">
<tal:block tal:define="result_list python: here.getPortalObject().portal_activities[options.get('active_process_id')].getResultList()">
<tal:block tal:condition="python: len(result_list)">
<ol>
<tal:block tal:repeat="result python: result_list[0].result">
<li tal:content="result"></li>
</tal:block>
</ol>
</tal:block>
</tal:block>
</tal:block>
</div>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<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_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ConfiguratorTool_viewCheckingStatus</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode>Installation Status Report Renderer</unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<tal:block tal:replace="nothing"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
</tal:block>
<tal:block metal:define-macro="master">
<tal:block
tal:define="object_uid here/getUid | nothing;
object_path here/getPath | nothing;
form nocall: form | nothing;
form_id form/id | nothing;
form_action python: form and form.action not in ('', None) and here.portal_membership.checkPermission('Modify portal content', here) and form.action or nothing;
local_parameter_list local_parameter_list | python: {};
dummy python: local_parameter_list.update({'object_uid': object_uid, 'object_path': object_path, 'form_id': form_id});
title string:${template/title_or_id} - ${here/Title};
">
<script type="text/javascript"
language="javascript"
tal:content="here/ConfiguratorTool_generateCheckingJavaScript"/>
<div id="client_installation_status"
style="background-color: #FFFFFF;
padding: 0.5em;
border-top: 1px solid #000000;
width: 480px;">
Loading ...
</div>
</tal:block>
</tal:block>
\ No newline at end of file
......@@ -45,6 +45,13 @@
<input type='hidden' name='field_your_business_configuration' tal:attributes='value python: request.get("business_configuration")'>
<tal:block tal:replace="structure python: options.get('form_html')" /> <br/>
<tal:block tal:condition="python: options.get('active_process_id') is not None">
<input type="hidden"
name="active_process_id"
value="active_process_id"
tal:attributes="value python: options.get('active_process_id')"/>
</tal:block>
<tal:block tal:condition="python: options.get('previous') is not None">
<input type="Submit"
value="Previous"
......
......@@ -34,11 +34,15 @@ from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Configurator.Tool.ConfiguratorTool import _validateFormToRequest
from Products.ERP5.Document.Item import Item
from Products.CMFActivity.ActiveResult import ActiveResult
## Workflow states definitions
INITIAL_STATE_TITLE = 'Start'
DOWNLOAD_STATE_TITLE = 'Download'
END_STATE_TITLE = 'End'
CHECK_EXISTING_SITE_STATE_TITLE = 'Check Existing Site'
FIX_EXISTING_SITE_STATE_TITLE = 'Fix Existing Site'
class BusinessConfiguration(Item):
"""
......@@ -87,6 +91,18 @@ class BusinessConfiguration(Item):
"""
return self.getCurrentStateTitle() == END_STATE_TITLE
security.declareProtected(Permissions.View, 'isCheckExistingSiteConfigurationState')
def isCheckExistingSiteConfigurationState(self):
""" Check if the Business Configuration is on check existing site State
"""
return self.getCurrentStateTitle() == CHECK_EXISTING_SITE_STATE_TITLE
security.declareProtected(Permissions.View, 'isFixExistingSiteConfigurationState')
def isFixExistingSiteConfigurationState(self):
""" Check if the Business Configuration is on fix existing site State
"""
return self.getCurrentStateTitle() == FIX_EXISTING_SITE_STATE_TITLE
security.declareProtected(Permissions.ModifyPortalContent, \
'initializeWorkflow')
def initializeWorkflow(self):
......@@ -165,7 +181,11 @@ class BusinessConfiguration(Item):
## exec next transition for this business configuration
self._executeTransition()
transition = self.getNextTransition()
return None, None, None, None
return None, None, None, None, "downlaod"
elif self.isFixExistingSiteConfigurationState():
self._executeTransition()
transition = self.getNextTransition()
return None, None, None, None, "fix existing site"
if form_id is None:
## go on until you find a form
self._executeTransition()
......@@ -182,9 +202,9 @@ class BusinessConfiguration(Item):
translate = self.Base_translateString
if self._isAlreadyConfSaveInWorkflowHistory(transition):
previous = translate("Previous")
return previous, form_html, form_title, \
translate(transition.getTitle())
if self.isCheckExistingSiteConfigurationState():
return previous, form_html, form_title, translate(transition.getTitle()), "check existing site"
return previous, form_html, form_title, translate(transition.getTitle()), "show"
security.declarePrivate('_renderFormInContext')
def _renderFormInContext(self, form_id, context, validation_errors):
html = ""
......@@ -358,3 +378,46 @@ class BusinessConfiguration(Item):
if self.portal_workflow.isTransitionPossible(self, 'install'):
self.activate(after_tag=kw["tag"]).install()
security.declareProtected(Permissions.ModifyPortalContent, 'getCheckResult')
def getCheckResult(self, active_process_url_list):
result_list = []
for active_process_url in active_process_url_list:
active_process = self.restrictedTraverse(active_process_url)
for result in active_process.getResultList():
result_list += result.result
result_list = [x if type(x) == str else str(x.getMessage()) for x in result_list]
return result_list
security.declareProtected(Permissions.ModifyPortalContent, 'checkExistingSite')
def checkExistingSite(self, active_process_url):
"""
Build list of business templates according to already saved
Configuration Saves (i.e. user input).
This is the actual implementation which can be used from workflow
actions and Configurator requets
"""
kw = dict(tag="start_configuration_%s" % self.getId(),
after_method_id=["updateBusinessTemplateFromUrl",
"immediateReindexObject"])
# build
configuration_save_list = self.contentValues(portal_type='Configuration Save')
configuration_save_list.sort(lambda x, y: cmp(x.getIntIndex(x.getIntId()),
y.getIntIndex(y.getIntId())))
active_process_list = []
for configuration_save in configuration_save_list:
# XXX: check which items are configure-able
configuration_item_list = configuration_save.contentValues()
configuration_item_list.sort(lambda x, y: cmp(x.getIntId(), y.getIntId()))
for configurator_item in configuration_item_list:
active_process = self.portal_activities.newActiveProcess()
configurator_item.activate(**kw).checkConsistency(
filter={"constraint_type":"configuration"})
kw["after_tag"] = kw["tag"]
kw["tag"] = "configurator_item_%s_%s" % (configurator_item.getId(),
configurator_item.getUid())
kw["active_process"] = active_process.getRelativeUrl()
active_process_list.append(kw["active_process"])
self.activate(
active_process=active_process_url,
after_tag=kw["after_tag"],
after_method_id = ["fixConsistency", 'immediateReindexObject']).getCheckResult(active_process_list)
......@@ -38,6 +38,7 @@ from Products.ERP5Configurator import _dtmldir
from Products.Formulator.Errors import FormValidationError
from DateTime import DateTime
referer = None
installation_status = {'bt5': {'current': 0,
'all': 0, },
......@@ -137,6 +138,8 @@ class ConfiguratorTool(BaseTool):
next=response['next'])
elif response["command"] == "install":
return self.startInstallation(bc, REQUEST=REQUEST)
elif response["command"] == "check existing site":
return self.startCheckExistingSite(bc, REQUEST=REQUEST)
def _next(self, business_configuration, kw):
""" Return next configuration form and validate previous. """
......@@ -144,7 +147,6 @@ class ConfiguratorTool(BaseTool):
need_validation = 1
validation_errors = None
response = {}
business_configuration.initializeWorkflow()
## initial state no previous form to validate
......@@ -269,6 +271,8 @@ class ConfiguratorTool(BaseTool):
if html is None:
## we have no more forms proceed to build
response.update(command="install", data=None)
elif html == 'check existing site':
response.update(command="check existing site", data=None)
else:
## we have more forms
next_state = self.restrictedTraverse(business_configuration.getNextTransition()\
......@@ -364,3 +368,16 @@ class ConfiguratorTool(BaseTool):
active_process=active_process, tag='initialERP5Setup'
).build()
return self.ConfiguratorTool_viewInstallationStatus(REQUEST)
def startCheckExistingSite(self, business_configuration, REQUEST):
global installation_status
# init installation status
installation_status['bt5']['all'] = 1
installation_status['bt5']['current'] = 0
installation_status['activity_list'] = []
active_process = self.portal_activities.newActiveProcess()
REQUEST.set('active_process_id', active_process.getId())
business_configuration.activate(
active_process=active_process, tag='initialERP5Setup'
).checkExistingSite()
return self.ConfiguratorTool_viewInstallationStatus(REQUEST)
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