should prefill cached values for relation in the primary or secondary category tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 06 May 2009 09:47:50 +0200
branchtls-sprint
changeset 1703 a2b5dfdb4b62
parent 1702 312310ed8a2f
child 1704 d6f0e04d82bd
should prefill cached values for relation in the primary or secondary category
web/views/editforms.py
--- a/web/views/editforms.py	Wed May 06 09:46:36 2009 +0200
+++ b/web/views/editforms.py	Wed May 06 09:47:50 2009 +0200
@@ -230,7 +230,7 @@
         # request's cache.
         entity.complete()
         self.newentity = copy(entity)
-        self.copying = self.newentity.eid
+        self.copying = entity
         self.initialize_varmaker()
         self.newentity.eid = self.varmaker.next()
         self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n'
@@ -242,7 +242,14 @@
         """customize your form before rendering here"""
         super(CopyFormView, self).init_form(form, entity)
         if entity.eid == self.newentity.eid:
-            form.form_add_hidden(eid_param('__cloned_eid', entity.eid), self.copying)
+            form.form_add_hidden(eid_param('__cloned_eid', entity.eid),
+                                 self.copying.eid)
+        for rschema, _, role in form.relations_by_category(form.attrcategories,
+                                                           'add'):
+            if not rschema.is_final():
+                # ensure relation cache is filed
+                rset = self.copying.related(rschema, role)
+                self.newentity.set_related_cache(rschema, role, rset)
 
     def submited_message(self):
         """return the message that will be displayed on successful edition"""