cleanup, various fix to get something working tls-sprint
authorsylvain.thenault@logilab.fr
Fri, 27 Mar 2009 12:31:42 +0100
branchtls-sprint
changeset 1181 620ec8e6ae19
parent 1180 5536d4ee2bc3
child 1182 78e4080252be
cleanup, various fix to get something working
view.py
web/__init__.py
web/box.py
web/formfields.py
web/formrenderers.py
web/test/unittest_form.py
web/views/baseforms.py
web/views/boxes.py
web/views/editviews.py
--- a/view.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/view.py	Fri Mar 27 12:31:42 2009 +0100
@@ -12,7 +12,7 @@
 from logilab.common.deprecation import obsolete
 from logilab.mtconverter import html_escape
 
-from cubicweb import NotAnEntity, NoSelectableObject
+from cubicweb import NotAnEntity
 from cubicweb.selectors import yes, non_final_entity, nonempty_rset, none_rset
 from cubicweb.selectors import require_group_compat, accepts_compat
 from cubicweb.appobject import AppRsetObject
--- a/web/__init__.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/web/__init__.py	Fri Mar 27 12:31:42 2009 +0100
@@ -3,7 +3,7 @@
 
 
 :organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 __docformat__ = "restructuredtext en"
@@ -35,12 +35,5 @@
 from logging import getLogger
 LOGGER = getLogger('cubicweb.web')
 
+# XXX deprecated
 FACETTES = set()
-
-
-## FACETTES = set( (
-##     # (relation, role, target's attribute)
-##     ('created_by', 'subject', 'login'),
-##     ('in_group', 'subject', 'name'),
-##     ('in_state', 'subject', 'name'),
-##     ))
--- a/web/box.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/web/box.py	Fri Mar 27 12:31:42 2009 +0100
@@ -38,7 +38,7 @@
     """
     __registry__ = 'boxes'
     __select__ = match_context_prop()
-    registered = require_group_compat(View.registered)
+    registered = classmethod(require_group_compat(View.registered))
     
     categories_in_order = ()
     property_defs = {
--- a/web/formfields.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/web/formfields.py	Fri Mar 27 12:31:42 2009 +0100
@@ -89,7 +89,13 @@
 
     def vocabulary(self, form):
         if self.choices is not None:
-            return self.choices
+            if callable(self.choices):
+                vocab = self.choices(req=form.req)
+            else:
+                vocab = self.choices
+            if vocab and not isinstance(vocab[0], (list, tuple)):
+                vocab = [(x, x) for x in vocab]
+            return vocab
         return form.form_field_vocabulary(self)
 
     
@@ -334,8 +340,8 @@
     field = None
     for cstr in constraints:
         if isinstance(cstr, StaticVocabularyConstraint):
-            kwargs.setdefault('widget', Select(vocabulary=cstr.vocabulary))
-            return StringField(**kwargs)
+            kwargs.setdefault('widget', Select())
+            return StringField(choices=cstr.vocabulary, **kwargs)
         if isinstance(cstr, SizeConstraint) and cstr.max is not None:
             if cstr.max > 257:
                 rows_cols_from_constraint(cstr, kwargs)
--- a/web/formrenderers.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/web/formrenderers.py	Fri Mar 27 12:31:42 2009 +0100
@@ -220,18 +220,21 @@
 class EntityFormRenderer(FormRenderer):
     """specific renderer for entity edition form (edition)"""
         
+    def render(self, form, values):
+        rendered = super(EntityFormRenderer, self).render(form, values)
+        return rendered + u'</div>' # close extra div introducted by open_form
+        
     def open_form(self, form, values):
         attrs_fs_label = ('<div class="iformTitle"><span>%s</span></div>'
                           % form.req._('main informations'))
         attrs_fs_label += '<div class="formBody">'
-        return super(EntityFormRenderer, self).open_form(form, values) + attrs_fs_label
+        return attrs_fs_label + super(EntityFormRenderer, self).open_form(form, values)
 
     def render_fields(self, w, form, values):
         super(EntityFormRenderer, self).render_fields(w, form, values)
         self.inline_entities_form(w, form)
         if form.edited_entity.has_eid():
             self.relations_form(w, form)
-        w(u'</div>') # close extra div introducted by open_form
 
     def _render_fields(self, fields, w, form, values):
         if not form.edited_entity.has_eid() or form.edited_entity.has_perm('update'):
--- a/web/test/unittest_form.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/web/test/unittest_form.py	Fri Mar 27 12:31:42 2009 +0100
@@ -17,6 +17,46 @@
         self.entity = self.user(self.req)
         self.renderer = FormRenderer()
         
+    # form view tests #########################################################
+        
+    def test_delete_conf_formview(self):
+        rset = self.execute('EGroup X')
+        self.view('deleteconf', rset, template=None).source
+        
+    def test_massmailing_formview(self):
+        self.execute('INSERT EmailAddress X: X address L + "@cubicweb.org", '
+                     'U use_email X WHERE U is EUser, U login L')
+        rset = self.execute('EUser X')
+        self.view('massmailing', rset, template=None)
+        
+    def test_automatic_edition_formview(self):
+        rset = self.execute('EUser X')
+        self.view('edition', rset, row=0, template=None).source
+        
+    def test_automatic_edition_formview(self):
+        rset = self.execute('EUser X')
+        self.view('copy', rset, row=0, template=None).source
+        
+    def test_automatic_creation_formview(self):
+        self.view('creation', None, etype='EUser', template=None).source
+        
+    def test_automatic_muledit_formview(self):
+        rset = self.execute('EUser X')
+        self.view('muledit', rset, template=None).source
+        
+    def test_automatic_reledit_formview(self):
+        rset = self.execute('EUser X')
+        self.view('reledit', rset, row=0, rtype='login', template=None).source
+        
+    def test_automatic_inline_edit_formview(self):
+        geid = self.execute('EGroup X LIMIT 1')[0][0]
+        rset = self.execute('EUser X LIMIT 1')
+        self.view('inline-edition', rset, row=0, rtype='in_group', peid=geid, template=None).source
+                              
+    def test_automatic_inline_creation_formview(self):
+        geid = self.execute('EGroup X LIMIT 1')[0][0]
+        self.view('inline-creation', None, etype='EUser', rtype='in_group', peid=geid, template=None).source
+
     # form tests ##############################################################
     
     def test_form_inheritance(self):
@@ -32,45 +72,13 @@
                                entity=self.entity)
         form.form_render(state=123, trcomment=u'')
         
-    def test_delete_conf_form_multi(self):
-        rset = self.execute('EGroup X')
-        self.view('deleteconf', rset, template=None).source
-        
-    def test_massmailing_form(self):
-        self.execute('INSERT EmailAddress X: X address L + "@cubicweb.org", '
-                     'U use_email X WHERE U is EUser, U login L')
-        rset = self.execute('EUser X')
-        self.view('massmailing', rset, template=None)
-        
-    def test_automatic_edition_form(self):
-        rset = self.execute('EUser X')
-        self.view('edition', rset, row=0, template=None).source
-        
-    def test_automatic_edition_form(self):
-        rset = self.execute('EUser X')
-        self.view('copy', rset, row=0, template=None).source
+    def test_edition_form(self):
+        rset = self.execute('EUser X LIMIT 1')
+        form = self.vreg.select_object('forms', 'edition', rset.req, rset, row=0, col=0)
+        # should be also selectable by specifying entity
+        self.vreg.select_object('forms', 'edition', self.request(), entity=rset.get_entity(0, 0))
+        self.failIf(any(f for f in form.fields if f is None))
         
-    def test_automatic_creation_form(self):
-        self.view('creation', None, etype='EUser', template=None).source
-        
-    def test_automatic_muledit_form(self):
-        rset = self.execute('EUser X')
-        self.view('muledit', rset, template=None).source
-        
-    def test_automatic_reledit_form(self):
-        rset = self.execute('EUser X')
-        self.view('reledit', rset, row=0, rtype='login', template=None).source
-        
-    def test_automatic_inline_edit_form(self):
-        geid = self.execute('EGroup X LIMIT 1')[0][0]
-        rset = self.execute('EUser X LIMIT 1')
-        self.view('inline-edition', rset, row=0, rtype='in_group', peid=geid, template=None).source
-                              
-    def test_automatic_inline_creation_form(self):
-        geid = self.execute('EGroup X LIMIT 1')[0][0]
-        self.view('inline-creation', None, etype='EUser', rtype='in_group', peid=geid, template=None).source
-
-
     # fields tests ############################################################
 
     def _render_entity_field(self, name, form):
--- a/web/views/baseforms.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/web/views/baseforms.py	Fri Mar 27 12:31:42 2009 +0100
@@ -327,7 +327,7 @@
     # should_* method extracted to allow overriding
     
     def should_inline_relation_form(self, entity, rschema, targettype, role):
-        return AutomaticForm.rinlined.etype_rtag(entity.id, role, rschema, targettype)
+        return AutomaticForm.rinlined.etype_rtag(entity.id, rschema, role, targettype)
 
     def should_display_inline_relation_form(self, rschema, existant, card):
         return not existant and card in '1+'
@@ -429,7 +429,7 @@
     def should_inline_relation_form(self, entity, rschema, targettype, role):
         if rschema == self.rschema:
             return False
-        return AutomaticForm.rinlined.etype_rtag(entity.id, role, rschema, targettype)
+        return AutomaticForm.rinlined.etype_rtag(entity.id, rschema, role, targettype)
 
     @cached
     def keep_entity(self, entity):
--- a/web/views/boxes.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/web/views/boxes.py	Fri Mar 27 12:31:42 2009 +0100
@@ -52,7 +52,7 @@
     @classmethod
     def registered(cls, registry):
         """build class using descriptor at registration time"""
-        super(AutomaticEntityForm, cls).registered(registry)
+        super(EditBox, cls).registered(registry)
         cls.init_rtags_mode()
         return cls
         
@@ -70,7 +70,7 @@
                     else:
                         X, Y = tschema, eschema
                         card = rschema.rproperty(X, Y, 'cardinality')[1]
-                    if not cls.rmode.rtag(role, rschema, X, Y):
+                    if not cls.rmode.rtag(rschema, role, X, Y):
                         if card in '?1':
                             # by default, suppose link mode if cardinality doesn't allow
                             # more than one relation
@@ -81,14 +81,14 @@
                         else:
                             # link mode by default
                             mode = 'link'
-                        cls.rmode.set_rtag(category, role, rschema, X, Y)
+                        cls.rmode.set_rtag(mode, rschema, role, X, Y)
 
     @classmethod
     def relation_mode(cls, rtype, etype, targettype, role='subject'):
         """return a string telling if the given relation is usually created
         to a new entity ('create' mode) or to an existant entity ('link' mode)
         """
-        return cls.rmode.rtag(role, rtype, etype, targettype)
+        return cls.rmode.rtag(rtype, role, etype, targettype)
 
 
     def call(self, **kwargs):
--- a/web/views/editviews.py	Fri Mar 27 12:30:59 2009 +0100
+++ b/web/views/editviews.py	Fri Mar 27 12:31:42 2009 +0100
@@ -17,7 +17,7 @@
                                 match_search_state, match_form_params)
 from cubicweb.common.uilib import cut
 from cubicweb.web.views import linksearch_select_url
-from cubicweb.web.views.editformss import relation_id
+from cubicweb.web.views.editforms import relation_id
 from cubicweb.web.views.baseviews import FinalView
 
 _ = unicode