equal
deleted
inserted
replaced
10 from datetime import date, datetime |
10 from datetime import date, datetime |
11 |
11 |
12 from simplejson import dumps |
12 from simplejson import dumps |
13 |
13 |
14 from logilab.common.compat import any |
14 from logilab.common.compat import any |
|
15 from logilab.common.decorators import iclassmethod |
15 from logilab.mtconverter import html_escape |
16 from logilab.mtconverter import html_escape |
16 |
17 |
17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
18 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
18 |
19 |
19 from cubicweb import typed_eid |
20 from cubicweb import typed_eid |
770 value = req.form.get(param) |
771 value = req.form.get(param) |
771 if value: |
772 if value: |
772 self.form_add_hidden(param, initial=value) |
773 self.form_add_hidden(param, initial=value) |
773 self.buttons = buttons or [] |
774 self.buttons = buttons or [] |
774 self.context = None |
775 self.context = None |
775 |
776 |
|
777 @iclassmethod |
|
778 def field_by_name(cls_or_self, name): |
|
779 if isinstance(cls_or_self, type): |
|
780 fields = cls_or_self._fields_ |
|
781 else: |
|
782 fields = cls_or_self.fields |
|
783 for field in fields: |
|
784 if field.name == name: |
|
785 return field |
|
786 raise Exception('field %s not found' % name) |
|
787 |
776 @property |
788 @property |
777 def form_needs_multipart(self): |
789 def form_needs_multipart(self): |
778 return any(field.needs_multipart for field in self.fields) |
790 return any(field.needs_multipart for field in self.fields) |
779 |
791 |
780 def form_add_hidden(self, name, value=None, **kwargs): |
792 def form_add_hidden(self, name, value=None, **kwargs): |