71 from yams.schema import KNOWN_METAATTRIBUTES, role_name |
71 from yams.schema import KNOWN_METAATTRIBUTES, role_name |
72 from yams.constraints import (SizeConstraint, StaticVocabularyConstraint, |
72 from yams.constraints import (SizeConstraint, StaticVocabularyConstraint, |
73 FormatConstraint) |
73 FormatConstraint) |
74 |
74 |
75 from cubicweb import Binary, tags, uilib |
75 from cubicweb import Binary, tags, uilib |
|
76 from cubicweb.utils import support_args |
76 from cubicweb.web import INTERNAL_FIELD_VALUE, ProcessFormError, eid_param, \ |
77 from cubicweb.web import INTERNAL_FIELD_VALUE, ProcessFormError, eid_param, \ |
77 formwidgets as fw, uicfg |
78 formwidgets as fw, uicfg |
78 |
79 |
79 |
80 |
80 class UnmodifiedField(Exception): |
81 class UnmodifiedField(Exception): |
343 return self.initial_typed_value(form, load_bytes) |
344 return self.initial_typed_value(form, load_bytes) |
344 |
345 |
345 def initial_typed_value(self, form, load_bytes): |
346 def initial_typed_value(self, form, load_bytes): |
346 if self.value is not _MARKER: |
347 if self.value is not _MARKER: |
347 if callable(self.value): |
348 if callable(self.value): |
348 return self.value(form) |
349 if support_args(self.value, 'form', 'field'): |
|
350 return self.value(form, self) |
|
351 else: |
|
352 warn("[3.10] field's value callback must now take form and field as argument", |
|
353 DeprecationWarning) |
|
354 return self.value(form) |
349 return self.value |
355 return self.value |
350 formattr = '%s_%s_default' % (self.role, self.name) |
356 formattr = '%s_%s_default' % (self.role, self.name) |
351 if hasattr(form, formattr): |
357 if hasattr(form, formattr): |
352 warn('[3.6] %s.%s deprecated, use field.value' % ( |
358 warn('[3.6] %s.%s deprecated, use field.value' % ( |
353 form.__class__.__name__, formattr), DeprecationWarning) |
359 form.__class__.__name__, formattr), DeprecationWarning) |