# HG changeset patch # User Sandrine Ribeau # Date 1241615914 25200 # Node ID d96a88158b24e9f0e6f82e2025f1489888498d05 # Parent 71b55db6426936c4916ed6ca142b56c0190db645# Parent d6f0e04d82bd9e7cbc2b6a98596b24b912432b70 merge diff -r 71b55db64269 -r d96a88158b24 web/form.py --- a/web/form.py Wed May 06 03:29:33 2009 -0700 +++ b/web/form.py Wed May 06 06:18:34 2009 -0700 @@ -520,9 +520,7 @@ return INTERNAL_FIELD_VALUE if attr == '__type': return entity.id - if field.role == 'object': - attr = 'reverse_' + attr - elif entity.e_schema.subject_relation(attr).is_final(): + if self.schema.rschema(attr).is_final(): attrtype = entity.e_schema.destination(attr) if attrtype == 'Password': return entity.has_eid() and INTERNAL_FIELD_VALUE or '' @@ -533,14 +531,14 @@ # XXX value should reflect if some file is already attached return True return False - if entity.has_eid(): + if entity.has_eid() or attr in entity: value = getattr(entity, attr) else: value = self._form_field_default_value(field, load_bytes) return value # non final relation field - if entity.has_eid(): - value = [ent.eid for ent in getattr(entity, attr)] + if entity.has_eid() or entity.relation_cached(attr, field.role): + value = [r[0] for r in entity.related(attr, field.role)] else: value = self._form_field_default_value(field, load_bytes) return value diff -r 71b55db64269 -r d96a88158b24 web/views/autoform.py --- a/web/views/autoform.py Wed May 06 03:29:33 2009 -0700 +++ b/web/views/autoform.py Wed May 06 06:18:34 2009 -0700 @@ -5,6 +5,7 @@ :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" +_ = unicode from logilab.common.decorators import iclassmethod @@ -15,7 +16,6 @@ from cubicweb.web.formwidgets import Button, SubmitButton from cubicweb.web.views.editforms import toggleable_relation_link, relation_id -_ = unicode class AutomaticEntityForm(EntityFieldsForm): """base automatic form to edit any entity. @@ -244,7 +244,7 @@ def editable_attributes(self): """return a list of (relation schema, role) to edit for the entity""" - return [(rschema, x) for rschema, _, x in self.relations_by_category( + return [(rschema, role) for rschema, _, role in self.relations_by_category( self.attrcategories, 'add') if rschema != 'eid'] def relations_table(self): diff -r 71b55db64269 -r d96a88158b24 web/views/editforms.py --- a/web/views/editforms.py Wed May 06 03:29:33 2009 -0700 +++ b/web/views/editforms.py Wed May 06 06:18:34 2009 -0700 @@ -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'\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""" diff -r 71b55db64269 -r d96a88158b24 web/widgets.py --- a/web/widgets.py Wed May 06 03:29:33 2009 -0700 +++ b/web/widgets.py Wed May 06 06:18:34 2009 -0700 @@ -735,12 +735,12 @@ values = entity.attribute_values(self.name) if values and hasattr(values[0], 'strftime'): formatstr = entity.req.property_value(self.format_key) - return [values[0].strftime(formatstr)] + return [values[0].strftime(str(formatstr))] return values def render_example(self, req): formatstr = req.property_value(self.format_key) - return datetime.now().strftime(formatstr) + return datetime.now().strftime(str(formatstr)) def _edit_render(self, entity): @@ -759,7 +759,7 @@ if example: help.append('(%s: %s)' % (req._('sample format'), example)) - help.append(u'') + help.append(u'') return u' '.join(help) def render_calendar_popup(self, entity): @@ -791,8 +791,8 @@ formatstr1 = req.property_value('ui.datetime-format') formatstr2 = req.property_value('ui.date-format') return req._('%(fmt1)s, or without time: %(fmt2)s') % { - 'fmt1': datetime.now().strftime(formatstr1), - 'fmt2': datetime.now().strftime(formatstr2), + 'fmt1': datetime.now().strftime(str(formatstr1)), + 'fmt2': datetime.now().strftime(str(formatstr2)), }