web/views/autoform.py
changeset 6577 0d9ea7f93065
parent 6576 481249ecdc4f
child 6630 f516ee1ef36c
equal deleted inserted replaced
6576:481249ecdc4f 6577:0d9ea7f93065
   823             if len(ttypes) != 1:
   823             if len(ttypes) != 1:
   824                 self.warning('entity related by the %s relation should have '
   824                 self.warning('entity related by the %s relation should have '
   825                              'inlined form but there is multiple target types, '
   825                              'inlined form but there is multiple target types, '
   826                              'dunno what to do', rschema)
   826                              'dunno what to do', rschema)
   827                 continue
   827                 continue
   828             ttype = ttypes[0].type
   828             tschema = ttypes[0]
       
   829             ttype = tschema.type
   829             formviews = list(self.inline_edition_form_view(rschema, ttype, role))
   830             formviews = list(self.inline_edition_form_view(rschema, ttype, role))
   830             card = rschema.role_rdef(entity.e_schema, ttype, role).role_cardinality(role)
   831             card = rschema.role_rdef(entity.e_schema, ttype, role).role_cardinality(role)
   831             # there is no related entity and we need at least one: we need to
   832             # there is no related entity and we need at least one: we need to
   832             # display one explicit inline-creation view
   833             # display one explicit inline-creation view
   833             if self.should_display_inline_creation_form(rschema, formviews, card):
   834             if self.should_display_inline_creation_form(rschema, formviews, card):
   834                 formviews += self.inline_creation_form_view(rschema, ttype, role)
   835                 formviews += self.inline_creation_form_view(rschema, ttype, role)
   835             # we can create more than one related entity, we thus display a link
   836             # we can create more than one related entity, we thus display a link
   836             # to add new related entities
   837             # to add new related entities
   837             if self.should_display_add_new_relation_link(rschema, formviews, card):
   838             if self.should_display_add_new_relation_link(rschema, formviews, card):
   838                 addnewlink = self._cw.vreg['views'].select(
   839                 rdef = entity.e_schema.rdef(rschema, role, ttype)
   839                     'inline-addnew-link', self._cw,
   840                 if role == 'subject':
   840                     etype=ttype, rtype=rschema, role=role, card=card,
   841                     rdefkwargs = {'fromeid': entity.eid}
   841                     peid=self.edited_entity.eid,
   842                 else:
   842                     petype=self.edited_entity.e_schema, pform=self)
   843                     rdefkwargs = {'toeid': entity.eid}
   843                 formviews.append(addnewlink)
   844                 if (tschema.has_perm(self._cw, 'add')
       
   845                     and rdef.has_perm(self._cw, 'add', **rdefkwargs)):
       
   846                     addnewlink = self._cw.vreg['views'].select(
       
   847                         'inline-addnew-link', self._cw,
       
   848                         etype=ttype, rtype=rschema, role=role, card=card,
       
   849                         peid=self.edited_entity.eid,
       
   850                         petype=self.edited_entity.e_schema, pform=self)
       
   851                     formviews.append(addnewlink)
   844             allformviews += formviews
   852             allformviews += formviews
   845         return allformviews
   853         return allformviews
   846 
   854 
   847     def should_display_inline_creation_form(self, rschema, existant, card):
   855     def should_display_inline_creation_form(self, rschema, existant, card):
   848         """return true if a creation form should be inlined
   856         """return true if a creation form should be inlined
   856         (through ajax call)
   864         (through ajax call)
   857 
   865 
   858         by default true if there is no related entity or if the relation has
   866         by default true if there is no related entity or if the relation has
   859         multiple cardinality
   867         multiple cardinality
   860         """
   868         """
   861         return not existant or card in '+*' # XXX add target type permisssions
   869         return not existant or card in '+*'
   862 
   870 
   863     def should_hide_add_new_relation_link(self, rschema, card):
   871     def should_hide_add_new_relation_link(self, rschema, card):
   864         """return true if once an inlined creation form is added, the 'add new'
   872         """return true if once an inlined creation form is added, the 'add new'
   865         link should be hidden
   873         link should be hidden
   866 
   874