web/views/forms.py
changeset 7889 6cebeb1f386a
parent 7875 65e460690139
child 7929 900f1627b171
equal deleted inserted replaced
7882:974a8653aede 7889:6cebeb1f386a
   384         if msg:
   384         if msg:
   385             msgid = self._cw.set_redirect_message(msg)
   385             msgid = self._cw.set_redirect_message(msg)
   386             self.add_hidden('_cwmsgid', msgid)
   386             self.add_hidden('_cwmsgid', msgid)
   387 
   387 
   388     def add_linkto_hidden(self):
   388     def add_linkto_hidden(self):
   389         '''add the __linkto hidden field used to directly attach the new object
   389         """add the __linkto hidden field used to directly attach the new object
   390         to an existing other one when the relation between those two is not
   390         to an existing other one when the relation between those two is not
   391         already present in the form.
   391         already present in the form.
   392         Warning: this method must be called only when all form fields are setup'''
   392 
   393         # if current form is not the main form, exit immediately
   393         Warning: this method must be called only when all form fields are setup
   394         try:
   394         """
   395             self.field_by_name('__maineid')
       
   396         except form.FieldNotFound:
       
   397             return
       
   398         for (rtype, role), eids in self.linked_to.iteritems():
   395         for (rtype, role), eids in self.linked_to.iteritems():
   399             # if the relation is already setup by a form field, do not add it
   396             # if the relation is already setup by a form field, do not add it
   400             # in a __linkto hidden to avoid setting it twice in the controller
   397             # in a __linkto hidden to avoid setting it twice in the controller
   401             try:
   398             try:
   402                 self.field_by_name(rtype, role)
   399                 self.field_by_name(rtype, role)
   409         return super(EntityFieldsForm, self).render(*args, **kwargs)
   406         return super(EntityFieldsForm, self).render(*args, **kwargs)
   410 
   407 
   411     @property
   408     @property
   412     @cached
   409     @cached
   413     def linked_to(self):
   410     def linked_to(self):
       
   411         # if current form is not the main form, exit immediately
       
   412         try:
       
   413             self.field_by_name('__maineid')
       
   414         except form.FieldNotFound:
       
   415             return {}
   414         linked_to = {}
   416         linked_to = {}
   415         for linkto in self._cw.list_form_param('__linkto'):
   417         for linkto in self._cw.list_form_param('__linkto'):
   416             ltrtype, eid, ltrole = linkto.split(':')
   418             ltrtype, eid, ltrole = linkto.split(':')
   417             linked_to.setdefault((ltrtype, ltrole), []).append(typed_eid(eid))
   419             linked_to.setdefault((ltrtype, ltrole), []).append(typed_eid(eid))
   418         return linked_to
   420         return linked_to