Commit 70e49e75 authored by Romain Courteaud's avatar Romain Courteaud

Implement a working version of FormBox validator.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20041 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 27b08a00
master allow_login_change allow_login_change_differentiate_id_and_login allow_login_change_wip arnau arnau-kns arnau-kns-without-property-mapping arnau-merge arnau-poc authentication_policy_fixes auto_extend_select_list autoflake backup_erp5_workflow bk_erp5ish_actions_tool bk_sqlcatalog boc-interaction-drop bt_owner cache catalog_fulltext catalog_fulltext_old cedric cedriclen cedriclen-eos certificate_authority cherry-pick-4a8e045d cherry-pick-bca64206 cleanJSByJSLint clean_up_upgrader compact_title_no_reference credential_update_action datetimefield deferred_listbox douglas_forum dream_distributor drop-legacy-simulation eos-dev erp5-component erp5-data-notebook erp5-forum erp5-preference erp5-release erp5-slapos-upgrade erp5-util-testing erp5-vifib erp5-vifib-cleanup erp5_calendar erp5_free_subscription erp5_workflow fix_system_processes_ownership floatArrayTest for_testrunner_1 for_testrunner_2 formbox gabriel gabriel-fix-rounding-in-accounting-generation gabriel-fix-rounding-in-accounting-generation2 gadget-json-value http_cache_fix import_fixes import_fixes_complete improve_default_caching_policy_manager interaction-drop isDeletable item_tracking_graph_editor ivan jerome-bt-reference-doc jerome-test jerome_events jerome_graph_editor_renderjs jerome_new_style_solve_divergence jerome_promise_in_tests jerome_user_preference_time_zone jio jm/form-action-guard joblib-activity jupyter_egg_tests jupyter_import_dot_fix jupyter_import_dot_quickfix jupyter_kernel_fixes jupyter_reference_warning jupyter_restricted kns lazy_simulation_causality lignan lingnan listbox-generator mame mame-bt5-cleanup mame-erp5_project-cleanup mame-naming-convention mame-naming-convention-list_method mame-test-stock-indexation mame-work mame2 master-erp5-test-result-scalability master-erp5-test-result-scalability-rebase master-test-fix-additionalbt5path master_calendar_wip_patches master_calendar_wip_patches_extend_security master_no_guard_on_workflow_transition master_no_guard_on_workflow_transition_plus_calendar_wip_patchs merge_xhtml_jquery mmariani-inventory mrp new-render-presentation nexedi-erp5-jp no_reindex_data_stream officejs pere portal_callables portal_solver_process_security_configuration presentation rebased_mrp reindex_calendar_after_change_calendar_exception removed_portal_skin_redundancy romain-fulltext scalability-master2 scalability-master2-rebase scalability-rebase shop-box shop-box-rebased simulation sms_more_than_140_characters strict_catalog syncml test_page testnode_software_link timezones tristan tristan-merge tristan-performance ttr ttrm upgradeSite view-aggregated-amounts vivekpab_erp5webrenderjs_layoutconfig vivekpab_jabberclient vivekpab_renderjs_interfaces wenjie wenjie_branch xiaowu_newui yryr yryr-components-cp yryr-inventory-cache yryr-test yryr-with-components yusei erp5.util-0.4.46 erp5.util-0.4.44 erp5.util-0.4.43 erp5.util-0.4.41 erp5.util-0.4.40 erp5.util-0.4.37 erp5.util-0.4.1 erp5.util-0.4 erp5.util-0.3 erp5.util-0.2 erp5.util-0.1
No related merge requests found
......@@ -38,10 +38,11 @@ from Globals import get_request
from Products.PythonScripts.Utility import allow_class
from Products.PythonScripts.standard import url_quote_plus
from Products.Formulator.Errors import FormValidationError, ValidationError
import string
from zLOG import LOG
from zLOG import LOG, WARNING, DEBUG, PROBLEM
class FormBoxWidget(Widget.Widget):
"""
......@@ -65,11 +66,12 @@ class FormBoxWidget(Widget.Widget):
"""
property_names = Widget.Widget.property_names + [
'form_id', \
'formbox_target_id', \
]
form_id = fields.StringField(
'form_id',
# This name was changed to prevent naming collision with ProxyField
formbox_target_id = fields.StringField(
'formbox_target_id',
title='Form ID',
description=(
"ID of the form which must be rendered in this box."),
......@@ -84,20 +86,53 @@ class FormBoxWidget(Widget.Widget):
default="",
required=0)
def render(self, field, key, value, REQUEST):
"""
Render a form in a field
"""
here = REQUEST['here']
form = getattr(here, field.get_value('form_id'))
return form()
try:
form = getattr(here, field.get_value('formbox_target_id'))
except AttributeError:
LOG('FormBox', WARNING,
'Could not get a form from formbox %s in %s' % \
(field.id, field.aq_parent.id))
return ''
return form(REQUEST=REQUEST)
class FormBoxEditor:
"""
A class holding all values required to update the object
"""
def __init__(self, field_id, result):
self.field_id = field_id
self.result = result
def view(self):
return self.__dict__
def __call__(self, REQUEST):
pass
def render_view(self, field, value):
"""
Display a form in a field
def edit(self, context):
context.edit(**self.result[0])
for encapsulated_editor in self.result[1]:
encapsulated_editor.edit(context)
def as_dict(self):
"""
This method is used to return parameter dict.
XXX This API is probably not stable and may change, as some editors are used to
edit multiple objects.
"""
return self.render()
result_dict = self.result[0]
for encapsulated_editor in self.result[1]:
if hasattr(encapsulated_editor, 'as_dict'):
result_dict.update(
encapsulated_editor.as_dict())
return result_dict
allow_class(FormBoxEditor)
class FormBoxValidator(Validator.Validator):
"""
......@@ -105,11 +140,30 @@ class FormBoxValidator(Validator.Validator):
the result as a single variable.
"""
property_names = Validator.Validator.property_names
message_names = Validator.Validator.message_names + \
['form_invalidated',]
form_invalidated = "Form invalidated."
def validate(self, field, key, REQUEST):
form = field.aq_parent
form = getattr(form, field.get_value('form_id'))
return form.validate(REQUEST)
# XXX hardcoded acquisition
here = field.aq_parent.aq_parent
formbox_target_id = field.get_value('formbox_target_id')
# Get current error fields
current_field_errors = REQUEST.get('field_errors', [])
# XXX Hardcode script name
result, result_type = here.Base_edit(formbox_target_id, silent_mode=1)
if result_type == 'edit':
return FormBoxEditor(field.id, result)
elif result_type == 'form':
formbox_field_errors = REQUEST.get('field_errors', [])
current_field_errors.extend(formbox_field_errors)
REQUEST.set('field_errors', current_field_errors)
getattr(here, formbox_target_id).validate_all_to_request(REQUEST)
else:
raise NotImplementedError, result_type
FormBoxWidgetInstance = FormBoxWidget()
FormBoxValidatorInstance = FormBoxValidator()
......
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