15 from logilab.mtconverter import html_escape |
15 from logilab.mtconverter import html_escape |
16 |
16 |
17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
17 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
18 |
18 |
19 from cubicweb import typed_eid |
19 from cubicweb import typed_eid |
|
20 from cubicweb.appobject import AppObject |
20 from cubicweb.utils import ustrftime |
21 from cubicweb.utils import ustrftime |
21 from cubicweb.selectors import match_form_params |
22 from cubicweb.selectors import yes, match_form_params, non_final_entity |
22 from cubicweb.view import NOINDEX, NOFOLLOW, View, EntityView, AnyRsetView |
23 from cubicweb.view import NOINDEX, NOFOLLOW, View, EntityView, AnyRsetView |
23 from cubicweb.common.registerers import accepts_registerer |
24 from cubicweb.common.registerers import accepts_registerer |
24 from cubicweb.common.uilib import toggle_action |
25 from cubicweb.common.uilib import toggle_action |
25 from cubicweb.web import stdmsgs |
26 from cubicweb.web import stdmsgs |
26 from cubicweb.web.httpcache import NoHTTPCacheManager |
27 from cubicweb.web.httpcache import NoHTTPCacheManager |
716 allfields.append(field) |
717 allfields.append(field) |
717 classdict['_fields_'] = allfields |
718 classdict['_fields_'] = allfields |
718 return super(metafieldsform, mcs).__new__(mcs, name, bases, classdict) |
719 return super(metafieldsform, mcs).__new__(mcs, name, bases, classdict) |
719 |
720 |
720 |
721 |
721 class FieldsForm(FormMixIn): |
722 class FieldsForm(FormMixIn, AppObject): |
722 __metaclass__ = metafieldsform |
723 __metaclass__ = metafieldsform |
723 |
724 __registry__ = 'forms' |
724 def __init__(self, req, domid=None, title=None, action='edit', |
725 __select__ = yes() |
725 onsubmit="return freezeFormButtons('%s');", |
726 |
|
727 def __init__(self, req, rset=None, domid=None, title=None, action='edit', |
|
728 onsubmit="return freezeFormButtons('%(domid)s');", |
726 cssclass=None, cssstyle=None, cwtarget=None, buttons=None, |
729 cssclass=None, cssstyle=None, cwtarget=None, buttons=None, |
727 redirect_path=None, set_error_url=True, copy_nav_params=False): |
730 redirect_path=None, set_error_url=True, copy_nav_params=False): |
728 self.req = req |
731 self.req = req |
|
732 self.rset = rset |
729 self.config = req.vreg.config |
733 self.config = req.vreg.config |
730 self.domid = domid or 'form' |
734 self.domid = domid or 'form' |
731 self.title = title |
735 self.title = title |
732 self.action = action |
736 self.action = action |
733 self.onsubmit = onsubmit |
737 self.onsubmit = onsubmit |
803 def form_buttons(self): |
807 def form_buttons(self): |
804 return self.buttons |
808 return self.buttons |
805 |
809 |
806 |
810 |
807 class EntityFieldsForm(FieldsForm): |
811 class EntityFieldsForm(FieldsForm): |
|
812 __select__ = non_final_entity() |
808 |
813 |
809 def __init__(self, *args, **kwargs): |
814 def __init__(self, *args, **kwargs): |
810 kwargs.setdefault('domid', 'entityForm') |
815 kwargs.setdefault('domid', 'entityForm') |
811 self.entity = kwargs.pop('entity', None) |
816 self.entity = kwargs.pop('entity', None) |
812 super(EntityFieldsForm, self).__init__(*args, **kwargs) |
817 super(EntityFieldsForm, self).__init__(*args, **kwargs) |