[admin ui] nicer views for users/groups management
authorCharles Hébert <charles.hebert@logilab.fr>
Tue, 08 Feb 2011 14:18:18 +0100
changeset 6950 8a17e6e34f0f
parent 6949 267ce7cf77f1
child 6951 cb6314b09e0f
[admin ui] nicer views for users/groups management
web/data/add_button.png
web/data/cubicweb.css
web/data/cubicweb.old.css
web/views/cwuser.py
web/views/urlrewrite.py
Binary file web/data/add_button.png has changed
--- a/web/data/cubicweb.css	Tue Feb 08 14:16:41 2011 +0100
+++ b/web/data/cubicweb.css	Tue Feb 08 14:18:18 2011 +0100
@@ -598,6 +598,10 @@
 }
 
 /* pagination */
+
+div.pagination{
+  margin: 0.5em 0;
+}
 span.slice a:visited,
 span.slice a:hover{
   color: %(helperColor)s;
@@ -752,7 +756,7 @@
 table.listing th {
   font-weight: bold;
   font-size: 8pt;
-  background: %(listingHeaderBgColor)s; 
+  background: %(listingHeaderBgColor)s;
   padding: 2px 4px;
   border: 1px solid %(listingBorderColor)s;
   border-right:none;
@@ -881,6 +885,12 @@
   background-color: transparent;
 }
 
+a.addButton {
+  margin-left: 0.5em;
+  padding-left: 16px;
+  background: transparent url("add_button.png") 0% 50% no-repeat;
+}
+
 /***************************************/
 /* lists                               */
 /***************************************/
--- a/web/data/cubicweb.old.css	Tue Feb 08 14:16:41 2011 +0100
+++ b/web/data/cubicweb.old.css	Tue Feb 08 14:18:18 2011 +0100
@@ -602,6 +602,10 @@
   border-bottom: 1px solid #ccc;
 }
 
+div.pagination{
+  margin: 0.5em 0;
+}
+
 span.slice a:visited,
 span.slice a:hover{
   color: #555544;
@@ -899,6 +903,12 @@
   background-color: transparent;
 }
 
+a.addButton {
+  margin-left: 0.5em;
+  padding-left: 16px;
+  background: transparent url("add_button.png") 0% 50% no-repeat;
+}
+
 /***************************************/
 /* footer                              */
 /***************************************/
--- a/web/views/cwuser.py	Tue Feb 08 14:16:41 2011 +0100
+++ b/web/views/cwuser.py	Tue Feb 08 14:18:18 2011 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -24,10 +24,11 @@
 
 from logilab.mtconverter import xml_escape
 
+from cubicweb.schema import display_name
 from cubicweb.selectors import one_line_rset, is_instance, match_user_groups
-from cubicweb.view import EntityView
+from cubicweb.view import EntityView, StartupView
 from cubicweb.web import action, uicfg, formwidgets
-from cubicweb.web.views import tabs
+from cubicweb.web.views import tabs, tableview, actions
 
 _pvs = uicfg.primaryview_section
 _pvs.tag_attribute(('CWUser', 'login'), 'hidden')
@@ -157,3 +158,50 @@
         entity = self.cw_rset.complete_entity(row, col)
         self.w(u'<a href="%s" class="%s">%s</a>' % (
             entity.absolute_url(), entity.name, entity.printable_value('name')))
+
+
+# user / groups management views ###############################################
+
+class ManageUsersAction(actions.ManagersAction):
+    __regid__ = 'cwuser' # see rewrite rule /cwuser
+    title = _('users management')
+    category = 'manage'
+
+
+class CWUserManagementView(StartupView):
+    __regid__ = 'cw.user-management'
+    rql = ('Any U, F, S, U, L ORDERBY L WHERE U is CWUser, U login L, U firstname F, U surname S')
+    title = _('users management')
+
+    def call(self, **kwargs):
+        self.w('<h1>%s</h1>' % self._cw._(self.title))
+        for etype in ('CWUser', 'CWGroup'):
+            eschema = self._cw.vreg.schema.eschema(etype)
+            if eschema.has_perm(self._cw, 'add'):
+                self.w(u'<a href="%s" class="addButton right">%s</a>' % (
+                    self._cw.build_url('add/%s' % eschema),
+                    self._cw._('add a %s' % etype).capitalize()))
+        self.w(u'<div class="clear"></div>')
+        self.wview('cw.user-table', self._cw.execute(self.rql))
+
+
+class CWUserTable(tableview.EditableTableView):
+    __regid__ = 'cw.user-table'
+    __select__ = is_instance('CWUser')
+
+    def call(self, **kwargs):
+        headers = (display_name(self._cw, 'CWUser', 'plural'),
+                   self._cw._('firstname'), self._cw._('surname'),
+                   display_name(self._cw, 'CWGroup', 'plural'))
+        super(CWUserTable, self).call(
+            paginate=True, cellvids={3: 'cw.user-table.group-cell'},
+            headers=headers, **kwargs)
+
+
+class CWUserGroupCell(EntityView):
+    __regid__ = 'cw.user-table.group-cell'
+    __select__ = is_instance('CWUser')
+
+    def cell_call(self, row, col, **kwargs):
+        entity = self.cw_rset.get_entity(row, col)
+        self.w(entity.view('reledit', rtype='in_group', role='subject'))
--- a/web/views/urlrewrite.py	Tue Feb 08 14:16:41 2011 +0100
+++ b/web/views/urlrewrite.py	Tue Feb 08 14:18:18 2011 +0100
@@ -96,6 +96,7 @@
         ('/error', dict(vid='error')),
         ('/sparql', dict(vid='sparql')),
         ('/processinfo', dict(vid='processinfo')),
+        (rgx('/cwuser', re.I), dict(vid='cw.user-management')),
         # XXX should be case insensitive as 'create', but I would like to find another way than
         # relying on the etype_selector
         (rgx('/schema/([^/]+?)/?'),  dict(vid='primary', rql=r'Any X WHERE X is CWEType, X name "\1"')),