Commit 1572f19a authored by Romain Courteaud's avatar Romain Courteaud

WIP [erp5_hal/web_renderjs_ui/officejs] Check python coding style

parent 944010af
...@@ -2,7 +2,6 @@ from Acquisition import aq_self, aq_base, aq_inner ...@@ -2,7 +2,6 @@ from Acquisition import aq_self, aq_base, aq_inner
from Products.ERP5Type.Utils import UpperCase from Products.ERP5Type.Utils import UpperCase
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from AccessControl import Unauthorized from AccessControl import Unauthorized
from Products.ZSQLCatalog.zsqlbrain import ZSQLBrain
def Base_aqSelf(self): def Base_aqSelf(self):
...@@ -68,7 +67,7 @@ def Listbox_getBrainValue(self, brain, obj, select, can_check_local_property, ed ...@@ -68,7 +67,7 @@ def Listbox_getBrainValue(self, brain, obj, select, can_check_local_property, ed
default_field_value = default_field_value() default_field_value = default_field_value()
except (ConflictError, RuntimeError): except (ConflictError, RuntimeError):
raise raise
except: except Exception:
default_field_value = None default_field_value = None
# Listbox.py forces result to be an empty string # Listbox.py forces result to be an empty string
......
...@@ -45,10 +45,7 @@ ...@@ -45,10 +45,7 @@
<item> <item>
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple/>
<string>W: 71, 4: No exception type(s) specified (bare-except)</string>
<string>W: 5, 0: Unused ZSQLBrain imported from Products.ZSQLCatalog.zsqlbrain (unused-import)</string>
</tuple>
</value> </value>
</item> </item>
<item> <item>
...@@ -103,24 +100,28 @@ ...@@ -103,24 +100,28 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>validate</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>validate</string> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>validated</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>validated</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -12,13 +12,10 @@ There are runtime values hidden in every dialog form (injected by getHateoas Scr ...@@ -12,13 +12,10 @@ There are runtime values hidden in every dialog form (injected by getHateoas Scr
extra_param_json - JSON serialized extra parameters for the dialog script extra_param_json - JSON serialized extra parameters for the dialog script
""" """
from Products.ERP5Type.Log import log, DEBUG, INFO, WARNING, ERROR from Products.ERP5Type.Log import log, WARNING
from Products.Formulator.Errors import FormValidationError, ValidationError from Products.Formulator.Errors import FormValidationError
from ZTUtils import make_query
import json import json
DOCUMENT_COUNT_LIMIT = 50
# http://stackoverflow.com/a/13105359 # http://stackoverflow.com/a/13105359
def byteify(value): def byteify(value):
if isinstance(value, dict): if isinstance(value, dict):
...@@ -53,7 +50,6 @@ else: ...@@ -53,7 +50,6 @@ else:
# request.form holds POST data thus containing 'field_' + field.id items # request.form holds POST data thus containing 'field_' + field.id items
# such as 'field_your_some_field' # such as 'field_your_some_field'
request_form = request.form request_form = request.form
error_message = ''
translate = context.Base_translateString translate = context.Base_translateString
portal = context.getPortalObject() portal = context.getPortalObject()
...@@ -161,7 +157,6 @@ except FormValidationError as validation_errors: ...@@ -161,7 +157,6 @@ except FormValidationError as validation_errors:
MARKER = [] # A recognisable default value. Use with 'is', not '=='. MARKER = [] # A recognisable default value. Use with 'is', not '=='.
listbox_id_list = [] # There should not be more than one listbox - but this give us a way to check. listbox_id_list = [] # There should not be more than one listbox - but this give us a way to check.
file_id_list = [] # For uploaded files.
for field in form.get_fields(): for field in form.get_fields():
field_id = field.id field_id = field.id
field_value = request.get(field_id, MARKER) field_value = request.get(field_id, MARKER)
......
...@@ -247,8 +247,6 @@ spp = context.getPhysicalPath() ...@@ -247,8 +247,6 @@ spp = context.getPhysicalPath()
spp =list(spp) spp =list(spp)
s_url = request["SERVER_URL"] s_url = request["SERVER_URL"]
spp.insert(0,s_url) spp.insert(0,s_url)
#calculate direct the url instead of using absolute_url
new_url = '/'.join(spp)
# for web mode, we should use 'view' instead of passed form_id # for web mode, we should use 'view' instead of passed form_id
# after 'Save & View'. # after 'Save & View'.
......
...@@ -57,10 +57,8 @@ import time ...@@ -57,10 +57,8 @@ import time
from email.Utils import formatdate from email.Utils import formatdate
import re import re
from zExceptions import Unauthorized from zExceptions import Unauthorized
from Products.ERP5Type.Log import log, DEBUG, INFO, WARNING, ERROR from Products.ERP5Type.Log import log, WARNING, ERROR
from Products.ERP5Type.Message import Message from Products.ERP5Type.Message import Message
from Products.ERP5Type.Utils import UpperCase
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
from collections import OrderedDict from collections import OrderedDict
from Products.ERP5Form.Selection import Selection from Products.ERP5Form.Selection import Selection
...@@ -77,12 +75,6 @@ if response is None: ...@@ -77,12 +75,6 @@ if response is None:
response = REQUEST.RESPONSE response = REQUEST.RESPONSE
def isFieldType(field, type_name):
if field.meta_type == 'ProxyField':
field = field.getRecursiveTemplateField()
return field.meta_type == type_name
def toBasicTypes(obj): def toBasicTypes(obj):
"""Ensure that obj contains only basic types.""" """Ensure that obj contains only basic types."""
if obj is None: if obj is None:
...@@ -97,7 +89,7 @@ def toBasicTypes(obj): ...@@ -97,7 +89,7 @@ def toBasicTypes(obj):
return obj.translate() return obj.translate()
try: try:
return {toBasicTypes(key): toBasicTypes(obj[key]) for key in obj} return {toBasicTypes(key): toBasicTypes(obj[key]) for key in obj}
except: except Exception:
log('Cannot convert {!s} to basic types {!s}'.format(type(obj), obj), level=100) log('Cannot convert {!s} to basic types {!s}'.format(type(obj), obj), level=100)
return obj return obj
...@@ -940,7 +932,6 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti ...@@ -940,7 +932,6 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
proxy_form_id_list = [('Base_viewRelatedObjectListBase/listbox', 'default')] proxy_form_id_list = [('Base_viewRelatedObjectListBase/listbox', 'default')]
# Create the possible choices # Create the possible choices
root_url = site_root.absolute_url()
renderHiddenField(response_dict, "proxy_form_id_list", '') renderHiddenField(response_dict, "proxy_form_id_list", '')
response_dict["proxy_form_id_list"].update({ response_dict["proxy_form_id_list"].update({
"items": [(Base_translateString(y), url_template_dict['traverse_generator_action'] % { "items": [(Base_translateString(y), url_template_dict['traverse_generator_action'] % {
...@@ -1403,7 +1394,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1403,7 +1394,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
'href': '%s' % view_action['url'], 'href': '%s' % view_action['url'],
'name': view_action['id'], 'name': view_action['id'],
'icon': view_action['icon'], 'icon': view_action['icon'],
'title': Base_translateString(view_action['title']) 'title': Base_translateString(view_action['title']),
}) })
global_action_type = ("view", "workflow", "object_new_content_action", global_action_type = ("view", "workflow", "object_new_content_action",
...@@ -1549,7 +1540,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1549,7 +1540,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
} }
elif relative_url == 'portal_preferences': elif relative_url == 'portal_preferences':
preference_tool = portal.portal_preferences
preference = traversed_document.getActiveUserPreference() preference = traversed_document.getActiveUserPreference()
if preference: if preference:
result_dict['_links']['active_preference'] = { result_dict['_links']['active_preference'] = {
...@@ -2019,7 +2009,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -2019,7 +2009,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
) )
except (ConflictError, RuntimeError): except (ConflictError, RuntimeError):
raise raise
except: except Exception:
log('could not evaluate the url method getListItemUrlDict with %r' % brain, log('could not evaluate the url method getListItemUrlDict with %r' % brain,
level=800) level=800)
......
...@@ -2,7 +2,7 @@ from Products.CMFCore.WorkflowCore import WorkflowException ...@@ -2,7 +2,7 @@ from Products.CMFCore.WorkflowCore import WorkflowException
from Products.Formulator.Errors import FormValidationError from Products.Formulator.Errors import FormValidationError
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
from Products.ERP5Type.Log import log, WARNING from Products.ERP5Type.Log import WARNING
portal = context.getPortalObject() portal = context.getPortalObject()
request = REQUEST or context.REQUEST request = REQUEST or context.REQUEST
......
...@@ -140,20 +140,20 @@ def do_fake_request(request_method, headers=None, data=()): ...@@ -140,20 +140,20 @@ def do_fake_request(request_method, headers=None, data=()):
def replace_request(new_request, context): def replace_request(new_request, context):
base_chain = [aq_base(x) for x in context.aq_chain] base_chain = [aq_base(x) for x in context.aq_chain]
# Grab existig request (last chain item) and create a copy. # Grab existig request (last chain item) and create a copy.
request_container = base_chain.pop() request_container = base_chain.pop()
# request = request_container.REQUEST # request = request_container.REQUEST
setRequest(new_request) setRequest(new_request)
new_request_container = request_container.__class__(REQUEST=new_request) new_request_container = request_container.__class__(REQUEST=new_request)
# Recreate acquisition chain. # Recreate acquisition chain.
my_self = new_request_container my_self = new_request_container
base_chain.reverse() base_chain.reverse()
for item in base_chain: for item in base_chain:
my_self = item.__of__(my_self) my_self = item.__of__(my_self)
return my_self return my_self
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
...@@ -2151,7 +2151,7 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -2151,7 +2151,7 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
# Create the listbox selection # Create the listbox selection
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas( self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request, REQUEST=fake_request,
mode="search", mode="search",
local_roles=["Manager"], local_roles=["Manager"],
......
...@@ -10,7 +10,7 @@ class TestHalRestricted(ERP5HALJSONStyleSkinsMixin): ...@@ -10,7 +10,7 @@ class TestHalRestricted(ERP5HALJSONStyleSkinsMixin):
def test_mode_root(self): def test_mode_root(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
self.logout() self.logout()
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request) self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 401) self.assertEquals(fake_request.RESPONSE.status, 401)
self.assertEquals(fake_request.RESPONSE.getHeader('WWW-Authenticate'), self.assertEquals(fake_request.RESPONSE.getHeader('WWW-Authenticate'),
'X-Delegate uri="%s/connection/login_form{?came_from}"' % self.portal.web_site_module.hateoas.absolute_url() 'X-Delegate uri="%s/connection/login_form{?came_from}"' % self.portal.web_site_module.hateoas.absolute_url()
...@@ -25,7 +25,7 @@ class TestHalRestricted(ERP5HALJSONStyleSkinsMixin): ...@@ -25,7 +25,7 @@ class TestHalRestricted(ERP5HALJSONStyleSkinsMixin):
document_relative_url = self._makeDocument().getRelativeUrl() document_relative_url = self._makeDocument().getRelativeUrl()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
self.logout() self.logout()
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="traverse", relative_url=document_relative_url) self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="traverse", relative_url=document_relative_url)
self.assertEquals(fake_request.RESPONSE.status, 401) self.assertEquals(fake_request.RESPONSE.status, 401)
self.assertEquals(fake_request.RESPONSE.getHeader('WWW-Authenticate'), self.assertEquals(fake_request.RESPONSE.getHeader('WWW-Authenticate'),
'X-Delegate uri="%s/connection/login_form{?came_from}"' % self.portal.web_site_module.hateoas.absolute_url() 'X-Delegate uri="%s/connection/login_form{?came_from}"' % self.portal.web_site_module.hateoas.absolute_url()
...@@ -39,7 +39,7 @@ class TestHalRestricted(ERP5HALJSONStyleSkinsMixin): ...@@ -39,7 +39,7 @@ class TestHalRestricted(ERP5HALJSONStyleSkinsMixin):
def test_mode_search(self): def test_mode_search(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
self.logout() self.logout()
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="search") self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="search")
self.assertEquals(fake_request.RESPONSE.status, 401) self.assertEquals(fake_request.RESPONSE.status, 401)
self.assertEquals(fake_request.RESPONSE.getHeader('WWW-Authenticate'), self.assertEquals(fake_request.RESPONSE.getHeader('WWW-Authenticate'),
'X-Delegate uri="%s/connection/login_form{?came_from}"' % self.portal.web_site_module.hateoas.absolute_url() 'X-Delegate uri="%s/connection/login_form{?came_from}"' % self.portal.web_site_module.hateoas.absolute_url()
...@@ -53,7 +53,7 @@ class TestHalRestricted(ERP5HALJSONStyleSkinsMixin): ...@@ -53,7 +53,7 @@ class TestHalRestricted(ERP5HALJSONStyleSkinsMixin):
def test_mode_worklist(self): def test_mode_worklist(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
self.logout() self.logout()
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="worklist") self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="worklist")
self.assertEquals(fake_request.RESPONSE.status, 401) self.assertEquals(fake_request.RESPONSE.status, 401)
self.assertEquals(fake_request.RESPONSE.getHeader('WWW-Authenticate'), self.assertEquals(fake_request.RESPONSE.getHeader('WWW-Authenticate'),
'X-Delegate uri="%s/connection/login_form{?came_from}"' % self.portal.web_site_module.hateoas.absolute_url() 'X-Delegate uri="%s/connection/login_form{?came_from}"' % self.portal.web_site_module.hateoas.absolute_url()
......
...@@ -100,24 +100,28 @@ ...@@ -100,24 +100,28 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>validate</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>validate</string> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>validated</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>validated</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -3,15 +3,10 @@ import json ...@@ -3,15 +3,10 @@ import json
portal = context.getPortalObject() portal = context.getPortalObject()
Base_translateString = context.Base_translateString Base_translateString = context.Base_translateString
#(data-i18n)=["']{{((?:.(?!["']?(?:\S+)=|[>"']))+.)}}["'] #(data-i18n)=["']{{((?:.(?!["']?(?:\S+)=|[>"']))+.)}}["']
attribute_filter_re = re.compile(r"""(data-i18n)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?""") attribute_filter_re = re.compile(r"""(data-i18n)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?""")
tmp_re = re.compile(r"""/[{}]/g, """"")
translate_word = [] translate_word = []
for web_page in portal.web_page_module.searchFolder(portal_type='Web Page', for web_page in portal.web_page_module.searchFolder(portal_type='Web Page',
......
appcache_file = context.getLayoutProperty("configuration_manifest_url", default="gadget_erp5.appcache") appcache_reference = context.getLayoutProperty("configuration_manifest_url", default="gadget_erp5.appcache")
text_content = context.getPortalObject().portal_catalog.getResultValue(
portal_type='Web Manifest',
reference=appcache_reference).getTextContent()
text_content = context.web_page_module.searchFolder( translation_data_url_list = []
portal_type= 'Web Manifest', url_list = []
reference = appcache_file)[0].getTextContent() for text_line in text_content.split('\n'):
text_line = text_line.split('/')[-1]
translation_data_file = [] if text_line.endswith('.html'):
file_list = [] url_list.append(text_line)
for file in text_content.split('\n'):
file = file.split('/')[-1]
if file.endswith('.html'):
file_list.append(file)
continue continue
if file.endswith('.js') and not only_html: if text_line.endswith('.js') and not only_html:
if file.endswith('translation_data.js'): if text_line.endswith('translation_data.js'):
translation_data_file = [file] translation_data_url_list = [text_line]
continue continue
file_list.append(file) url_list.append(text_line)
return translation_data_file + file_list return translation_data_url_list + url_list
...@@ -3,8 +3,8 @@ if REQUEST is None: ...@@ -3,8 +3,8 @@ if REQUEST is None:
if response is None: if response is None:
response = REQUEST.RESPONSE response = REQUEST.RESPONSE
file = context file_document = context
file_content = file.getData() file_content = file_document.getData()
# The vanilla HTML is wanted # The vanilla HTML is wanted
response.setBase(None) response.setBase(None)
...@@ -12,7 +12,7 @@ response.setBase(None) ...@@ -12,7 +12,7 @@ response.setBase(None)
# Allow any external app to download the source code # Allow any external app to download the source code
response.setHeader("Access-Control-Allow-Origin", "*") response.setHeader("Access-Control-Allow-Origin", "*")
if REQUEST.getHeader('If-Modified-Since', '') == file.getModificationDate().rfc822(): if REQUEST.getHeader('If-Modified-Since', '') == file_document.getModificationDate().rfc822():
response.setStatus(304) response.setStatus(304)
return "" return ""
...@@ -20,6 +20,6 @@ if REQUEST.getHeader('If-Modified-Since', '') == file.getModificationDate().rfc8 ...@@ -20,6 +20,6 @@ if REQUEST.getHeader('If-Modified-Since', '') == file.getModificationDate().rfc8
#if file_content_type is None: #if file_content_type is None:
# file_content_type = 'application/octet-stream' # file_content_type = 'application/octet-stream'
response.setHeader('Content-Type', (file.getContentType() or 'application/octet-stream')) response.setHeader('Content-Type', (file_document.getContentType() or 'application/octet-stream'))
return file_content return file_content
...@@ -89,6 +89,6 @@ else: ...@@ -89,6 +89,6 @@ else:
background-attachment: fixed; background-attachment: fixed;
background-image: url("%s"); background-image: url("%s");
} }
""" % wallpaper_url); """ % wallpaper_url)
return view_as_web_method(mapping_dict=mapping_dict) return view_as_web_method(mapping_dict=mapping_dict)
""" """
Default logout handler, overwritten to give website specific portal status message. Default logout handler, overwritten to give website specific portal status message.
""" """
website = context.getWebSiteValue()
REQUEST = context.REQUEST REQUEST = context.REQUEST
if REQUEST.has_key('portal_skin'): if REQUEST.has_key('portal_skin'):
context.portal_skins.clearSkinCookie() context.portal_skins.clearSkinCookie()
......
alpha = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' alpha = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
new_password = ''.join([random.choice(alpha) for i in range(10)]) new_password = ''.join(map(lambda x: random.choice(alpha), range(10)))
person_module = context.getPortalObject().person_module person_module = context.getPortalObject().person_module
user_id = "user_a_test" user_id = "user_a_test"
......
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