[selectors] new logged_user_in_rset selector stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 07 May 2010 20:07:54 +0200
branchstable
changeset 5502 c342531032a1
parent 5501 1af69779f597
child 5503 5b7eb0839da3
[selectors] new logged_user_in_rset selector
selectors.py
web/views/cwproperties.py
--- a/selectors.py	Fri May 07 16:50:09 2010 +0200
+++ b/selectors.py	Fri May 07 20:07:54 2010 +0200
@@ -689,6 +689,16 @@
         return rset and self.match_expected(len(rset.column_types(col))) or 0
 
 
+@objectify_selector
+def logged_user_in_rset(cls, req, rset=None, row=None, col=0, **kwargs):
+    """Return positive score if the result set at the specified row / col
+    contains the eid of the logged user.
+    """
+    if rset is None:
+        return 0
+    return req.user.eid == rset[row or 0][col]
+
+
 # entity selectors #############################################################
 
 class non_final_entity(EClassSelector):
--- a/web/views/cwproperties.py	Fri May 07 16:50:09 2010 +0200
+++ b/web/views/cwproperties.py	Fri May 07 20:07:54 2010 +0200
@@ -27,12 +27,14 @@
 
 from cubicweb import UnknownProperty
 from cubicweb.selectors import (one_line_rset, none_rset, implements,
-                                match_user_groups, objectify_selector)
+                                match_user_groups, objectify_selector,
+                                logged_user_in_rset)
 from cubicweb.view import StartupView
 from cubicweb.web import uicfg, stdmsgs
 from cubicweb.web.form import FormViewMixIn
 from cubicweb.web.formfields import FIELDS, StringField
-from cubicweb.web.formwidgets import Select, TextInput, Button, SubmitButton, FieldWidget
+from cubicweb.web.formwidgets import (Select, TextInput, Button, SubmitButton,
+                                      FieldWidget)
 from cubicweb.web.views import primary, formrenderers
 
 uicfg.primaryview_section.tag_object_of(('*', 'for_user', '*'), 'hidden')
@@ -233,17 +235,12 @@
         return subform
 
 
-@objectify_selector
-def is_user_prefs(cls, req, rset=None, row=None, col=0, **kwargs):
-    return req.user.eid == rset[row or 0][col]
-
-
 class CWPropertiesForm(SystemCWPropertiesForm):
     """user's preferences properties edition form"""
     __regid__ = 'propertiesform'
     __select__ = (
         (none_rset() & match_user_groups('users','managers'))
-        | (one_line_rset() & match_user_groups('users') & is_user_prefs())
+        | (one_line_rset() & match_user_groups('users') & logged_user_in_rset())
         | (one_line_rset() & match_user_groups('managers') & implements('CWUser'))
         )