--- a/web/views/formrenderers.py Tue Sep 29 12:44:06 2009 +0200
+++ b/web/views/formrenderers.py Tue Sep 29 12:44:50 2009 +0200
@@ -474,51 +474,23 @@
def inline_entities_form(self, w, form):
"""create a form to edit entity's inlined relations"""
- if not hasattr(form, 'inlined_relations'):
+ if not hasattr(form, 'inlined_form_views'):
return
- for rschema, targettypes, role in form.inlined_relations():
- # show inline forms only if there's one possible target type
- # for rschema
- if len(targettypes) != 1:
- self.warning('entity related by the %s relation should have '
- 'inlined form but there is multiple target types, '
- 'dunno what to do', rschema)
- continue
- targettype = targettypes[0].type
- if form.should_inline_relation_form(rschema, targettype, role):
- self.inline_relation_form(w, form, rschema, targettype, role)
+ keysinorder = []
+ formviews = form.inlined_form_views()
+ for formview in formviews:
+ if not (formview.rtype, formview.role) in keysinorder:
+ keysinorder.append( (formview.rtype, formview.role) )
+ for key in keysinorder:
+ self.inline_relation_form(w, form, [fv for fv in formviews
+ if (fv.rtype, fv.role) == key])
- def inline_relation_form(self, w, form, rschema, targettype, role):
- entity = form.edited_entity
- __ = self.req.pgettext
- i18nctx = 'inlined:%s.%s.%s' % (entity.e_schema, rschema, role)
- w(u'<div id="inline%sslot">' % rschema)
- existant = form.display_inline_edition_form(w, rschema, targettype,
- role, i18nctx)
- if role == 'subject':
- card = rschema.rproperty(entity.e_schema, targettype, 'cardinality')[0]
- else:
- card = rschema.rproperty(targettype, entity.e_schema, 'cardinality')[1]
- # there is no related entity and we need at least one: we need to
- # display one explicit inline-creation view
- if form.should_display_inline_creation_form(rschema, existant, card):
- form.display_inline_creation_form(w, rschema, targettype,
- role, i18nctx)
- existant = True
- # we can create more than one related entity, we thus display a link
- # to add new related entities
- if form.should_display_add_new_relation_link(rschema, existant, card):
- divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid)
- w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">'
- % divid)
- js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s')" % (
- entity.eid, targettype, rschema, role, i18nctx)
- if form.should_hide_add_new_relation_link(rschema, card):
- js = "toggleVisibility('%s'); %s" % (divid, js)
- w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
- % (rschema, entity.eid, js, __(i18nctx, 'add a %s' % targettype)))
- w(u'</div>')
- w(u'<div class="trame_grise"> </div>')
+ def inline_relation_form(self, w, form, formviews):
+ i18nctx = 'inlined:%s.%s.%s' % (form.edited_entity.e_schema,
+ formviews[0].rtype, formviews[0].role)
+ w(u'<div id="inline%sslot">' % formviews[0].rtype)
+ for formview in formviews:
+ w(formview.render(i18nctx=i18nctx, row=formview.row, col=formview.col))
w(u'</div>')