merge tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 29 Apr 2009 09:03:31 +0200
branchtls-sprint
changeset 1530 849fd3d64f11
parent 1525 cc2e2cbd7019 (current diff)
parent 1529 7d1794175e40 (diff)
child 1531 5fc1e6a15147
merge
web/form.py
--- a/rtags.py	Wed Apr 29 08:58:41 2009 +0200
+++ b/rtags.py	Wed Apr 29 09:03:31 2009 +0200
@@ -22,6 +22,9 @@
         self.use_set = use_set
         self._tagdefs = {}
 
+    def __repr__(self):
+        return repr(self._tagdefs)
+
     def set_rtag(self, tag, rtype, role, stype='*', otype='*'):
         assert not self.use_set
         assert role in ('subject', 'object'), role
--- a/web/form.py	Wed Apr 29 08:58:41 2009 +0200
+++ b/web/form.py	Wed Apr 29 09:03:31 2009 +0200
@@ -481,7 +481,7 @@
         """overriden to add edit[s|o] hidden fields and to ensure schema fields
         have eidparam set to True
 
-        edit[s|o] hidden fields are used t o indicate the value for the
+        edit[s|o] hidden fields are used to indicate the value for the
         associated field before the (potential) modification made when
         submitting the form.
         """
@@ -600,7 +600,7 @@
         """
         entity = self.edited_entity
         if isinstance(rtype, basestring):
-            rtype = self.schema.rschema(rtype)
+            rtype = entity.schema.rschema(rtype)
         done = None
         assert not rtype.is_final(), rtype
         if entity.has_eid():
@@ -622,7 +622,7 @@
         """
         entity = self.edited_entity
         if isinstance(rtype, basestring):
-            rtype = self.schema.rschema(rtype)
+            rtype = entity.schema.rschema(rtype)
         done = None
         if entity.has_eid():
             done = set(e.eid for e in getattr(entity, 'reverse_%s' % rtype))
--- a/web/views/autoform.py	Wed Apr 29 08:58:41 2009 +0200
+++ b/web/views/autoform.py	Wed Apr 29 09:03:31 2009 +0200
@@ -13,6 +13,8 @@
 from cubicweb.web.form import FieldNotFound, EntityFieldsForm
 from cubicweb.web.formfields import guess_field
 from cubicweb.web.formwidgets import Button, SubmitButton
+from cubicweb.web.views.editforms import toggleable_relation_link, relation_id
+
 _ = unicode
 
 class AutomaticEntityForm(EntityFieldsForm):
@@ -241,7 +243,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(
-            self.attrcategories, 'add') if rschema != 'eid']
+                self.attrcategories, 'add') if rschema != 'eid']
 
     def relations_table(self):
         """yiels 3-tuples (rtype, target, related_list)
@@ -256,9 +258,9 @@
         for label, rschema, role in self.srelations_by_category('generic', 'add'):
             relatedrset = entity.related(rschema, role, limit=self.related_limit)
             if rschema.has_perm(self.req, 'delete'):
-                toggable_rel_link_func = toggable_relation_link
+                toggleable_rel_link_func = toggleable_relation_link
             else:
-                toggable_rel_link_func = lambda x, y, z: u''
+                toggleable_rel_link_func = lambda x, y, z: u''
             related = []
             for row in xrange(relatedrset.rowcount):
                 nodeid = relation_id(entity.eid, rschema, role,
@@ -269,7 +271,7 @@
                 else:
                     status = u''
                     label = 'x'
-                dellink = toggable_rel_link_func(entity.eid, nodeid, label)
+                dellink = toggleable_rel_link_func(entity.eid, nodeid, label)
                 eview = self.view('oneline', relatedrset, row=row)
                 related.append((nodeid, dellink, status, eview))
             yield (rschema, role, related)
--- a/web/views/basecontrollers.py	Wed Apr 29 08:58:41 2009 +0200
+++ b/web/views/basecontrollers.py	Wed Apr 29 09:03:31 2009 +0200
@@ -44,6 +44,7 @@
         self.req.set_content_type('application/json')
         result = func(self, *args, **kwargs)
         return simplejson.dumps(result)
+    wrapper.__name__ = func.__name__
     return wrapper
 
 def xhtmlize(func):
@@ -52,6 +53,7 @@
         self.req.set_content_type(self.req.html_content_type())
         result = func(self, *args, **kwargs)
         return xhtml_wrap(result)
+    wrapper.__name__ = func.__name__
     return wrapper
 
 def check_pageid(func):
@@ -360,6 +362,9 @@
 
     @jsonize
     def js_validate_form(self, action, names, values):
+        return self.validate_form(action, names, values)
+
+    def validate_form(self, action, names, values):
         # XXX this method (and correspoding js calls) should use the new
         #     `RemoteCallFailed` mechansim
         self.req.form = self._rebuild_posted_form(names, values, action)
@@ -388,7 +393,7 @@
 
     @jsonize
     def js_edit_field(self, action, names, values, rtype, eid):
-        success, args = self.js_validate_form(action, names, values)
+        success, args = self.validate_form(action, names, values)
         if success:
             rset = self.req.execute('Any X,N WHERE X eid %%(x)s, X %s N' % rtype,
                                     {'x': eid}, 'x')
--- a/web/views/editforms.py	Wed Apr 29 08:58:41 2009 +0200
+++ b/web/views/editforms.py	Wed Apr 29 09:03:31 2009 +0200
@@ -33,7 +33,7 @@
         return u'%s:%s:%s' % (eid, rtype, reid)
     return u'%s:%s:%s' % (reid, rtype, eid)
 
-def toggable_relation_link(eid, nodeid, label='x'):
+def toggleable_relation_link(eid, nodeid, label='x'):
     """return javascript snippet to delete/undelete a relation between two
     entities
     """
--- a/web/views/editviews.py	Wed Apr 29 08:58:41 2009 +0200
+++ b/web/views/editviews.py	Wed Apr 29 09:03:31 2009 +0200
@@ -120,7 +120,7 @@
         pending_inserts = self.req.get_pending_inserts(eid)
         rtype = rschema.type
         form = self.vreg.select_object('forms', 'edition', self.req,
-                                       entity=entity)
+                                       self.rset, entity=entity)
         field = form.field_by_name(rschema, target, entity.e_schema)
         limit = self.req.property_value('navigation.combobox-limit')
         for eview, reid in form.form_field_vocabulary(field, limit):