[management ui] add views to manage sources similarly to users
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Feb 2011 18:06:27 +0100
changeset 6962 220e32f058be
parent 6961 686c59dfc401
child 6963 5774d4ba4306
[management ui] add views to manage sources similarly to users
web/views/cwsources.py
web/views/startup.py
web/views/urlrewrite.py
--- a/web/views/cwsources.py	Wed Feb 09 18:06:25 2011 +0100
+++ b/web/views/cwsources.py	Wed Feb 09 18:06:27 2011 +0100
@@ -25,10 +25,12 @@
 from itertools import repeat, chain
 
 from cubicweb.selectors import is_instance, score_entity, match_user_groups
-from cubicweb.view import EntityView
+from cubicweb.view import EntityView, StartupView
 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name
 from cubicweb.web import uicfg
-from cubicweb.web.views import tabs
+from cubicweb.web.views import tabs, actions
+
+# source primary views #########################################################
 
 _pvs = uicfg.primaryview_section
 _pvs.tag_object_of(('*', 'cw_for_source', 'CWSource'), 'hidden')
@@ -56,6 +58,12 @@
     def entity_call(self, entity):
         _ = self._cw._
         self.w('<h3>%s</h3>' % _('Entity and relation supported by this source'))
+        eschema = self._cw.vreg.schema.eschema('CWSourceSchemaConfig')
+        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 CWSourceSchemaConfig')))
+            self.w(u'<div class="clear"></div>')
         rset = self._cw.execute(
             'Any X, SCH, XO ORDERBY ET WHERE X options XO, X cw_for_source S, S eid %(s)s, '
             'X cw_schema SCH, SCH is ET', {'s': entity.eid})
@@ -197,3 +205,25 @@
 MAPPING_CHECKERS = {
     'pyrorql': PyroRQLMappingChecker,
     }
+
+# sources management view ######################################################
+
+class ManageSourcesAction(actions.ManagersAction):
+    __regid__ = 'cwsource'
+    title = _('data sources')
+    category = 'manage'
+
+class CWSourceManagementView(StartupView):
+    __regid__ = 'cw.source-management'
+    rql = ('Any S, ST, SN ORDERBY SN WHERE S is CWSource, S name SN, S type ST')
+    title = _('data sources management')
+
+    def call(self, **kwargs):
+        self.w('<h1>%s</h1>' % self._cw._(self.title))
+        eschema = self._cw.vreg.schema.eschema('CWSource')
+        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 CWSource')))
+            self.w(u'<div class="clear"></div>')
+        self.wview('table', self._cw.execute(self.rql), displaycols=range(2))
--- a/web/views/startup.py	Wed Feb 09 18:06:25 2011 +0100
+++ b/web/views/startup.py	Wed Feb 09 18:06:27 2011 +0100
@@ -38,7 +38,7 @@
     add_etype_links = ()
     skip_startup_views = set( ('index', 'manage', 'schema', 'owl', 'changelog',
                                'systempropertiesform', 'propertiesform',
-                               'cw.user-management',
+                               'cw.user-management', 'cw.source-management',
                                'siteinfo', 'info', 'registry', 'gc',
                                'tree') )
 
--- a/web/views/urlrewrite.py	Wed Feb 09 18:06:25 2011 +0100
+++ b/web/views/urlrewrite.py	Wed Feb 09 18:06:27 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.
@@ -97,6 +97,7 @@
         ('/sparql', dict(vid='sparql')),
         ('/processinfo', dict(vid='processinfo')),
         (rgx('/cwuser', re.I), dict(vid='cw.user-management')),
+        (rgx('/cwsource', re.I), dict(vid='cw.source-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"')),