[management table] upgrade sources groups management table to new api
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 21 Oct 2011 14:32:37 +0200
changeset 7994 af3fb709c061
parent 7993 aa0addce4dae
child 7995 9a9f35ef418c
[management table] upgrade sources groups management table to new api
entities/authobjs.py
web/test/unittest_viewselector.py
web/views/cwsources.py
web/views/urlrewrite.py
--- a/entities/authobjs.py	Fri Oct 21 14:32:37 2011 +0200
+++ b/entities/authobjs.py	Fri Oct 21 14:32:37 2011 +0200
@@ -29,6 +29,19 @@
     fetch_attrs, cw_fetch_order = fetch_config(['name'])
     cw_fetch_unrelated_order = cw_fetch_order
 
+    def dc_long_title(self):
+        name = self.name
+        trname = self._cw._(name)
+        if trname != name:
+            return '%s (%s)' % (name, trname)
+        return name
+
+    @cached
+    def num_users(self):
+        """return the number of users in this group"""
+        return self._cw.execute('Any COUNT(U) WHERE U in_group G, G eid %(g)s',
+                                {'g': self.eid})[0][0]
+
 
 class CWUser(AnyEntity):
     __regid__ = 'CWUser'
--- a/web/test/unittest_viewselector.py	Fri Oct 21 14:32:37 2011 +0200
+++ b/web/test/unittest_viewselector.py	Fri Oct 21 14:32:37 2011 +0200
@@ -90,7 +90,7 @@
         req = self.request()
         self.assertListEqual(self.pviews(req, None),
                              [('changelog', wdoc.ChangeLogView),
-                              ('cw.source-management', cwsources.CWSourceManagementView),
+                              ('cw.sources-management', cwsources.CWSourcesManagementView),
                               ('cw.users-and-groups-management', cwuser.UsersAndGroupsManagementView),
                               ('gc', debug.GCView),
                               ('index', startup.IndexView),
--- a/web/views/cwsources.py	Fri Oct 21 14:32:37 2011 +0200
+++ b/web/views/cwsources.py	Fri Oct 21 14:32:37 2011 +0200
@@ -29,7 +29,7 @@
 from cubicweb.view import EntityView, StartupView
 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name
 from cubicweb.web import uicfg, formwidgets as wdgs
-from cubicweb.web.views import tabs, actions, ibreadcrumbs, add_etype_button
+from cubicweb.web.views import tabs, actions, ibreadcrumbs, tableview, add_etype_button
 
 
 _abaa = uicfg.actionbox_appearsin_addmenu
@@ -255,9 +255,10 @@
     title = _('data sources')
     category = 'manage'
 
-class CWSourceManagementView(StartupView):
-    __regid__ = 'cw.source-management'
-    rql = ('Any S, ST, SP, SD, SN ORDERBY SN WHERE S is CWSource, S name SN, S type ST, '
+
+class CWSourcesManagementView(StartupView):
+    __regid__ = 'cw.sources-management'
+    rql = ('Any S,ST,SP,SD,SN ORDERBY SN WHERE S is CWSource, S name SN, S type ST, '
            'S latest_retrieval SD, S parser SP')
     title = _('data sources management')
 
@@ -265,7 +266,18 @@
         self.w('<h1>%s</h1>' % self._cw._(self.title))
         self.w(add_etype_button(self._cw, 'CWSource'))
         self.w(u'<div class="clear"></div>')
-        self.wview('table', self._cw.execute(self.rql), displaycols=range(4))
+        self.wview('cw.sources-table', self._cw.execute(self.rql))
+
+
+class CWSourcesTable(tableview.EntityTableView):
+    __regid__ = 'cw.sources-table'
+    __select__ = is_instance('CWSource')
+    columns = ['source', 'type', 'parser', 'latest_retrieval']
+
+    # @tableview.etable_header_title('CWSource_plural', addcount=True)
+    # @tableview.etable_entity_sortvalue()
+    # def source_cell(self, w, entity):
+    #     w(entity.view('incontext'))
 
 
 # breadcrumbs configuration ####################################################
--- a/web/views/urlrewrite.py	Fri Oct 21 14:32:37 2011 +0200
+++ b/web/views/urlrewrite.py	Fri Oct 21 14:32:37 2011 +0200
@@ -101,7 +101,7 @@
                                     tab=domid('cw.users-management'))),
         (rgx('/cwgroup', re.I), dict(vid='cw.users-and-groups-management',
                                      tab=domid('cw.groups-management'))),
-        (rgx('/cwsource', re.I), dict(vid='cw.source-management')),
+        (rgx('/cwsource', re.I), dict(vid='cw.sources-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"')),