Commit 9121fa4a authored by Rafael Monnerat's avatar Rafael Monnerat

Improve code style (pep8)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44415 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e749aeab
...@@ -48,8 +48,8 @@ cookiejar = cookielib.CookieJar() ...@@ -48,8 +48,8 @@ cookiejar = cookielib.CookieJar()
last_loggedin_user_and_password = None last_loggedin_user_and_password = None
referer = None referer = None
installation_status = {'bt5': {'current': 0, installation_status = {'bt5': {'current': 0,
'all': 0,}, 'all': 0, },
'activity_list': [],} 'activity_list': [], }
# cookie name to store user's preferred language name # cookie name to store user's preferred language name
LANGUAGE_COOKIE_NAME = 'configurator_user_preferred_language' LANGUAGE_COOKIE_NAME = 'configurator_user_preferred_language'
...@@ -87,7 +87,7 @@ def _validateFormToRequest(form, REQUEST, **kw): ...@@ -87,7 +87,7 @@ def _validateFormToRequest(form, REQUEST, **kw):
## missing fields ## missing fields
validation_status = 2 validation_status = 2
## extract form arguments and remove leading prefixes ## extract form arguments and remove leading prefixes
if validation_status==0: if validation_status == 0:
for field in form.get_fields(): for field in form.get_fields():
field_id = field.id field_id = field.id
value = getattr(REQUEST, field_id, None) value = getattr(REQUEST, field_id, None)
...@@ -104,8 +104,7 @@ def _validateFormToRequest(form, REQUEST, **kw): ...@@ -104,8 +104,7 @@ def _validateFormToRequest(form, REQUEST, **kw):
class ConfiguratorTool(BaseTool): class ConfiguratorTool(BaseTool):
""" """This tool provides a Configurator Tool.
This tool provides a Configurator Tool.
""" """
id = 'portal_configurator' id = 'portal_configurator'
...@@ -118,7 +117,7 @@ class ConfiguratorTool(BaseTool): ...@@ -118,7 +117,7 @@ class ConfiguratorTool(BaseTool):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareProtected(Permissions.ManagePortal, 'manage_overview') security.declareProtected(Permissions.ManagePortal, 'manage_overview')
manage_overview = DTMLFile('explainConfiguratorTool', _dtmldir ) manage_overview = DTMLFile('explainConfiguratorTool', _dtmldir)
def getConfiguratorUserPreferredLanguage(self): def getConfiguratorUserPreferredLanguage(self):
""" Get configuration language as selected by user """ """ Get configuration language as selected by user """
...@@ -159,17 +158,17 @@ class ConfiguratorTool(BaseTool): ...@@ -159,17 +158,17 @@ class ConfiguratorTool(BaseTool):
REQUEST.RESPONSE.setCookie(LANGUAGE_COOKIE_NAME, REQUEST.RESPONSE.setCookie(LANGUAGE_COOKIE_NAME,
user_preferred_language, user_preferred_language,
path='/', path='/',
expires=(DateTime()+30).rfc822()) expires=(DateTime() + 30).rfc822())
# set encoded __ac_key cookie at client's browser # set encoded __ac_key cookie at client's browser
__ac_key = quote(encodestring(password)) __ac_key = quote(encodestring(password))
expires = (DateTime() + 1).toZone('GMT').rfc822() expires = (DateTime() + 1).toZone('GMT').rfc822()
REQUEST.RESPONSE.setCookie('__ac_key', REQUEST.RESPONSE.setCookie('__ac_key',
__ac_key, __ac_key,
expires = expires) expires=expires)
REQUEST.set('__ac_key', __ac_key) REQUEST.set('__ac_key', __ac_key)
REQUEST.RESPONSE.setCookie(BUSINESS_CONFIGURATION_COOKIE_NAME, REQUEST.RESPONSE.setCookie(BUSINESS_CONFIGURATION_COOKIE_NAME,
bc, bc,
expires = expires) expires=expires)
REQUEST.set(BUSINESS_CONFIGURATION_COOKIE_NAME, bc) REQUEST.set(BUSINESS_CONFIGURATION_COOKIE_NAME, bc)
return self.next(REQUEST=REQUEST) return self.next(REQUEST=REQUEST)
else: else:
...@@ -186,7 +185,8 @@ class ConfiguratorTool(BaseTool): ...@@ -186,7 +185,8 @@ class ConfiguratorTool(BaseTool):
password = quote(encodestring(password)) password = quote(encodestring(password))
# Not still not finished yet. # Not still not finished yet.
if business_configuration is None: if business_configuration is None:
business_configuration = self.REQUEST.get(BUSINESS_CONFIGURATION_COOKIE_NAME, None) business_configuration = self.REQUEST.get(
BUSINESS_CONFIGURATION_COOKIE_NAME, None)
if None not in [password, business_configuration]: if None not in [password, business_configuration]:
def is_key_valid(password, business_configuration): def is_key_valid(password, business_configuration):
bc = self.getPortalObject().unrestrictedTraverse(business_configuration) bc = self.getPortalObject().unrestrictedTraverse(business_configuration)
...@@ -197,7 +197,6 @@ class ConfiguratorTool(BaseTool): ...@@ -197,7 +197,6 @@ class ConfiguratorTool(BaseTool):
password, business_configuration) password, business_configuration)
return False return False
#security.declareProtected(Permissions.ModifyPortalContent, 'next') #security.declareProtected(Permissions.ModifyPortalContent, 'next')
def next(self, REQUEST): def next(self, REQUEST):
""" Validate settings and return a new form to the user. """ """ Validate settings and return a new form to the user. """
...@@ -215,7 +214,7 @@ class ConfiguratorTool(BaseTool): ...@@ -215,7 +214,7 @@ class ConfiguratorTool(BaseTool):
self.Base_translateString( self.Base_translateString(
'You cannot Continue. Unable to find your Business Configuration.')) 'You cannot Continue. Unable to find your Business Configuration.'))
return self.view() return self.view()
response = self._next(business_configuration=bc,kw=kw) response = self._next(business_configuration=bc, kw=kw)
## Parse server response ## Parse server response
command = response["command"] command = response["command"]
if command == "show": if command == "show":
...@@ -231,7 +230,6 @@ class ConfiguratorTool(BaseTool): ...@@ -231,7 +230,6 @@ class ConfiguratorTool(BaseTool):
need_validation = 1 need_validation = 1
validation_errors = None validation_errors = None
response = {} response = {}
portal = self.getPortalObject()
## initial state no previous form to validate ## initial state no previous form to validate
if business_configuration.isInitialConfigurationState(): if business_configuration.isInitialConfigurationState():
...@@ -255,19 +253,19 @@ class ConfiguratorTool(BaseTool): ...@@ -255,19 +253,19 @@ class ConfiguratorTool(BaseTool):
## iterate all forms ## iterate all forms
for form_counter in range(0, isMultiEntryTransition): for form_counter in range(0, isMultiEntryTransition):
single_form_kw = {} single_form_kw = {}
for key,value in form_kw.items(): for key, value in form_kw.items():
if isinstance(value, list) or isinstance(value, tuple): if isinstance(value, list) or isinstance(value, tuple):
## we have more than one form shown ## we have more than one form shown
single_form_kw[key] = value[form_counter] single_form_kw[key] = value[form_counter]
# save original value in request in some cases of multiple forms # save original value in request in some cases of multiple forms
# we need it for validation # we need it for validation
single_form_kw['_original_%s' %key] = value single_form_kw['_original_%s' % key] = value
else: else:
## even though we have multiple entry transition customer wants ## even though we have multiple entry transition customer wants
## ONE form! ## ONE form!
single_form_kw[key] = value single_form_kw[key] = value
## update properly REQUEST with current form data ## update properly REQUEST with current form data
for key,value in single_form_kw.items(): for key, value in single_form_kw.items():
self.REQUEST.set(key, value) self.REQUEST.set(key, value)
## get validation status ## get validation status
validation_status, dummy, validation_errors = \ validation_status, dummy, validation_errors = \
...@@ -298,7 +296,7 @@ class ConfiguratorTool(BaseTool): ...@@ -298,7 +296,7 @@ class ConfiguratorTool(BaseTool):
single_form_html = form() single_form_html = form()
## wrap in form template ## wrap in form template
single_form_html = self.Base_mainConfiguratorFormTemplate( single_form_html = self.Base_mainConfiguratorFormTemplate(
current_form_number = form_counter +1, current_form_number = form_counter + 1,
max_form_numbers = isMultiEntryTransition, max_form_numbers = isMultiEntryTransition,
form_html = single_form_html) form_html = single_form_html)
## add to list of forms as html code ## add to list of forms as html code
...@@ -327,9 +325,9 @@ class ConfiguratorTool(BaseTool): ...@@ -327,9 +325,9 @@ class ConfiguratorTool(BaseTool):
else: else:
validation_status, form_kw, validation_errors = \ validation_status, form_kw, validation_errors = \
business_configuration._validateNextForm(**kw) business_configuration._validateNextForm(**kw)
if validation_status==1: if validation_status == 1:
need_validation = 0 need_validation = 0
elif validation_status==2: elif validation_status == 2:
rendered = True rendered = True
need_validation = 0 need_validation = 0
if business_configuration.getNextTransition() == None: if business_configuration.getNextTransition() == None:
...@@ -434,7 +432,7 @@ class ConfiguratorTool(BaseTool): ...@@ -434,7 +432,7 @@ class ConfiguratorTool(BaseTool):
portal_activities = getToolByName(self.getPortalObject(), portal_activities = getToolByName(self.getPortalObject(),
'portal_activities') 'portal_activities')
is_bt5_installation_over = (portal_activities.countMessageWithTag( is_bt5_installation_over = (portal_activities.countMessageWithTag(
'initialERP5Setup')==0) 'initialERP5Setup') == 0)
if 0 == len(portal_activities.getMessageList()) and \ if 0 == len(portal_activities.getMessageList()) and \
is_bt5_installation_over: is_bt5_installation_over:
html = self.ConfiguratorTool_viewSuccessfulConfigurationMessageRenderer() html = self.ConfiguratorTool_viewSuccessfulConfigurationMessageRenderer()
...@@ -465,7 +463,7 @@ class ConfiguratorTool(BaseTool): ...@@ -465,7 +463,7 @@ class ConfiguratorTool(BaseTool):
active_process = self.portal_activities.newActiveProcess() active_process = self.portal_activities.newActiveProcess()
REQUEST.set('active_process_id', active_process.getId()) REQUEST.set('active_process_id', active_process.getId())
request_restore_dict = {'__ac_key': REQUEST.get('__ac_key', request_restore_dict = {'__ac_key': REQUEST.get('__ac_key',
None),} None), }
self.activate(active_process=active_process, tag = 'initialERP5Setup' self.activate(active_process=active_process, tag = 'initialERP5Setup'
).initialERP5Setup(business_configuration.getRelativeUrl(), request_restore_dict) ).initialERP5Setup(business_configuration.getRelativeUrl(), request_restore_dict)
return self.ConfiguratorTool_viewInstallationStatus(REQUEST) 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