merge tls-sprint
authorSandrine Ribeau <sandrine.ribeau@logilab.fr>
Wed, 06 May 2009 06:18:34 -0700
branchtls-sprint
changeset 1708 d96a88158b24
parent 1707 71b55db64269 (current diff)
parent 1704 d6f0e04d82bd (diff)
child 1709 f7110f533d14
merge
--- 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
--- 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):
--- 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'<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"""
--- 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('<span>(%s: %s)</span>'
                         % (req._('sample format'), example))
-	help.append(u'</div>')
+        help.append(u'</div>')
         return u'&nbsp;'.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)),
             }