16 from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity, |
16 from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity, |
17 specified_etype_implements, yes) |
17 specified_etype_implements, yes) |
18 from cubicweb.utils import make_uid |
18 from cubicweb.utils import make_uid |
19 from cubicweb.view import EntityView |
19 from cubicweb.view import EntityView |
20 from cubicweb.common import tags |
20 from cubicweb.common import tags |
21 from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs |
21 from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, eid_param |
22 from cubicweb.web.form import CompositeForm, EntityFieldsForm, FormViewMixIn |
22 from cubicweb.web.form import CompositeForm, EntityFieldsForm, FormViewMixIn |
23 from cubicweb.web.formwidgets import Button, SubmitButton, ResetButton |
23 from cubicweb.web.formwidgets import Button, SubmitButton, ResetButton |
24 from cubicweb.web.formrenderers import (FormRenderer, EntityFormRenderer, |
24 from cubicweb.web.formrenderers import (FormRenderer, EntityFormRenderer, |
25 EntityCompositeFormRenderer, |
25 EntityCompositeFormRenderer, |
26 EntityInlinedFormRenderer) |
26 EntityInlinedFormRenderer) |
226 id = 'copy' |
226 id = 'copy' |
227 def render_form(self, entity): |
227 def render_form(self, entity): |
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 self.newentity = copy(entity) |
232 self.newentity = copy(entity) |
232 self.copying = self.newentity.eid |
233 self.copying = self.newentity.eid |
233 self.newentity.eid = None |
234 self.initialize_varmaker() |
|
235 self.newentity.eid = self.varmaker.next() |
234 self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n' |
236 self.w(u'<script type="text/javascript">updateMessage("%s");</script>\n' |
235 % self.req._('Please note that this is only a shallow copy')) |
237 % self.req._('Please note that this is only a shallow copy')) |
236 super(CopyFormView, self).render_form(entity) |
238 super(CopyFormView, self).render_form(self.newentity) |
237 del self.newentity |
239 del self.newentity |
238 |
240 |
239 def init_form(self, form, entity): |
241 def init_form(self, form, entity): |
240 """customize your form before rendering here""" |
242 """customize your form before rendering here""" |
241 super(CopyFormView, self).init_form(form, entity) |
243 super(CopyFormView, self).init_form(form, entity) |
242 if entity.eid == self.newentity.eid: |
244 if entity.eid == self.newentity.eid: |
243 form.form_add_hidden('__cloned_eid', self.copying, eidparam=True) |
245 form.form_add_hidden(eid_param('__cloned_eid', entity.eid), self.copying) |
244 |
246 |
245 def submited_message(self): |
247 def submited_message(self): |
246 """return the message that will be displayed on successful edition""" |
248 """return the message that will be displayed on successful edition""" |
247 return self.req._('entity copied') |
249 return self.req._('entity copied') |
248 |
250 |