# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1239273420 -7200 # Node ID 9cff1eee0208c4e1d0bf916de79ef2f9ffb967a1 # Parent df7f847e13888d0e1032211d6785b50850f812c7 put class, not class name into rwidgets. New rfields rtags to specify a field for a relation diff -r df7f847e1388 -r 9cff1eee0208 entity.py --- a/entity.py Thu Apr 09 12:35:03 2009 +0200 +++ b/entity.py Thu Apr 09 12:37:00 2009 +0200 @@ -45,6 +45,7 @@ CATEGORY_TAGS = set(('primary', 'secondary', 'generic', 'generated')) # , 'metadata')) try: + from cubicweb.web import formwidgets from cubicweb.web.views.editforms import AutomaticEntityForm from cubicweb.web.views.boxes import EditBox @@ -127,6 +128,9 @@ if wdgname in ('URLWidget', 'EmbededURLWidget'): warn('%s widget is deprecated' % wdgname, DeprecationWarning) continue + if wdgname == 'StringWidget': + wdgname = 'TextInput' + widget = getattr(formwidgets, wdgname) AutomaticEntityForm.rwidgets.set_rtag(wdgname, rtype, 'subject', etype) return super(metaentity, mcs).__new__(mcs, name, bases, classdict) diff -r df7f847e1388 -r 9cff1eee0208 web/uicfg.py --- a/web/uicfg.py Thu Apr 09 12:35:03 2009 +0200 +++ b/web/uicfg.py Thu Apr 09 12:37:00 2009 +0200 @@ -36,7 +36,10 @@ rcategories.set_rtag('generated', 'for_user', 'subject') rcategories.set_rtag('generated', 'for_user', 'object') -# relations'widget (eg one of available class name in cubicweb.web.formwidgets) +# relations'field class +rfields = RelationTags() + +# relations'widget class rwidgets = RelationTags() # inlined view flag for non final relations: when True for an entry, the diff -r df7f847e1388 -r 9cff1eee0208 web/views/editforms.py --- a/web/views/editforms.py Thu Apr 09 12:35:03 2009 +0200 +++ b/web/views/editforms.py Thu Apr 09 12:37:00 2009 +0200 @@ -20,7 +20,7 @@ from cubicweb.utils import make_uid from cubicweb.view import EntityView from cubicweb.common import tags -from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, formwidgets, uicfg +from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, uicfg from cubicweb.web.form import (FieldNotFound, CompositeForm, EntityFieldsForm, FormMixIn) from cubicweb.web.formfields import guess_field @@ -103,7 +103,6 @@ if not entity.has_perm('update'): self.w(value) return - self.req.add_js( ('cubicweb.ajax.js',) ) eid = entity.eid edit_key = make_uid('%s-%s' % (rtype, eid)) divid = 'd%s' % edit_key @@ -127,15 +126,14 @@ """base automatic form to edit any entity Designed to be flly generated from schema but highly configurable through: - * rtags (rcategories, rwidgets, inlined, rpermissions) + * rtags (rcategories, rfields, rwidgets, inlined, rpermissions) * various standard form parameters You can also easily customise it by adding/removing fields in AutomaticEntityForm instances. """ id = 'edition' - - needs_js = EntityFieldsForm.needs_js + ('cubicweb.ajax.js',) + cwtarget = 'eformframe' cssclass = 'entityForm' copy_nav_params = True @@ -146,6 +144,7 @@ # class attributes below are actually stored in the uicfg module since we # don't want them to be reloaded rcategories = uicfg.rcategories + rfields = uicfg.rfields rwidgets = uicfg.rwidgets rinlined = uicfg.rinlined rpermissions_overrides = uicfg.rpermissions_overrides @@ -282,10 +281,15 @@ continue # explicitly specified except FieldNotFound: pass # has to be guessed - wdgname = self.rwidgets.etype_rtag(self.edited_entity.id, rschema, + fieldcls = self.rfields.etype_rtag(self.edited_entity.id, rschema, role) - if wdgname: - widget = getattr(formwidgets, wdgname) + if fieldcls: + field = fieldcls(name=rschema.type, role=role, eidparam=True) + self.fields.append(field) + continue + widget = self.rwidgets.etype_rtag(self.edited_entity.id, rschema, + role) + if widget: field = guess_field(self.edited_entity.__class__, rschema, role, eidparam=True, widget=widget) else: