--- a/common/selectors.py Wed Feb 11 18:46:14 2009 +0100
+++ b/common/selectors.py Wed Feb 11 18:47:12 2009 +0100
@@ -161,13 +161,20 @@
def paginated_rset(cls, req, rset, *args, **kwargs):
"""accept result sets with more rows than the page size
"""
- if rset is None or len(rset) <= req.property_value('navigation.page-size'):
+ page_size = kwargs.get('page_size')
+ if page_size is None:
+ page_size = req.form.get('page_size')
+ if page_size is None:
+ page_size = req.property_value('navigation.page-size')
+ else:
+ page_size = int(page_size)
+ if rset is None or len(rset) <= page_size:
return 0
return 1
largerset_selector = deprecated_function(paginated_rset)
@lltrace
-def sorted_rset(cls, req, rset, row=None, col=None):
+def sorted_rset(cls, req, rset, row=None, col=None, **kwargs):
"""accept sorted result set"""
rqlst = rset.syntax_tree()
if len(rqlst.children) > 1 or not rqlst.children[0].orderby:
--- a/devtools/repotest.py Wed Feb 11 18:46:14 2009 +0100
+++ b/devtools/repotest.py Wed Feb 11 18:47:12 2009 +0100
@@ -3,7 +3,7 @@
This module contains functions to initialize a new repository.
:organization: Logilab
-:copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
@@ -249,7 +249,8 @@
_orig_select_principal = rqlannotation._select_principal
def _select_principal(scope, relations):
- return _orig_select_principal(scope, sorted(relations, key=lambda x: x.r_type))
+ return _orig_select_principal(scope, relations,
+ _sort=lambda rels: sorted(rels, key=lambda x: x.r_type))
try:
from cubicweb.server.msplanner import PartPlanInformation
--- a/entities/authobjs.py Wed Feb 11 18:46:14 2009 +0100
+++ b/entities/authobjs.py Wed Feb 11 18:47:12 2009 +0100
@@ -1,3 +1,10 @@
+"""entity classes user and group entities
+
+:organization: Logilab
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+"""
+__docformat__ = "restructuredtext en"
from logilab.common.decorators import cached
from cubicweb import Unauthorized
@@ -26,6 +33,7 @@
'in_group' : 'primary',
('owned_by', '*', 'object') : ('generated', 'link'),
('created_by','*','object') : ('generated', 'link'),
+ ('bookmarked_by', '*', 'object'): ('generated', 'create'),
}
# used by repository to check if the user can log in or not
@@ -85,6 +93,13 @@
"""
return self.matching_groups(group) == 1
+ def is_anonymous(self):
+ """ checks if user is an anonymous user"""
+ #FIXME on the web-side anonymous user is detected according
+ # to config['anonymous-user'], we don't have this info on
+ # the server side.
+ return self.groups == frozenset(('guests', ))
+
def owns(self, eid):
if hasattr(self.req, 'unsafe_execute'):
# use unsafe_execute on the repository side, in case
--- a/entities/lib.py Wed Feb 11 18:46:14 2009 +0100
+++ b/entities/lib.py Wed Feb 11 18:47:12 2009 +0100
@@ -1,7 +1,7 @@
"""entity classes for optional library entities
: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"
--- a/i18n/en.po Wed Feb 11 18:46:14 2009 +0100
+++ b/i18n/en.po Wed Feb 11 18:47:12 2009 +0100
@@ -376,6 +376,9 @@
msgid "Problem occured"
msgstr ""
+msgid "Project linked data"
+msgstr ""
+
msgid "RQLExpression"
msgstr "RQL expression"
@@ -717,6 +720,9 @@
msgid "add"
msgstr ""
+msgid "add Bookmark bookmarked_by EUser object"
+msgstr "bookmark"
+
msgid "add EEType add_permission RQLExpression subject"
msgstr "rql expression for the add permission"
@@ -1311,6 +1317,9 @@
msgid "created_by_object"
msgstr "has created"
+msgid "creating Bookmark (Bookmark bookmarked_by EUser %(linkto)s)"
+msgstr "creating bookmark for %(linkto)s"
+
msgid "creating EConstraint (EFRDef %(linkto)s constrained_by EConstraint)"
msgstr "creating constraint for attribute %(linkto)s"
@@ -1668,12 +1677,18 @@
msgid "february"
msgstr ""
+msgid "file tree view"
+msgstr ""
+
msgid "final"
msgstr ""
msgid "firstname"
msgstr ""
+msgid "foaf"
+msgstr ""
+
msgid "follow"
msgstr ""
@@ -1997,6 +2012,9 @@
msgid "list"
msgstr ""
+msgid "loading"
+msgstr ""
+
msgid "log in"
msgstr ""
@@ -2025,6 +2043,9 @@
msgid "manage bookmarks"
msgstr ""
+msgid "manage permissions"
+msgstr ""
+
msgid "manage security"
msgstr ""
@@ -2137,6 +2158,9 @@
msgid "not authorized"
msgstr ""
+msgid "not selected"
+msgstr ""
+
msgid "not specified"
msgstr ""
@@ -2173,6 +2197,15 @@
msgid "ordernum"
msgstr "order"
+msgid "owl (tbox+abox)"
+msgstr ""
+
+msgid "owlabox"
+msgstr ""
+
+msgid "owlaboxlight"
+msgstr ""
+
msgid "owned_by"
msgstr "owned by"
@@ -2416,6 +2449,9 @@
msgid "select this entity"
msgstr ""
+msgid "selected"
+msgstr ""
+
msgid "semantic description of this attribute"
msgstr ""
@@ -2541,6 +2577,9 @@
msgid "task progression"
msgstr ""
+msgid "tbox"
+msgstr ""
+
msgid "text"
msgstr ""
@@ -2617,6 +2656,9 @@
msgid "transition_of_object"
msgstr "use transitions"
+msgid "tree view"
+msgstr ""
+
msgid "tuesday"
msgstr ""
--- a/i18n/es.po Wed Feb 11 18:46:14 2009 +0100
+++ b/i18n/es.po Wed Feb 11 18:47:12 2009 +0100
@@ -381,6 +381,9 @@
msgid "Problem occured"
msgstr "Ha ocurrido un error"
+msgid "Project linked data"
+msgstr ""
+
msgid "RQLExpression"
msgstr "Expresión RQL"
@@ -738,6 +741,9 @@
msgid "add"
msgstr "agregar"
+msgid "add Bookmark bookmarked_by EUser object"
+msgstr ""
+
msgid "add EEType add_permission RQLExpression subject"
msgstr "Definir una expresión RQL de agregación"
@@ -1359,6 +1365,9 @@
msgid "created_by_object"
msgstr "ha creado"
+msgid "creating Bookmark (Bookmark bookmarked_by EUser %(linkto)s)"
+msgstr ""
+
msgid "creating EConstraint (EFRDef %(linkto)s constrained_by EConstraint)"
msgstr "creación condicionada por el atributo %(linkto)s"
@@ -1745,12 +1754,18 @@
msgid "february"
msgstr "febrero"
+msgid "file tree view"
+msgstr ""
+
msgid "final"
msgstr "final"
msgid "firstname"
msgstr "nombre"
+msgid "foaf"
+msgstr ""
+
msgid "follow"
msgstr "seguir la liga"
@@ -2090,6 +2105,9 @@
msgid "list"
msgstr "liste"
+msgid "loading"
+msgstr ""
+
msgid "log in"
msgstr "s'identifier"
@@ -2118,6 +2136,9 @@
msgid "manage bookmarks"
msgstr "gÈrer les signets"
+msgid "manage permissions"
+msgstr ""
+
msgid "manage security"
msgstr "gestion de la sÈcuritÈ"
@@ -2232,6 +2253,9 @@
msgid "not authorized"
msgstr "non autorisÈ"
+msgid "not selected"
+msgstr ""
+
msgid "not specified"
msgstr "non spÈcifiÈ"
@@ -2268,6 +2292,15 @@
msgid "ordernum"
msgstr "ordre"
+msgid "owl (tbox+abox)"
+msgstr ""
+
+msgid "owlabox"
+msgstr ""
+
+msgid "owlaboxlight"
+msgstr ""
+
msgid "owned_by"
msgstr "appartient ‡"
@@ -2521,6 +2554,9 @@
msgid "select this entity"
msgstr "sÈlectionner cette entitÈ"
+msgid "selected"
+msgstr ""
+
msgid "semantic description of this attribute"
msgstr "description sÈmantique de cet attribut"
@@ -2649,6 +2685,9 @@
msgid "task progression"
msgstr "avancement de la t‚che"
+msgid "tbox"
+msgstr ""
+
msgid "text"
msgstr "text"
@@ -2726,6 +2765,9 @@
msgid "transition_of_object"
msgstr "a pour transition"
+msgid "tree view"
+msgstr ""
+
msgid "tuesday"
msgstr "mardi"
--- a/i18n/fr.po Wed Feb 11 18:46:14 2009 +0100
+++ b/i18n/fr.po Wed Feb 11 18:47:12 2009 +0100
@@ -381,6 +381,9 @@
msgid "Problem occured"
msgstr "Une erreur est survenue"
+msgid "Project linked data"
+msgstr ""
+
msgid "RQLExpression"
msgstr "Expression RQL"
@@ -740,6 +743,9 @@
msgid "add"
msgstr "ajouter"
+msgid "add Bookmark bookmarked_by EUser object"
+msgstr "signet"
+
msgid "add EEType add_permission RQLExpression subject"
msgstr "définir une expression RQL d'ajout"
@@ -1197,7 +1203,7 @@
msgstr "la barre de requête rql, dans l'en-tête de page"
msgid "components_rss_feed_url"
-msgstr ""
+msgstr "syndication rss"
msgid "components_rss_feed_url_description"
msgstr ""
@@ -1361,14 +1367,17 @@
msgid "created_by_object"
msgstr "a créé"
+msgid "creating Bookmark (Bookmark bookmarked_by EUser %(linkto)s)"
+msgstr "création d'un signet pour %(linkto)s"
+
msgid "creating EConstraint (EFRDef %(linkto)s constrained_by EConstraint)"
-msgstr "création contrainte pour l'attribut %(linkto)s"
+msgstr "création d'une contrainte pour l'attribut %(linkto)s"
msgid "creating EConstraint (ENFRDef %(linkto)s constrained_by EConstraint)"
-msgstr "création contrainte pour la relation %(linkto)s"
+msgstr "création d'une contrainte pour la relation %(linkto)s"
msgid "creating EFRDef (EFRDef relation_type ERType %(linkto)s)"
-msgstr "création attribut %(linkto)s"
+msgstr "création d'un attribut %(linkto)s"
msgid "creating ENFRDef (ENFRDef relation_type ERType %(linkto)s)"
msgstr "création relation %(linkto)s"
@@ -1744,12 +1753,18 @@
msgid "february"
msgstr "février"
+msgid "file tree view"
+msgstr "arborescence (fichiers)"
+
msgid "final"
msgstr "final"
msgid "firstname"
msgstr "prénom"
+msgid "foaf"
+msgstr "foaf"
+
msgid "follow"
msgstr "suivre le lien"
@@ -2091,6 +2106,9 @@
msgid "list"
msgstr "liste"
+msgid "loading"
+msgstr "chargement"
+
msgid "log in"
msgstr "s'identifier"
@@ -2119,6 +2137,9 @@
msgid "manage bookmarks"
msgstr "gérer les signets"
+msgid "manage permissions"
+msgstr "gestion des permissions"
+
msgid "manage security"
msgstr "gestion de la sécurité"
@@ -2233,6 +2254,9 @@
msgid "not authorized"
msgstr "non autorisé"
+msgid "not selected"
+msgstr "non sélectionné"
+
msgid "not specified"
msgstr "non spécifié"
@@ -2269,6 +2293,15 @@
msgid "ordernum"
msgstr "ordre"
+msgid "owl (tbox+abox)"
+msgstr ""
+
+msgid "owlabox"
+msgstr ""
+
+msgid "owlaboxlight"
+msgstr ""
+
msgid "owned_by"
msgstr "appartient à"
@@ -2522,6 +2555,9 @@
msgid "select this entity"
msgstr "sélectionner cette entité"
+msgid "selected"
+msgstr "sélectionné"
+
msgid "semantic description of this attribute"
msgstr "description sémantique de cet attribut"
@@ -2650,6 +2686,9 @@
msgid "task progression"
msgstr "avancement de la tâche"
+msgid "tbox"
+msgstr ""
+
msgid "text"
msgstr "text"
@@ -2727,6 +2766,9 @@
msgid "transition_of_object"
msgstr "a pour transition"
+msgid "tree view"
+msgstr "arborescence"
+
msgid "tuesday"
msgstr "mardi"
--- a/server/repository.py Wed Feb 11 18:46:14 2009 +0100
+++ b/server/repository.py Wed Feb 11 18:47:12 2009 +0100
@@ -490,7 +490,7 @@
session = self.internal_session()
try:
if session.execute('EUser X WHERE X login %(login)s', {'login': login}):
- return
+ return False
# we have to create the user
user = self.vreg.etype_class('EUser')(session, None)
if isinstance(password, unicode):
@@ -505,6 +505,7 @@
session.commit()
finally:
session.close()
+ return True
def connect(self, login, password, cnxprops=None):
"""open a connection for a given user
--- a/server/rqlannotation.py Wed Feb 11 18:46:14 2009 +0100
+++ b/server/rqlannotation.py Wed Feb 11 18:47:12 2009 +0100
@@ -146,16 +146,17 @@
class CantSelectPrincipal(Exception): pass
-def _select_principal(sqlscope, relations):
+def _select_principal(sqlscope, relations, _sort=lambda x:x):
"""given a list of rqlst relations, select one which will be used to
represent an invariant variable (e.g. using on extremity of the relation
instead of the variable's type table
"""
+ # _sort argument is there for test
diffscope_rels = {}
has_same_scope_rel = False
ored_rels = set()
diffscope_rels = set()
- for rel in relations:
+ for rel in _sort(relations):
# note: only eid and has_text among all final relations may be there
if rel.r_type in ('eid', 'identity'):
has_same_scope_rel = rel.sqlscope is sqlscope
@@ -175,18 +176,17 @@
if isinstance(common_parent(rel1, rel2), Or):
ored_rels.discard(rel1)
ored_rels.discard(rel2)
- for rel in ored_rels:
+ for rel in _sort(ored_rels):
if rel.sqlscope is sqlscope:
return rel
diffscope_rels.add(rel)
# if DISTINCT query, can use variable from a different scope as principal
# since introduced duplicates will be removed
if sqlscope.stmt.distinct and diffscope_rels:
- return iter(diffscope_rels).next()
+ return iter(_sort(diffscope_rels)).next()
# XXX could use a relation for a different scope if it can't generate
# duplicates, so we would have to check cardinality
- raise CantSelectPrincipal()
-
+ raise CantSelectPrincipal()
def _select_main_var(relations):
"""given a list of rqlst relations, select one which will be used as main
--- a/server/test/unittest_rql2sql.py Wed Feb 11 18:46:14 2009 +0100
+++ b/server/test/unittest_rql2sql.py Wed Feb 11 18:47:12 2009 +0100
@@ -805,7 +805,7 @@
'F name "read", F require_group E, U in_group E)), U eid 1',
'''SELECT A.eid, rel_documented_by0.eid_to
FROM Affaire AS A LEFT OUTER JOIN documented_by_relation AS rel_documented_by0 ON (rel_documented_by0.eid_from=A.eid)
-WHERE ((rel_documented_by0.eid_to IS NULL) OR (EXISTS(SELECT 1 FROM require_permission_relation AS rel_require_permission1, EPermission AS F, require_group_relation AS rel_require_group2, in_group_relation AS rel_in_group3 WHERE rel_documented_by0.eid_to=rel_require_permission1.eid_from AND rel_require_permission1.eid_to=F.eid AND F.name=read AND rel_require_group2.eid_from=F.eid AND rel_in_group3.eid_from=1 AND rel_in_group3.eid_to=rel_require_group2.eid_to)))'''),
+WHERE ((rel_documented_by0.eid_to IS NULL) OR (EXISTS(SELECT 1 FROM require_permission_relation AS rel_require_permission1, EPermission AS F, require_group_relation AS rel_require_group2, in_group_relation AS rel_in_group3 WHERE rel_documented_by0.eid_to=rel_require_permission1.eid_from AND rel_require_permission1.eid_to=F.eid AND F.name=read AND rel_require_group2.eid_from=F.eid AND rel_in_group3.eid_to=rel_require_group2.eid_to AND rel_in_group3.eid_from=1)))'''),
("Any X WHERE X eid 12, P? connait X",
'''SELECT X.eid
--- a/web/component.py Wed Feb 11 18:46:14 2009 +0100
+++ b/web/component.py Wed Feb 11 18:47:12 2009 +0100
@@ -73,6 +73,19 @@
selected_page_link_templ = u'<span class="selectedSlice"><a href="%s" title="%s">%s</a></span>'
previous_page_link_templ = next_page_link_templ = page_link_templ
no_previous_page_link = no_next_page_link = u''
+
+ @classmethod
+ def selected(cls, req, rset, row=None, col=None, page_size=None, **kwargs):
+ """by default web app objects are usually instantiated on
+ selection according to a request, a result set, and optional
+ row and col
+ """
+ instance = super(NavigationComponent, cls).selected(req, rset, row, col, **kwargs)
+ if page_size is not None:
+ instance.page_size = page_size
+ elif 'page_size' in req.form:
+ instance.page_size = int(req.form['page_size'])
+ return instance
def __init__(self, req, rset):
super(NavigationComponent, self).__init__(req, rset)
--- a/web/test/unittest_viewselector.py Wed Feb 11 18:46:14 2009 +0100
+++ b/web/test/unittest_viewselector.py Wed Feb 11 18:47:12 2009 +0100
@@ -19,6 +19,7 @@
treeview, idownloadable, wdoc, debug)
from cubicweb.entities.lib import Card
from cubicweb.interfaces import IMileStone
+from cubicweb.web.views import owl
USERACTIONS = [('myprefs', actions.UserPreferencesAction),
('myinfos', actions.UserInfoAction),
@@ -74,7 +75,7 @@
('index', startup.IndexView),
('info', management.ProcessInformationView),
('manage', startup.ManageView),
- ('owl', startup.OWLView),
+ ('owl', owl.OWLView),
('schema', startup.SchemaView),
('systemepropertiesform', management.SystemEpropertiesForm)])
# no entity but etype
@@ -97,6 +98,7 @@
('filetree', treeview.FileTreeView),
('list', baseviews.ListView),
('oneline', baseviews.OneLineView),
+ ('owlabox', owl.OWLABOXView),
('primary', baseviews.PrimaryView),
('rsetxml', baseviews.XMLRsetView),
('rss', baseviews.RssView),
@@ -117,6 +119,7 @@
('filetree', treeview.FileTreeView),
('list', baseviews.ListView),
('oneline', baseviews.OneLineView),
+ ('owlabox', owl.OWLABOXView),
('primary', baseviews.PrimaryView),
('rsetxml', baseviews.XMLRsetView),
('rss', baseviews.RssView),
@@ -137,6 +140,7 @@
('filetree', treeview.FileTreeView),
('list', baseviews.ListView),
('oneline', baseviews.OneLineView),
+ ('owlabox', owl.OWLABOXView),
('primary', baseviews.PrimaryView),
('rsetxml', baseviews.XMLRsetView),
('rss', baseviews.RssView),
@@ -163,8 +167,10 @@
('ecsvexport', baseviews.CSVEntityView),
('editable-table', tableview.EditableTableView),
('filetree', treeview.FileTreeView),
+ ('foaf', euser.FoafView),
('list', baseviews.ListView),
('oneline', baseviews.OneLineView),
+ ('owlabox', owl.OWLABOXView),
('primary', euser.EUserPrimaryView),
('rsetxml', baseviews.XMLRsetView),
('rss', baseviews.RssView),
--- a/web/views/basetemplates.py Wed Feb 11 18:46:14 2009 +0100
+++ b/web/views/basetemplates.py Wed Feb 11 18:47:12 2009 +0100
@@ -7,11 +7,13 @@
"""
__docformat__ = "restructuredtext en"
+
from logilab.mtconverter import html_escape
from cubicweb import NoSelectableObject, ObjectNotFound
from cubicweb.common.view import Template, MainTemplate, NOINDEX, NOFOLLOW
from cubicweb.common.utils import make_uid
+from cubicweb.common.utils import UStringIO
from cubicweb.web.views.baseviews import vid_from_rset
@@ -73,6 +75,7 @@
- guess and call an appropriate view through the view manager
"""
id = 'main'
+ nav_html = UStringIO()
def _select_view_and_rset(self):
req = self.req
@@ -162,7 +165,9 @@
self.req, self.rset)
if etypefilter and etypefilter.propval('visible'):
etypefilter.dispatch(w=self.w)
- self.pagination(self.req, self.rset, self.w, not (view and view.need_navigation))
+ self.pagination(self.req, self.rset, self.nav_html.write,
+ not (view and view.need_navigation))
+ self.w(_(self.nav_html.getvalue()))
self.w(u'<div id="contentmain">\n')
def template_html_header(self, content_type, page_title, additional_headers=()):
@@ -198,6 +203,7 @@
def template_footer(self, view=None):
self.w(u'</div>\n') # close id=contentmain
+ self.w(_(self.nav_html.getvalue()))
self.w(u'</div>\n') # closes id=pageContent
self.content_footer(view)
self.w(u'</td>\n')
--- a/web/views/euser.py Wed Feb 11 18:46:14 2009 +0100
+++ b/web/views/euser.py Wed Feb 11 18:47:12 2009 +0100
@@ -14,11 +14,6 @@
from cubicweb.web.form import EntityForm
from cubicweb.web.views.baseviews import PrimaryView, EntityView
-try:
- from hashlib import sha1 as sha
-
-except ImportError:
- from sha import sha
class EUserPrimaryView(PrimaryView):
accepts = ('EUser',)
@@ -72,8 +67,8 @@
% html_escape(entity.firstname))
emailaddr = entity.get_email()
if emailaddr:
- self.w(u'<foaf:mbox>%s</foaf:mbox>\n' % html_escape(unicode(emailaddr)))
- self.w(u'</foaf:Person>\n')
+ self.w(u'<foaf:mbox>%s</foaf:mbox>\n' % html_escape(emailaddr))
+ self.w(u'</foaf:Person>\n')
class EditGroups(EntityForm):
--- a/web/views/navigation.py Wed Feb 11 18:46:14 2009 +0100
+++ b/web/views/navigation.py Wed Feb 11 18:47:12 2009 +0100
@@ -36,15 +36,17 @@
while start < rset.rowcount:
stop = min(start + page_size - 1, rset.rowcount - 1)
blocklist.append(self.page_link(basepath, params, start, stop,
- u'%s - %s' % (start+1, stop+1)))
+ self.index_display(start, stop)))
start = stop + 1
w(u'<div class="pagination">')
w(u'%s ' % self.previous_link(params))
w(u'[ %s ]' % u' | '.join(blocklist))
w(u' %s' % self.next_link(params))
w(u'</div>')
+
+ def index_display(self, start, stop):
+ return u'%s - %s' % (start+1, stop+1)
-
class SortedNavigation(NavigationComponent):
"""sorted navigation apply if navigation is needed (according to page size)
and if the result set is sorted
@@ -142,9 +144,11 @@
self.w(u'</div>')
-def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False, show_all_option=True):
+def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False,
+ show_all_option=True, page_size = None):
showall = forcedisplay or req.form.get('__force_display') is not None
- nav = not showall and self.vreg.select_component('navigation', req, rset)
+ nav = not showall and self.vreg.select_component('navigation', req, rset,
+ page_size=page_size)
if nav:
# get boundaries before component rendering
start, stop = nav.page_boundaries()
--- a/web/views/owl.py Wed Feb 11 18:46:14 2009 +0100
+++ b/web/views/owl.py Wed Feb 11 18:47:12 2009 +0100
@@ -1,4 +1,4 @@
-from logilab.mtconverter import html_escape
+from logilab.mtconverter import TransformError, html_escape
from cubicweb.common.view import StartupView
from cubicweb.common.view import EntityView
@@ -11,124 +11,77 @@
'*': ''
}
-OWL_CARD_MAP_DATA = {'String': 'xsd:string',
- 'Datetime': 'xsd:dateTime',
- 'Bytes': 'xsd:byte',
- 'Float': 'xsd:float',
- 'Boolean': 'xsd:boolean',
- 'Int': 'xsd:int',
- 'Date':'xsd:date',
- 'Time': 'xsd:time',
- 'Password': 'xsd:byte',
- 'Decimal' : 'xsd:decimal',
- 'Interval': 'xsd:duration'
- }
+OWL_TYPE_MAP = {'String': 'xsd:string',
+ 'Datetime': 'xsd:dateTime',
+ 'Bytes': 'xsd:byte',
+ 'Float': 'xsd:float',
+ 'Boolean': 'xsd:boolean',
+ 'Int': 'xsd:int',
+ 'Date':'xsd:date',
+ 'Time': 'xsd:time',
+ 'Password': 'xsd:byte',
+ 'Decimal' : 'xsd:decimal',
+ 'Interval': 'xsd:duration'
+ }
OWL_OPENING_ROOT = u'''<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE rdf:RDF [
+<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
- <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
- <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
- <!ENTITY %s "http://logilab.org/owl/ontologies/%s#" >
-
- ]>
- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
- xmlns:owl="http://www.w3.org/2002/07/owl#"
- xmlns="http://logilab.org/owl/ontologies/%s#"
- xmlns:%s="http://logilab.org/owl/ontologies/%s#"
- xmlns:base="http://logilab.org/owl/ontologies/%s">
+]>
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
+ xmlns:owl="http://www.w3.org/2002/07/owl#"
+ xmlns="http://logilab.org/owl/ontologies/%(appid)s#"
+ xmlns:%(appid)s="http://logilab.org/owl/ontologies/%(appid)s#"
+ xmlns:base="http://logilab.org/owl/ontologies/%(appid)s">
- <owl:Ontology rdf:about="">
- <rdfs:comment>
- %s Cubicweb OWL Ontology
-
- </rdfs:comment>
- </owl:Ontology>'''
+ <owl:Ontology rdf:about="">
+ <rdfs:comment>
+ %(appid)s Cubicweb OWL Ontology
+ </rdfs:comment>
+ </owl:Ontology>'''
OWL_CLOSING_ROOT = u'</rdf:RDF>'
-class OWLView(StartupView):
- """This view export in owl format the whole cubicweb ontologie. First part is the TBOX, second part is an ABOX ligth version."""
- id = 'owl'
- title = _('owl (tbox+abox)')
- templatable =False
- content_type = 'application/xml' # 'text/xml'
+DEFAULT_SKIP_RELS = frozenset(('is', 'is_instance_of', 'identity',
+ 'owned_by', 'created_by'))
- def call(self):
-
- skipmeta = int(self.req.form.get('skipmeta', True))
- self.w(OWL_OPENING_ROOT % (self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name))
- self.wview('tbox', None, writeprefix=False)
- entities = [eschema for eschema in self.schema.entities()
- if not eschema.is_final()]
- if skipmeta:
- entities = [eschema for eschema in entities
- if not eschema.meta]
- for entity in entities:
- rql = 'Any X where X is %s'
- rset = self.req.execute(rql% entity)
- if rset:
- self.wview('owlaboxlight', rset, writeprefix=False)
- self.w(OWL_CLOSING_ROOT)
-
-class TBoxView(StartupView):
+class OWLView(StartupView):
"""This view export in owl format schema database. It is the TBOX"""
- id = 'tbox'
- title = _('tbox')
- templatable =False
+ id = 'owl'
+ title = _('owl')
+ templatable = False
content_type = 'application/xml' # 'text/xml'
def call(self, writeprefix=True):
skipmeta = int(self.req.form.get('skipmeta', True))
if writeprefix:
- self.w(OWL_OPENING_ROOT % (self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name) )
-
- self.visit_schema(display_relations=True,
- skiprels=('is', 'is_instance_of', 'identity',
- 'owned_by', 'created_by'),
- skipmeta=skipmeta)
+ self.w(OWL_OPENING_ROOT % {'appid': self.schema.name})
+ self.visit_schema(skipmeta=skipmeta)
if writeprefix:
self.w(OWL_CLOSING_ROOT)
- def visit_schema(self, display_relations=0,
- skiprels=(), skipmeta=True):
+ def visit_schema(self, skiprels=DEFAULT_SKIP_RELS, skipmeta=True):
"""get a layout for a whole schema"""
-
- entities = [eschema for eschema in self.schema.entities()
- if not eschema.is_final()]
+ entities = sorted([eschema for eschema in self.schema.entities()
+ if not eschema.is_final()])
if skipmeta:
entities = [eschema for eschema in entities
if not eschema.meta]
- keys = [(eschema.type, eschema) for eschema in entities]
self.w(u'<!-- classes definition -->')
- for key, eschema in sorted(keys):
+ for eschema in entities:
self.visit_entityschema(eschema, skiprels)
- self.w(u'<!-- property definition -->')
- self.w(u'<!-- object property -->')
- for key, eschema in sorted(keys):
- self.visit_property_schema(eschema, skiprels)
- self.w(u'<!-- datatype property -->')
- for key, eschema in sorted(keys):
- self.visit_property_object_schema(eschema, skiprels)
-
- def stereotype(self, name):
- return Span((' <<%s>>' % name,), klass='stereotype')
+ self.w(u'<!-- property definition -->')
+ self.visit_property_schema(eschema, skiprels)
+ self.w(u'<!-- datatype property -->')
+ self.visit_property_object_schema(eschema)
def visit_entityschema(self, eschema, skiprels=()):
"""get a layout for an entity OWL schema"""
- etype = eschema.type
-
- if eschema.meta:
- self.stereotype('meta')
- self.w(u'''<owl:Class rdf:ID="%s"><rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
- '''%eschema, stereotype)
- else:
- self.w(u'''<owl:Class rdf:ID="%s"><rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
- '''% eschema)
-
+ self.w(u'<owl:Class rdf:ID="%s"><rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>'
+ % eschema)
self.w(u'<!-- relations -->')
for rschema, targetschemas, role in eschema.relation_definitions():
if rschema.type in skiprels:
@@ -141,13 +94,15 @@
card = rschema.rproperty(eschema, oeschema, 'cardinality')[0]
else:
card = rschema.rproperty(oeschema, eschema, 'cardinality')[1]
- self.w(u'''<rdfs:subClassOf>
- <owl:Restriction>
- <owl:onProperty rdf:resource="#%s"/>
- %s
- </owl:Restriction>
- </rdfs:subClassOf>
- ''' % (label, OWL_CARD_MAP[card]))
+ cardtag = OWL_CARD_MAP[card]
+ if cardtag:
+ self.w(u'''<rdfs:subClassOf>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#%s"/>
+ %s
+ </owl:Restriction>
+</rdfs:subClassOf>
+''' % (label, cardtag))
self.w(u'<!-- attributes -->')
@@ -157,21 +112,17 @@
aname = rschema.type
if aname == 'eid':
continue
- card_data = aschema.type
self.w(u'''<rdfs:subClassOf>
- <owl:Restriction>
- <owl:onProperty rdf:resource="#%s"/>
- <rdf:type rdf:resource="&owl;FunctionalProperty"/>
- </owl:Restriction>
- </rdfs:subClassOf>'''
-
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#%s"/>
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ </owl:Restriction>
+</rdfs:subClassOf>'''
% aname)
self.w(u'</owl:Class>')
def visit_property_schema(self, eschema, skiprels=()):
"""get a layout for property entity OWL schema"""
- etype = eschema.type
-
for rschema, targetschemas, role in eschema.relation_definitions():
if rschema.type in skiprels:
continue
@@ -180,78 +131,54 @@
for oeschema in targetschemas:
label = rschema.type
self.w(u'''<owl:ObjectProperty rdf:ID="%s">
- <rdfs:domain rdf:resource="#%s"/>
- <rdfs:range rdf:resource="#%s"/>
- </owl:ObjectProperty>
-
- ''' % (label, eschema, oeschema.type ))
+ <rdfs:domain rdf:resource="#%s"/>
+ <rdfs:range rdf:resource="#%s"/>
+</owl:ObjectProperty>
+''' % (label, eschema, oeschema.type))
- def visit_property_object_schema(self, eschema, skiprels=()):
-
+ def visit_property_object_schema(self, eschema):
for rschema, aschema in eschema.attribute_definitions():
if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
continue
aname = rschema.type
if aname == 'eid':
continue
- card_data = aschema.type
self.w(u'''<owl:DatatypeProperty rdf:ID="%s">
- <rdfs:domain rdf:resource="#%s"/>
- <rdfs:range rdf:resource="%s"/>
- </owl:DatatypeProperty>'''
- % (aname, eschema, OWL_CARD_MAP_DATA[card_data]))
-
-class OWLABOXLightView(EntityView):
- '''This view represents the lihgt part of the ABOX for a given entity'''
- id = 'owlaboxlight'
- title = _('owlaboxlight')
- templatable =False
- accepts = ('Any',)
- content_type = 'application/xml' # 'text/xml'
-
- def call(self, writeprefix=True):
+ <rdfs:domain rdf:resource="#%s"/>
+ <rdfs:range rdf:resource="%s"/>
+</owl:DatatypeProperty>'''
+ % (aname, eschema, OWL_TYPE_MAP[aschema.type]))
- skipmeta = int(self.req.form.get('skipmeta', True))
- if writeprefix:
- self.w(OWL_OPENING_ROOT % (self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name))
- for i in xrange(self.rset.rowcount):
- self.cell_call(i, 0, skiprels=('is', 'is_instance_of', 'identity',
- 'owned_by', 'created_by'),
- skipmeta=skipmeta)
- if writeprefix:
- self.w(OWL_CLOSING_ROOT)
-
-
- def cell_call(self, row, col, skiprels=(), skipmeta=True):
- entity = self.complete_entity(row, col)
- eschema = entity.e_schema
- self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid))
- self.w(u'</%s>'% eschema)
-
-
-class OWLABOXEView(EntityView):
+
+class OWLABOXView(EntityView):
'''This view represents a part of the ABOX for a given entity.'''
id = 'owlabox'
title = _('owlabox')
- templatable =False
+ templatable = False
accepts = ('Any',)
content_type = 'application/xml' # 'text/xml'
- def call(self, writeprefix=True):
-
- skipmeta = int(self.req.form.get('skipmeta', True))
- if writeprefix:
- self.w(OWL_OPENING_ROOT % (self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name))
+ def call(self):
+ self.w(OWL_OPENING_ROOT % {'appid': self.schema.name})
+ self.wview('owl', None, writeprefix=False)
for i in xrange(self.rset.rowcount):
- self.cell_call(i, 0, skiprels=('is', 'is_instance_of', 'identity',
- 'owned_by', 'created_by'),
- skipmeta=skipmeta)
- if writeprefix:
- self.w(OWL_CLOSING_ROOT)
+ self.cell_call(i, 0)
+ self.w(OWL_CLOSING_ROOT)
+
+ def cell_call(self, row, col, skiprels=DEFAULT_SKIP_RELS):
+ self.wview('owlaboxitem', self.rset, row=row, col=col, skiprels=skiprels)
+
+class OWLABOXItemView(EntityView):
+ '''This view represents a part of the ABOX for a given entity.'''
+
+ id = 'owlaboxitem'
+ templatable = False
+ accepts = ('Any',)
+ content_type = 'application/xml' # 'text/xml'
- def cell_call(self, row, col, skiprels=(), skipmeta=True):
+ def cell_call(self, row, col, skiprels=DEFAULT_SKIP_RELS):
entity = self.complete_entity(row, col)
eschema = entity.e_schema
self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid))
@@ -264,9 +191,12 @@
aname = rschema.type
if aname == 'eid':
continue
- attr = getattr(entity, aname)
- if attr is not None:
- self.w(u'<%s>%s</%s>' % (aname, html_escape(unicode(attr)), aname))
+ try:
+ attr = entity.printable_value(aname, format='text/plain')
+ if attr:
+ self.w(u'<%s>%s</%s>' % (aname, html_escape(attr), aname))
+ except TransformError:
+ pass
self.w(u'<!--relations -->')
for rschema, targetschemas, role in eschema.relation_definitions():
if rschema.type in skiprels:
--- a/web/webctl.py Wed Feb 11 18:46:14 2009 +0100
+++ b/web/webctl.py Wed Feb 11 18:47:12 2009 +0100
@@ -2,12 +2,12 @@
web configuration
: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"
-from cubicweb.toolsutils import CommandHandler
+from cubicweb.toolsutils import CommandHandler, confirm
class WebCreateHandler(CommandHandler):
@@ -22,7 +22,10 @@
print '** repository server configuration'
print '-' * 72
config.input_config('pyro-client', inputlevel)
-
+ if confirm('allow anonymous access', False):
+ config.global_set_option('anonymous-user', 'anon')
+ config.global_set_option('anonymous-password', 'anon')
+
def postcreate(self):
"""hooks called once application's initialization has been completed"""