web/views/autoform.py
changeset 6394 eb9a5bd778bc
parent 6101 1aff7367a20c
child 6401 d7f5d873e1b8
equal deleted inserted replaced
6391:e330ead0804b 6394:eb9a5bd778bc
   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             ttype = ttypes[0].type
   829             if self.should_inline_relation_form(rschema, ttype, role):
   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                     addnewlink = self._cw.vreg['views'].select(
   839                     'inline-addnew-link', self._cw,
   840                         'inline-addnew-link', self._cw,
   840                     etype=ttype, rtype=rschema, role=role, card=card,
   841                         etype=ttype, rtype=rschema, role=role, card=card,
   841                     peid=self.edited_entity.eid,
   842                         peid=self.edited_entity.eid,
   842                     petype=self.edited_entity.e_schema, pform=self)
   843                         petype=self.edited_entity.e_schema, pform=self)
   843                 formviews.append(addnewlink)
   844                     formviews.append(addnewlink)
   844             allformviews += formviews
   845                 allformviews += formviews
       
   846         return allformviews
   845         return allformviews
   847 
       
   848     def should_inline_relation_form(self, rschema, targettype, role):
       
   849         """return true if the given relation with entity has role and a
       
   850         targettype target should be inlined
       
   851 
       
   852         At this point we now relation has inlined_attributes tag (eg is returned
       
   853         by `inlined_relations()`. Overrides this for more finer control.
       
   854         """
       
   855         return True
       
   856 
   846 
   857     def should_display_inline_creation_form(self, rschema, existant, card):
   847     def should_display_inline_creation_form(self, rschema, existant, card):
   858         """return true if a creation form should be inlined
   848         """return true if a creation form should be inlined
   859 
   849 
   860         by default true if there is no related entity and we need at least one
   850         by default true if there is no related entity and we need at least one
   861         """
   851         """
   862         return not existant and card in '1+' or self._cw.form.has_key('force_%s_display' % rschema)
   852         return not existant and card in '1+'
   863 
   853 
   864     def should_display_add_new_relation_link(self, rschema, existant, card):
   854     def should_display_add_new_relation_link(self, rschema, existant, card):
   865         """return true if we should add a link to add a new creation form
   855         """return true if we should add a link to add a new creation form
   866         (through ajax call)
   856         (through ajax call)
   867 
   857