Various forms2 changes
This commit is contained in:
parent
587871e87c
commit
1e8a4534d5
|
@ -360,12 +360,12 @@ class Form(object):
|
||||||
self.remove(*args)
|
self.remove(*args)
|
||||||
|
|
||||||
def make_schema(self):
|
def make_schema(self):
|
||||||
if not self.model_class:
|
|
||||||
# TODO
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
if not self.schema:
|
if not self.schema:
|
||||||
|
|
||||||
|
if not self.model_class:
|
||||||
|
# TODO
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
mapper = orm.class_mapper(self.model_class)
|
mapper = orm.class_mapper(self.model_class)
|
||||||
|
|
||||||
# first filter our "full" field list so we ignore certain ones. in
|
# first filter our "full" field list so we ignore certain ones. in
|
||||||
|
@ -438,6 +438,10 @@ class Form(object):
|
||||||
def set_label(self, key, label):
|
def set_label(self, key, label):
|
||||||
self.labels[key] = label
|
self.labels[key] = label
|
||||||
|
|
||||||
|
# update schema if necessary
|
||||||
|
if self.schema and key in self.schema:
|
||||||
|
self.schema[key].title = label
|
||||||
|
|
||||||
def get_label(self, key):
|
def get_label(self, key):
|
||||||
return self.labels.get(key, prettify(key))
|
return self.labels.get(key, prettify(key))
|
||||||
|
|
||||||
|
@ -498,6 +502,10 @@ class Form(object):
|
||||||
def set_widget(self, key, widget):
|
def set_widget(self, key, widget):
|
||||||
self.widgets[key] = widget
|
self.widgets[key] = widget
|
||||||
|
|
||||||
|
# update schema if necessary
|
||||||
|
if self.schema and key in self.schema:
|
||||||
|
self.schema[key].widget = widget
|
||||||
|
|
||||||
def set_validator(self, key, validator):
|
def set_validator(self, key, validator):
|
||||||
self.validators[key] = validator
|
self.validators[key] = validator
|
||||||
|
|
||||||
|
@ -659,8 +667,13 @@ class Form(object):
|
||||||
return getattr(record, field_name)
|
return getattr(record, field_name)
|
||||||
|
|
||||||
def validate(self, *args, **kwargs):
|
def validate(self, *args, **kwargs):
|
||||||
|
raise_error = kwargs.pop('raise_error', True)
|
||||||
form = self.make_deform_form()
|
form = self.make_deform_form()
|
||||||
return form.validate(*args, **kwargs)
|
try:
|
||||||
|
return form.validate(*args, **kwargs)
|
||||||
|
except deform.ValidationFailure:
|
||||||
|
if raise_error:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
class FieldList(list):
|
class FieldList(list):
|
||||||
|
|
|
@ -127,6 +127,17 @@
|
||||||
${self.extra_javascript()}
|
${self.extra_javascript()}
|
||||||
${self.core_styles()}
|
${self.core_styles()}
|
||||||
${self.extra_styles()}
|
${self.extra_styles()}
|
||||||
|
|
||||||
|
## TODO: should this be elsewhere / more customizable?
|
||||||
|
% if dform is not Undefined:
|
||||||
|
<% resources = dform.get_widget_resources() %>
|
||||||
|
% for path in resources['js']:
|
||||||
|
${h.javascript_link(request.static_url(path))}
|
||||||
|
% endfor
|
||||||
|
% for path in resources['css']:
|
||||||
|
${h.stylesheet_link(request.static_url(path))}
|
||||||
|
% endfor
|
||||||
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="core_javascript()">
|
<%def name="core_javascript()">
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
% if not readonly:
|
% if not readonly:
|
||||||
<% _focus_rendered = False %>
|
<% _focus_rendered = False %>
|
||||||
${h.form(form.action_url, id=dform.formid, method='post', enctype='multipart/form-data')}
|
${h.form(form.action_url, id=dform.formid, method='post', enctype='multipart/form-data', class_='autodisable')}
|
||||||
${h.csrf_token(request)}
|
${h.csrf_token(request)}
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
|
@ -26,7 +26,11 @@ ${h.csrf_token(request)}
|
||||||
## <div class="field-error">${error}</div>
|
## <div class="field-error">${error}</div>
|
||||||
## % endfor
|
## % endfor
|
||||||
% if field.error:
|
% if field.error:
|
||||||
<div class="field-error"><span class="error-msg">${field.error.msg}</span></div>
|
<div class="field-error">
|
||||||
|
% for msg in field.error.messages():
|
||||||
|
<span class="error-msg">${msg}</span>
|
||||||
|
% endfor
|
||||||
|
</div>
|
||||||
% endif
|
% endif
|
||||||
<div class="field-row">
|
<div class="field-row">
|
||||||
<label for="${field.oid}">${field.title}</label>
|
<label for="${field.oid}">${field.title}</label>
|
||||||
|
|
|
@ -6,15 +6,6 @@
|
||||||
<%def name="extra_javascript()">
|
<%def name="extra_javascript()">
|
||||||
${parent.extra_javascript()}
|
${parent.extra_javascript()}
|
||||||
${self.disable_button_js()}
|
${self.disable_button_js()}
|
||||||
% if dform is not Undefined:
|
|
||||||
<% resources = dform.get_widget_resources() %>
|
|
||||||
% for path in resources['js']:
|
|
||||||
${h.javascript_link(request.static_url(path))}
|
|
||||||
% endfor
|
|
||||||
% for path in resources['css']:
|
|
||||||
${h.stylesheet_link(request.static_url(path))}
|
|
||||||
% endfor
|
|
||||||
% endif
|
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="disable_button_js()">
|
<%def name="disable_button_js()">
|
||||||
|
|
|
@ -18,15 +18,6 @@
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
% if dform is not Undefined:
|
|
||||||
<% resources = dform.get_widget_resources() %>
|
|
||||||
% for path in resources['js']:
|
|
||||||
${h.javascript_link(request.static_url(path))}
|
|
||||||
% endfor
|
|
||||||
% for path in resources['css']:
|
|
||||||
${h.stylesheet_link(request.static_url(path))}
|
|
||||||
% endfor
|
|
||||||
% endif
|
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
<%def name="context_menu_items()">
|
||||||
|
|
Loading…
Reference in a new issue