web/views/editforms.py
branchtls-sprint
changeset 1703 a2b5dfdb4b62
parent 1692 56009f2101fe
child 1710 8c717cc0b353
equal deleted inserted replaced
1702:312310ed8a2f 1703:a2b5dfdb4b62
   228         """fetch and render the form"""
   228         """fetch and render the form"""
   229         # make a copy of entity to avoid altering the entity in the
   229         # make a copy of entity to avoid altering the entity in the
   230         # request's cache.
   230         # request's cache.
   231         entity.complete()
   231         entity.complete()
   232         self.newentity = copy(entity)
   232         self.newentity = copy(entity)
   233         self.copying = self.newentity.eid
   233         self.copying = entity
   234         self.initialize_varmaker()
   234         self.initialize_varmaker()
   235         self.newentity.eid = self.varmaker.next()
   235         self.newentity.eid = self.varmaker.next()
   236         self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n'
   236         self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n'
   237                % self.req._('Please note that this is only a shallow copy'))
   237                % self.req._('Please note that this is only a shallow copy'))
   238         super(CopyFormView, self).render_form(self.newentity)
   238         super(CopyFormView, self).render_form(self.newentity)
   240 
   240 
   241     def init_form(self, form, entity):
   241     def init_form(self, form, entity):
   242         """customize your form before rendering here"""
   242         """customize your form before rendering here"""
   243         super(CopyFormView, self).init_form(form, entity)
   243         super(CopyFormView, self).init_form(form, entity)
   244         if entity.eid == self.newentity.eid:
   244         if entity.eid == self.newentity.eid:
   245             form.form_add_hidden(eid_param('__cloned_eid', entity.eid), self.copying)
   245             form.form_add_hidden(eid_param('__cloned_eid', entity.eid),
       
   246                                  self.copying.eid)
       
   247         for rschema, _, role in form.relations_by_category(form.attrcategories,
       
   248                                                            'add'):
       
   249             if not rschema.is_final():
       
   250                 # ensure relation cache is filed
       
   251                 rset = self.copying.related(rschema, role)
       
   252                 self.newentity.set_related_cache(rschema, role, rset)
   246 
   253 
   247     def submited_message(self):
   254     def submited_message(self):
   248         """return the message that will be displayed on successful edition"""
   255         """return the message that will be displayed on successful edition"""
   249         return self.req._('entity copied')
   256         return self.req._('entity copied')
   250 
   257