From e2fa25fc32fb43d2f13af3cc595d52b82ebc1932 Mon Sep 17 00:00:00 2001 From: Julien Muchembled <jm@nexedi.com> Date: Wed, 11 May 2016 20:13:44 +0200 Subject: [PATCH] erp5_forge: improve script to compare fields of 2 skins, to make results easier to read --- .../erp5_toolbox/Base_checkSkinFolderForms.py | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_checkSkinFolderForms.py b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_checkSkinFolderForms.py index b8480c8a55..251aae963d 100644 --- a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_checkSkinFolderForms.py +++ b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_checkSkinFolderForms.py @@ -1,50 +1,50 @@ -skin_folder = getattr(context.portal_skins, original_skin_name) -new_skin_folder = getattr(context.portal_skins, new_skin_name) - -output_list = [] +from cgi import escape +portal = context.getPortalObject() +skin_folder = portal.portal_skins[original_skin_name] +new_skin_folder = portal.portal_skins[new_skin_name] + +output_list = ["""<html><head><style> +table { border-collapse: collapse; } +th, td { border: 1px solid gray; padding: 0 .3em; } +</style></head><body>"""] output_append = output_list.append -output_append("<html>") -output_append(" <body>") for original_form in skin_folder.objectValues(): - if (original_form.meta_type=='ERP5 Form' or original_form.meta_type=='ERP5 Report') and not original_form.getId().endswith('FieldLibrary'): - new_form = getattr(new_skin_folder, original_form.id) + if original_form.meta_type in ('ERP5 Form', 'ERP5 Report') and \ + not original_form.getId().endswith('FieldLibrary'): + new_form = new_skin_folder[original_form.id] for original_field in original_form.objectValues(): - new_field = getattr(new_form, original_field.id, None) - if new_field is None: - output_append("Missing %s in %s" % (original_field.id, new_form)) - - else: - - original_value_dict, original_value_tales = context.Base_getFieldData(original_field) - - try: - new_value_dict, new_value_tales = context.Base_getFieldData(new_field) - except AttributeError: - new_value_dict = new_value_tales = None - output_append("Dead proxy field %s %s" % (original_field.id, new_form)) - - if new_value_dict is not None: - - if (original_value_dict != new_value_dict) or \ - (original_value_tales != new_value_tales): - - output_append("%s %s <a href='%s'>old</a> <a href='%s'>new</a>" % ( - new_form.id, new_field.id, - original_field.absolute_url() + '/manage_main', - new_field.absolute_url() + '/manage_main')) - output_append("<blockquote><ul>") - - - for key, original_value in original_value_dict.items(): - if original_value != new_value_dict[key]: - output_append(" <li>" + key + ' Origin: %s ' % original_value \ - + ' New: %s</li>' % new_value_dict[key]) - - for key, original_value in original_value_tales.items(): - if original_value != new_value_tales[key]: - output_append(" <li>" + key + ' Origin: %s ' % original_value \ - + ' New: %s<br></li>' % new_value_tales[key]) - output_append("</ul></blockquote>") + try: + new_field = new_form[original_field.id] + except KeyError: + output_append("<p>Missing %s in %s</p>" % (original_field.id, new_form.id)) + continue + try: + new_value_dict, new_value_tales = portal.Base_getFieldData(new_field) + except AttributeError: + output_append("<p>Dead proxy field %s %s</p>" % (original_field.id, new_form.id)) + continue + + original_value_dict, original_value_tales = portal.Base_getFieldData( + original_field) + if original_value_dict == new_value_dict and \ + original_value_tales == new_value_tales: + continue + + output_append("<p>%s/%s<blockquote><table><tr><th>name</th>" + "<th><a href='%s/manage_main'>old</a></th>" + "<th><a href='%s/manage_main'>new</a></th>" + "</tr>" % ( + new_form.id, new_field.id, + original_field.absolute_url(), new_field.absolute_url())) + + output_list += ("<tr><td>%s</td></tr>" % "</td><td>".join( + map(escape, ('[%s]' % key if T else key, str(old), str(new[key])))) + for T, old, new in ((0, original_value_dict, new_value_dict), + (1, original_value_tales, new_value_tales)) + for key, old in old.iteritems() + if old != new[key]) + + output_append("</table></blockquote><p>") output_append("Finished<br>") output_append(" </body>") -- 2.30.9