cubicweb/web/views/autoform.py
changeset 11151 4259c55df3e7
parent 11145 d3edefdeddb4
parent 11129 97095348b3ee
child 11374 0e50215016f3
equal deleted inserted replaced
11144:fd8bf29ed00e 11151:4259c55df3e7
   897                 continue
   897                 continue
   898             tschema = ttypes[0]
   898             tschema = ttypes[0]
   899             ttype = tschema.type
   899             ttype = tschema.type
   900             formviews = list(self.inline_edition_form_view(rschema, ttype, role))
   900             formviews = list(self.inline_edition_form_view(rschema, ttype, role))
   901             card = rschema.role_rdef(entity.e_schema, ttype, role).role_cardinality(role)
   901             card = rschema.role_rdef(entity.e_schema, ttype, role).role_cardinality(role)
   902             related = entity.has_eid() and entity.related(rschema, role)
   902             existing = entity.related(rschema, role) if entity.has_eid() else formviews
   903             if self.should_display_inline_creation_form(rschema, related, card):
   903             if self.should_display_inline_creation_form(rschema, existing, card):
   904                 formviews += self.inline_creation_form_view(rschema, ttype, role)
   904                 formviews += self.inline_creation_form_view(rschema, ttype, role)
   905             # we can create more than one related entity, we thus display a link
   905             # we can create more than one related entity, we thus display a link
   906             # to add new related entities
   906             # to add new related entities
   907             if self.must_display_add_new_relation_link(rschema, role, tschema,
   907             if self.must_display_add_new_relation_link(rschema, role, tschema,
   908                                                        ttype, related, card):
   908                                                        ttype, existing, card):
   909                 addnewlink = self._cw.vreg['views'].select(
   909                 addnewlink = self._cw.vreg['views'].select(
   910                     'inline-addnew-link', self._cw,
   910                     'inline-addnew-link', self._cw,
   911                     etype=ttype, rtype=rschema, role=role, card=card,
   911                     etype=ttype, rtype=rschema, role=role, card=card,
   912                     peid=self.edited_entity.eid,
   912                     peid=self.edited_entity.eid,
   913                     petype=self.edited_entity.e_schema, pform=self)
   913                     petype=self.edited_entity.e_schema, pform=self)
   914                 formviews.append(addnewlink)
   914                 formviews.append(addnewlink)
   915             allformviews += formviews
   915             allformviews += formviews
   916         return allformviews
   916         return allformviews
   917 
   917 
   918     def should_display_inline_creation_form(self, rschema, existant, card):
   918     def should_display_inline_creation_form(self, rschema, existing, card):
   919         """return true if a creation form should be inlined
   919         """return true if a creation form should be inlined
   920 
   920 
   921         by default true if there is no related entity and we need at least one
   921         by default true if there is no related entity and we need at least one
   922         """
   922         """
   923         return not existant and card in '1+'
   923         return not existing and card in '1+'
   924 
   924 
   925     def should_display_add_new_relation_link(self, rschema, existant, card):
   925     def should_display_add_new_relation_link(self, rschema, existing, card):
   926         """return true if we should add a link to add a new creation form
   926         """return true if we should add a link to add a new creation form
   927         (through ajax call)
   927         (through ajax call)
   928 
   928 
   929         by default true if there is no related entity or if the relation has
   929         by default true if there is no related entity or if the relation has
   930         multiple cardinality
   930         multiple cardinality
   931         """
   931         """
   932         return not existant or card in '+*'
   932         return not existing or card in '+*'
   933 
   933 
   934     def must_display_add_new_relation_link(self, rschema, role, tschema,
   934     def must_display_add_new_relation_link(self, rschema, role, tschema,
   935                                            ttype, existant, card):
   935                                            ttype, existing, card):
   936         """return true if we must add a link to add a new creation form
   936         """return true if we must add a link to add a new creation form
   937         (through ajax call)
   937         (through ajax call)
   938 
   938 
   939         by default true if there is no related entity or if the relation has
   939         by default true if there is no related entity or if the relation has
   940         multiple cardinality and it is permitted to add the inlined object and
   940         multiple cardinality and it is permitted to add the inlined object and
   941         relation.
   941         relation.
   942         """
   942         """
   943         return (self.should_display_add_new_relation_link(
   943         return (self.should_display_add_new_relation_link(
   944                     rschema, existant, card) and
   944                     rschema, existing, card) and
   945                 self.check_inlined_rdef_permissions(
   945                 self.check_inlined_rdef_permissions(
   946                     rschema, role, tschema, ttype))
   946                     rschema, role, tschema, ttype))
   947 
   947 
   948     def check_inlined_rdef_permissions(self, rschema, role, tschema, ttype):
   948     def check_inlined_rdef_permissions(self, rschema, role, tschema, ttype):
   949         """return true if permissions are granted on the inlined object and
   949         """return true if permissions are granted on the inlined object and