# HG changeset patch # User Adrien Di Mascio # Date 1233135006 -3600 # Node ID 334df77b38f5746197f7853767ee12edc72caa70 # Parent e6d025d7d3135b58308cc118517ef59fec469549# Parent cd792cfda0715312f47676611842d3ccdb8fc192 backport stable branch changesets diff -r cd792cfda071 -r 334df77b38f5 common/appobject.py --- a/common/appobject.py Wed Jan 28 10:29:39 2009 +0100 +++ b/common/appobject.py Wed Jan 28 10:30:06 2009 +0100 @@ -1,7 +1,7 @@ """Base class for dynamically loaded objects manipulated in the web interface :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" @@ -12,6 +12,8 @@ from simplejson import dumps from logilab.common.deprecation import obsolete + +from rql.nodes import VariableRef, SubQuery from rql.stmts import Union, Select from cubicweb import Unauthorized diff -r cd792cfda071 -r 334df77b38f5 common/entity.py --- a/common/entity.py Wed Jan 28 10:29:39 2009 +0100 +++ b/common/entity.py Wed Jan 28 10:30:06 2009 +0100 @@ -1,7 +1,7 @@ """Base class for entity objects manipulated in clients :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" diff -r cd792cfda071 -r 334df77b38f5 common/mail.py --- a/common/mail.py Wed Jan 28 10:29:39 2009 +0100 +++ b/common/mail.py Wed Jan 28 10:30:06 2009 +0100 @@ -56,9 +56,10 @@ msg['Reply-to'] = msg['From'] if config is not None: msg['X-CW'] = config.appid - msg['To'] = ', '.join(addrheader(addr) for addr in to_addrs if addr is not None) + unique_addrs = lambda addrs: sorted(set(addr for addr in addrs if addr is not None)) + msg['To'] = ', '.join(addrheader(addr) for addr in unique_addrs(to_addrs)) if cc_addrs: - msg['Cc'] = ', '.join(addrheader(addr) for addr in cc_addrs if addr is not None) + msg['Cc'] = ', '.join(addrheader(addr) for addr in unique_addrs(cc_addrs)) if msgid: msg['Message-id'] = msgid if references: diff -r cd792cfda071 -r 334df77b38f5 common/migration.py --- a/common/migration.py Wed Jan 28 10:29:39 2009 +0100 +++ b/common/migration.py Wed Jan 28 10:30:06 2009 +0100 @@ -346,7 +346,7 @@ if optdescr[0] == 'added': optdict = self.config.get_option_def(optdescr[1]) if optdict.get('default') is REQUIRED: - self.config.input_option(option, optdict) + self.config.input_option(optdescr[1], optdict) self.config.generate_config(open(newconfig, 'w')) show_diffs(configfile, newconfig) if exists(newconfig): diff -r cd792cfda071 -r 334df77b38f5 common/mixins.py --- a/common/mixins.py Wed Jan 28 10:29:39 2009 +0100 +++ b/common/mixins.py Wed Jan 28 10:30:06 2009 +0100 @@ -145,7 +145,6 @@ return self.iterchildren() def is_leaf(self): - print '*' * 80 return len(self.children()) == 0 def is_root(self): @@ -165,7 +164,11 @@ @property def state(self): - return self.in_state[0].name + try: + return self.in_state[0].name + except IndexError: + self.warning('entity %s has no state', self) + return None @property def displayable_state(self): diff -r cd792cfda071 -r 334df77b38f5 common/selectors.py --- a/common/selectors.py Wed Jan 28 10:29:39 2009 +0100 +++ b/common/selectors.py Wed Jan 28 10:30:06 2009 +0100 @@ -499,7 +499,7 @@ propval = req.property_value('%s.%s.context' % (cls.__registry__, cls.id)) if not propval: propval = cls.context - if context is not None and propval is not None and context != propval: + if context is not None and propval and context != propval: return 0 return 1 contextprop_selector = deprecated_function(match_context_prop) diff -r cd792cfda071 -r 334df77b38f5 common/view.py --- a/common/view.py Wed Jan 28 10:29:39 2009 +0100 +++ b/common/view.py Wed Jan 28 10:30:06 2009 +0100 @@ -59,6 +59,8 @@ cubicweb:tlunit CDATA #IMPLIED cubicweb:loadurl CDATA #IMPLIED cubicweb:uselabel CDATA #IMPLIED + cubicweb:facetargs CDATA #IMPLIED + cubicweb:facetName CDATA #IMPLIED "> ] ''' TRANSITIONAL_DOCTYPE = u'\n' diff -r cd792cfda071 -r 334df77b38f5 debian/control --- a/debian/control Wed Jan 28 10:29:39 2009 +0100 +++ b/debian/control Wed Jan 28 10:30:06 2009 +0100 @@ -5,6 +5,7 @@ Uploaders: Sylvain Thenault Build-Depends: debhelper (>= 5.0.37.1), python (>=2.4), python-dev (>=2.4), python-central (>= 0.5) Standards-Version: 3.8.0 +Homepage: http://www.cubicweb.org XS-Python-Version: >= 2.4, << 2.6 Package: cubicweb diff -r cd792cfda071 -r 334df77b38f5 debian/cubicweb-ctl.postinst --- a/debian/cubicweb-ctl.postinst Wed Jan 28 10:29:39 2009 +0100 +++ b/debian/cubicweb-ctl.postinst Wed Jan 28 10:30:06 2009 +0100 @@ -2,7 +2,7 @@ case "$1" in configure|abort-upgrade|abort-remove|abort-deconfigure) - update-rc.d cubicweb defaults >/dev/null + update-rc.d cubicweb defaults 99 >/dev/null ;; *) echo "postinst called with unknown argument \`$1'" >&2 diff -r cd792cfda071 -r 334df77b38f5 devtools/test/data/bootstrap_cubes --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/devtools/test/data/bootstrap_cubes Wed Jan 28 10:30:06 2009 +0100 @@ -0,0 +1,1 @@ +person, comment diff -r cd792cfda071 -r 334df77b38f5 devtools/test/data/bootstrap_packages --- a/devtools/test/data/bootstrap_packages Wed Jan 28 10:29:39 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -eperson, ecomment diff -r cd792cfda071 -r 334df77b38f5 devtools/testlib.py --- a/devtools/testlib.py Wed Jan 28 10:29:39 2009 +0100 +++ b/devtools/testlib.py Wed Jan 28 10:30:06 2009 +0100 @@ -113,6 +113,7 @@ 'combobox' : None, 'csvexport' : None, 'ecsvexport' : None, + 'owl' : None, # XXX } valmap = {None: None, 'dtd': DTDValidator, 'xml': SaxOnlyValidator} no_auto_populate = () @@ -328,7 +329,6 @@ """this method tries to find everything that can be tested for `rset` and yields a callable test (as needed in generative tests) """ - rqlst = parse(rset.rql) propdefs = self.vreg['propertydefs'] # make all components visible for k, v in propdefs.items(): diff -r cd792cfda071 -r 334df77b38f5 doc/book/en/A03a-concepts.en.txt --- a/doc/book/en/A03a-concepts.en.txt Wed Jan 28 10:29:39 2009 +0100 +++ b/doc/book/en/A03a-concepts.en.txt Wed Jan 28 10:30:06 2009 +0100 @@ -11,7 +11,7 @@ .. image:: images/archi_globale.en.png -`CubicWeb` framework is a server/client application framework. Those two +`CubicWeb` framework is a server/client application framework. Those two parties communicates through RQL (`CubicWeb` query language implementation) and ResultSet (which will be explained in :ref:`TermsVocabulary`). @@ -44,7 +44,7 @@ stored in the database at the time an instance is created. `CubicWeb` provides a certain number of system entities included automatically as it is necessary for the core of `CubicWeb` and a library of - cubes (which defined application entities) that can be explicitely + cubes (which defined application entities) that can be explicitely included if necessary. *entity type* @@ -69,7 +69,7 @@ *relation definition* A relation definition is a 3-uple (subject entity type, relation type, object entity type), with an associated set of property such as cardinality, constraints... - + *repository* This is the RQL server side of `CubicWeb`. Be carefull not to get confused with a Mercurial repository or a debian repository. @@ -77,7 +77,7 @@ *source* A data source is a container of data (SGBD, LDAP directory, `Google App Engine`'s datastore ...) integrated in the - `CubicWeb` repository. This repository has at least one source, `system` which + `CubicWeb` repository. This repository has at least one source, `system` which contains the schema of the application, plain-text index and others vital informations for the system. @@ -86,7 +86,7 @@ - ``repository`` : repository only, accessible for clients using Pyro - ``twisted`` : web interface only, access the repository using Pyro - - ``all-in-one`` : web interface and repository in a single process. + - ``all-in-one`` : web interface and repository in a single process. The repository could be or not accessible using Pyro. *cube* @@ -94,7 +94,7 @@ to provide a specific functionnality or a complete `CubicWeb` application potentially using other cubes. The available cubes are located in the file system at `/path/to/forest/cubicweb/cubes` for a Mercurial forest installation, - for a debian packages installation they will be located in + for a debian packages installation they will be located in `/usr/share/cubicweb/cubes`. Larger applications can be built faster by importing cubes, adding entities and relationships and overriding the @@ -102,7 +102,7 @@ cubes. *instance* - An instance is a specific installation of one or multiple cubes. All the required + An instance is a specific installation of one or multiple cubes. All the required configuration files necessary for the well being of your web application are grouped in an instance. This will refer to the cube(s) your application is based on. @@ -112,7 +112,7 @@ *application* The term application is sometime used to talk about an instance - and sometimes to talk of a cube depending on the context. + and sometimes to talk of a cube depending on the context. So we would like to avoid using this term and try to use *cube* and *instance* instead. @@ -127,7 +127,7 @@ *query language* A full-blown query language named RQL is used to formulate requests - to the database or any sources such as LDAP or `Google App Engine`'s + to the database or any sources such as LDAP or `Google App Engine`'s datastore. *views* @@ -147,7 +147,7 @@ This query language is inspired by SQL but is highest level, its implementation generates SQL. - + .. _`Python Remote Object`: http://pyro.sourceforge.net/ .. _`yams`: http://www.logilab.org/project/yams/ @@ -194,14 +194,14 @@ ~~~~~~~~~~~~~~ The Python API developped to interface with RQL is inspired from the standard db-api, -with a Connection object having the methods cursor, rollback and commit essentially. +with a Connection object having the methods cursor, rollback and commit essentially. The most important method is the `execute` method of a cursor : `execute(rqlstring, args=None, eid_key=None, build_descr=True)` :rqlstring: the RQL query to execute (unicode) :args: if the query contains substitutions, a dictionnary containing the values to use -:eid_key: +:eid_key: an implementation detail of the RQL queries cache implies that if a substitution is used to introduce an eid *susceptible to raise the ambiguities in the query type resolution*, then we have to specify the correponding key in the dictionnary @@ -210,14 +210,14 @@ The `Connection` object owns the methods `commit` and `rollback`. You *should never need to use them* during the development of the web interface based on -the `CubicWeb` framework as it determines the end of the transaction depending +the `CubicWeb` framework as it determines the end of the transaction depending on the query execution success. .. note:: While executing updates queries (SET, INSERT, DELETE), if a query generates an error related to security, a rollback is automatically done on the current transaction. - + The `Request` class (`cubicweb.web`) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -243,7 +243,7 @@ key or the value `default` if the key is not defined * `set_session_data(key, value)`, assign a value to a key * `del_session_data(key)`, suppress the value associated to a key - + :Cookies handling: * `get_cookie()`, returns a dictionnary containing the value of the header @@ -290,7 +290,7 @@ `__registry__`) and its identifier (attribute `id`). Usually we do not have to take care of the register, only the identifier `id`. -We can find a certain number of attributes and methods defined in this class +We can find a certain number of attributes and methods defined in this class and common to all the application objects. At the recording, the following attributes are dynamically added to @@ -333,7 +333,7 @@ also call the method `complete()` on the entity before returning it :Data formatting: - * `format_date(date, date_format=None, time=False)` returns a string for a + * `format_date(date, date_format=None, time=False)` returns a string for a mx date time according to application's configuration * `format_time(time)` returns a string for a mx date time according to application's configuration @@ -342,8 +342,8 @@ * `external_resource(rid, default=_MARKER)`, access to a value defined in the configuration file `external_resource` - - * `tal_render(template, variables)`, renders a precompiled page template with + + * `tal_render(template, variables)`, renders a precompiled page template with variables in the given dictionary as context .. note:: @@ -357,7 +357,7 @@ PrimaryView.f(self, arg1) You'd better write: :: - + class Truc(PrimaryView): def f(self, arg1): super(Truc, self).f(arg1) @@ -374,7 +374,7 @@ in order to provide a specific feature or even a complete application using others cubes. -You can decide to write your own set of cubes if you wish to re-use the +You can decide to write your own set of cubes if you wish to re-use the entity types you develop. Lots of cubes are available from the `CubicWeb Forge`_ under a free software license. @@ -388,12 +388,12 @@ A cube is structured as follows: :: - + mycube/ | |-- data/ | |-- cubes.mycube.css - | |-- cubes.mycube.js + | |-- cubes.mycube.js | `-- external_resources | |-- debian/ @@ -437,12 +437,12 @@ | `-- views.py - + We can use subpackages instead of python modules for ``views.py``, ``entities.py``, ``schema.py`` or ``hooks.py``. For example, we could have: :: - + mycube/ | |-- entities.py @@ -451,7 +451,7 @@ |-- forms.py |-- primary.py `-- widgets.py - + where : @@ -472,13 +472,13 @@ * file ``__pkginfo__.py`` provides component meta-data, especially the distribution and the current version (server side and web interface) or sub-cubes used by the cube. - - + + At least you should have: * the file ``__pkginfo__.py`` * the schema definition - XXX false, we may want to have cubes which are only adding a service, + XXX false, we may want to have cubes which are only adding a service, no persistent data (eg embeding for instance) diff -r cd792cfda071 -r 334df77b38f5 doc/book/en/B0011-schema-stdlib.en.txt --- a/doc/book/en/B0011-schema-stdlib.en.txt Wed Jan 28 10:29:39 2009 +0100 +++ b/doc/book/en/B0011-schema-stdlib.en.txt Wed Jan 28 10:30:06 2009 +0100 @@ -37,34 +37,54 @@ An application is based on several basic cubes. In the set of available basic cubes we can find for example : -* `comment`, provides an entity type for `Comment` allowing us to comment others - site's entities - -* `mailinglist`, provides an entity type for `Mailinglist` which groups informations - in a discussion list +* addressbook_: PhoneNumber and PostalAddress -* `file`, provides entity types for `File` et `Image` used to represent - files (text or binary) with additionnal informations such as MIME type or - encoding. - -* `link`, provides an entity type for hypertext link (`Link`) +* basket_: Basket (like a shopping cart) -* `blog`, provides an entity type weblog (`Blog`) - -* `person`, provides an entity type for a person (`Person`) +* blog_: Blog (a *very* basic blog) -* `addressbook`, provides an entity type used to represent phone - numbers (`PhoneNumber`) and mailing address (`PostalAddress`) - -* `classtags`, categorization system based on tags (`Tag`) +* comment_: Comment (to attach comment threads to entities) -* `classfolders`, categorization system based on folders hierarchy in order - to create navigation sections (`Folder`) - -* `email`, archiving management for emails (`Email`, `Emailpart`, +* email_: archiving management for emails (`Email`, `Emailpart`, `Emailthread`) -* `basket`, basket management (`Basket`) allowing to group entities +* event_: Event (define events, display them in calendars) + +* file_: File (to allow users to upload and store binary or text files) + +* folder_: Folder (to organize things but grouping them in folders) + +* keyword_: Keyword (to define classification schemes) + +* link_: Link (to collect links to web resources) + +* mailinglist_: MailingList (to reference a mailing-list and the URLs + for its archives and its admin interface) + +* person_: Person (easily mixed with addressbook) + +* tag_: Tag (to tag anything) + +* task_: Task (something to be done between start and stop date) + +* zone_: Zone (to define places within larger places, for example a + city in a state in a country) + +.. _addressbook: http://www.cubicweb.org/project/cubicweb-addressbook +.. _basket: http://www.cubicweb.org/project/cubicweb-basket +.. _blog: http://www.cubicweb.org/project/cubicweb-blog +.. _comment: http://www.cubicweb.org/project/cubicweb-comment +.. _email: http://www.cubicweb.org/project/cubicweb-email +.. _event: http://www.cubicweb.org/project/cubicweb-event +.. _file: http://www.cubicweb.org/project/cubicweb-file +.. _folder: http://www.cubicweb.org/project/cubicweb-folder +.. _keyword: http://www.cubicweb.org/project/cubicweb-keyword +.. _link: http://www.cubicweb.org/project/cubicweb-link +.. _mailinglist: http://www.cubicweb.org/project/cubicweb-mailinglist +.. _person: http://www.cubicweb.org/project/cubicweb-person +.. _tag: http://www.cubicweb.org/project/cubicweb-tag +.. _task: http://www.cubicweb.org/project/cubicweb-task +.. _zone: http://www.cubicweb.org/project/cubicweb-zone To declare the use of a component, once installed, add the name of the component to the variable `__use__` in the file `__pkginfo__.py` of your own component. diff -r cd792cfda071 -r 334df77b38f5 doc/book/en/B1030-form-management.en.txt --- a/doc/book/en/B1030-form-management.en.txt Wed Jan 28 10:29:39 2009 +0100 +++ b/doc/book/en/B1030-form-management.en.txt Wed Jan 28 10:30:06 2009 +0100 @@ -13,7 +13,7 @@ The form generated by default does not fit your needs? You are not required to re-do all by hands! :) -* rtags primary, secondary, generated, generic, +* rtags primary, secondary, generated, generic, `Entity.relation_category(rtype, x='subject')` * inline_view (now a rtag?) * widget specification @@ -36,8 +36,8 @@ starting by `eid:` and also having a parameter `__type` associated (also *qualified* by eid) -2. For all the attributes and the relations of an entity to edit: - +2. For all the attributes and the relations of an entity to edit: + 1. search for a parameter `edits-` or `edito-` qualified in the case of a relation where the entity is object 2. if found, the value returned is considered as the initial value @@ -50,24 +50,24 @@ 1. if a qualified parameter `__linkto` is specified, its value has to be a string (or a list of string) such as: :: - + :: - + where is either `subject` or `object` and each eid could be separated from the others by a `_`. Target specifies if the *edited entity* is subject or object of the relation and each relation specified will be inserted. 2. if a qualified parameter `__clone_eid` is specified for an entity, the - relations of the specified entity passed as value of this parameter are + relations of the specified entity passed as value of this parameter are copied on the edited entity. 3. if a qualified parameter `__delete` is specified, its value must be a string or a list of string such as follows: :: - + :: - where each eid subject or object can be seperated from the other + where each eid subject or object can be seperated from the other by `_`. Each relation specified will be deleted. 4. if a qualified parameter `__insert` is specified, its value should @@ -84,14 +84,14 @@ .. note:: - + * If the parameter `__action_delete` is found, all the entities specified as to be edited will be deleted. - + * If the parameter`__action_cancel` is found, no action is completed. - * If the parameter `__action_apply` is found, the editing is applied - normally but the redirection is done on the form + * If the parameter `__action_apply` is found, the editing is applied + normally but the redirection is done on the form (see :ref:`RedirectionControl`). * The parameter `__method` is also supported as for the main template @@ -120,7 +120,7 @@ * `__redirectparams`: forms parameters to add to the path -* `__redirectrql`: redirection RQL request +* `__redirectrql`: redirection RQL request * `__redirectvid`: redirection view identifier @@ -132,6 +132,6 @@ * `__form_id`: initial view form identifier, used if `__action_apply` is found -In general we use either `__redirectpath` and `__redirectparams` or +In general we use either `__redirectpath` and `__redirectparams` or `__redirectrql` and `__redirectvid`. diff -r cd792cfda071 -r 334df77b38f5 entities/__init__.py --- a/entities/__init__.py Wed Jan 28 10:29:39 2009 +0100 +++ b/entities/__init__.py Wed Jan 28 10:30:06 2009 +0100 @@ -1,7 +1,7 @@ """base application's entities class implementation: `AnyEntity` :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" diff -r cd792cfda071 -r 334df77b38f5 goa/__init__.py --- a/goa/__init__.py Wed Jan 28 10:29:39 2009 +0100 +++ b/goa/__init__.py Wed Jan 28 10:30:06 2009 +0100 @@ -28,7 +28,7 @@ regular python datetime object """ if yamstype is None: - yamstype = guess_yamstype_from_date(datetimeobj) + yamstype = guess_yamstype_for_date(datetimeobj) assert yamstype is not None if yamstype == 'Datetime': # don't use date, db model doesn't actually support it, only datetime diff -r cd792cfda071 -r 334df77b38f5 goa/db.py --- a/goa/db.py Wed Jan 28 10:29:39 2009 +0100 +++ b/goa/db.py Wed Jan 28 10:30:06 2009 +0100 @@ -391,7 +391,7 @@ @classmethod def kind(cls): - return self.id + return cls.id @classmethod def properties(cls): diff -r cd792cfda071 -r 334df77b38f5 goa/overrides/rqlannotation.py --- a/goa/overrides/rqlannotation.py Wed Jan 28 10:29:39 2009 +0100 +++ b/goa/overrides/rqlannotation.py Wed Jan 28 10:30:06 2009 +0100 @@ -1,4 +1,4 @@ -def set_qdata(union, noinvariant): +def set_qdata(getrschema, union, noinvariant): pass class SQLGenAnnotator(object): diff -r cd792cfda071 -r 334df77b38f5 goa/testlib.py --- a/goa/testlib.py Wed Jan 28 10:29:39 2009 +0100 +++ b/goa/testlib.py Wed Jan 28 10:30:06 2009 +0100 @@ -7,7 +7,7 @@ # additional monkey patches necessary in regular cubicweb environment from cubicweb.server import rqlannotation from cubicweb.goa.overrides import rqlannotation as goarqlannotation -rqlannotation.sqlgen_annotate = goarqlannotation.sqlgen_annotate +rqlannotation.SQLGenAnnotator = goarqlannotation.SQLGenAnnotator rqlannotation.set_qdata = goarqlannotation.set_qdata try: diff -r cd792cfda071 -r 334df77b38f5 goa/tools/i18n.py --- a/goa/tools/i18n.py Wed Jan 28 10:29:39 2009 +0100 +++ b/goa/tools/i18n.py Wed Jan 28 10:30:06 2009 +0100 @@ -221,7 +221,7 @@ os.chdir(appdirectory) potfiles = [] if osp.exists(osp.join('i18n', 'entities.pot')): - potfiles = potfiles.append( osp.join('i18n', scfile) ) + potfiles = potfiles.append( osp.join('i18n', 'entities.pot') ) print '******** extract schema messages' schemapot = osp.join(tempdir, 'schema.pot') potfiles.append(schemapot) diff -r cd792cfda071 -r 334df77b38f5 schema.py --- a/schema.py Wed Jan 28 10:29:39 2009 +0100 +++ b/schema.py Wed Jan 28 10:30:06 2009 +0100 @@ -1,7 +1,7 @@ """classes to define schemas for CubicWeb :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" diff -r cd792cfda071 -r 334df77b38f5 server/__init__.py --- a/server/__init__.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/__init__.py Wed Jan 28 10:30:06 2009 +0100 @@ -113,6 +113,8 @@ for eid, etype in needisfix: handler.session.unsafe_execute('SET X is E WHERE X eid %(x)s, E name %(name)s', {'x': eid, 'name': etype}, 'x') + handler.session.unsafe_execute('SET X is_instance_of E WHERE X eid %(x)s, E name %(name)s', + {'x': eid, 'name': etype}, 'x') # insert versions handler.cmd_add_entity('EProperty', pkey=u'system.version.cubicweb', value=unicode(config.cubicweb_version())) diff -r cd792cfda071 -r 334df77b38f5 server/hooks.py --- a/server/hooks.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/hooks.py Wed Jan 28 10:30:06 2009 +0100 @@ -2,7 +2,7 @@ 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" diff -r cd792cfda071 -r 334df77b38f5 server/migractions.py --- a/server/migractions.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/migractions.py Wed Jan 28 10:30:06 2009 +0100 @@ -11,7 +11,7 @@ :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" @@ -679,11 +679,11 @@ espschema = eschema.specializes() if repospschema and not espschema: self.rqlexec('DELETE X specializes Y WHERE X is EEType, X name %(x)s', - {'x': str(repoechema)}) + {'x': str(repoeschema)}) elif not repospschema and espschema: self.rqlexec('SET X specializes Y WHERE X is EEType, X name %(x)s, ' 'Y is EEType, Y name %(y)s', - {'x': str(repoechema), 'y': str(epschema)}) + {'x': str(repoeschema), 'y': str(espschema)}) self.rqlexecall(ss.updateeschema2rql(eschema), ask_confirm=self.verbosity >= 2) for rschema, targettypes, x in eschema.relation_definitions(True): diff -r cd792cfda071 -r 334df77b38f5 server/msplanner.py --- a/server/msplanner.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/msplanner.py Wed Jan 28 10:30:06 2009 +0100 @@ -999,7 +999,9 @@ step = AggrStep(plan, selection, select, atemptable, temptable) step.children = steps elif len(steps) > 1: - if select.need_intersect: + if select.need_intersect or any(select.need_intersect + for step in steps + for select in step.union.children): if temptable: step = IntersectFetchStep(plan) else: diff -r cd792cfda071 -r 334df77b38f5 server/mssteps.py --- a/server/mssteps.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/mssteps.py Wed Jan 28 10:30:06 2009 +0100 @@ -6,7 +6,7 @@ for now) :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" @@ -274,9 +274,9 @@ result &= frozenset(step.execute()) result = list(result) if self.offset: - result = result[offset:] + result = result[self.offset:] if self.limit: - result = result[:limit] + result = result[:self.limit] return result diff -r cd792cfda071 -r 334df77b38f5 server/querier.py --- a/server/querier.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/querier.py Wed Jan 28 10:30:06 2009 +0100 @@ -196,7 +196,7 @@ self._insert_security(union, noinvariant) self.rqlhelper.simplify(union) self.sqlannotate(union) - set_qdata(union, noinvariant) + set_qdata(self.schema.rschema, union, noinvariant) if union.has_text_query: self.cache_key = None diff -r cd792cfda071 -r 334df77b38f5 server/repository.py --- a/server/repository.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/repository.py Wed Jan 28 10:30:06 2009 +0100 @@ -11,7 +11,7 @@ :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" @@ -791,7 +791,7 @@ # since the current session user may not have required permissions to # do necessary stuff and we don't want to commit user session. # - # More other, even if session is already an internal session but is + # Moreover, even if session is already an internal session but is # processing a commit, we have to use another one if not session.is_internal_session: session = self.internal_session() @@ -803,6 +803,7 @@ entity = source.before_entity_insertion(session, lid, etype, eid) if source.should_call_hooks: self.hm.call_hooks('before_add_entity', etype, session, entity) + # XXX call add_info with complete=False ? self.add_info(session, entity, source, lid) source.after_entity_insertion(session, lid, entity) if source.should_call_hooks: diff -r cd792cfda071 -r 334df77b38f5 server/rqlannotation.py --- a/server/rqlannotation.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/rqlannotation.py Wed Jan 28 10:30:06 2009 +0100 @@ -20,7 +20,7 @@ #if server.DEBUG: # print '-------- sql annotate', repr(rqlst) getrschema = annotator.schema.rschema - has_text_query = need_intersect = False + has_text_query = False need_distinct = rqlst.distinct for rel in rqlst.iget_nodes(Relation): if rel.neged(strict=True): @@ -29,13 +29,6 @@ else: rschema = getrschema(rel.r_type) if not rschema.is_final(): - # if one of the relation's variable is ambiguous, an intersection - # will be necessary - for vref in rel.get_nodes(VariableRef): - var = vref.variable - if not var.stinfo['selected'] and len(var.stinfo['possibletypes']) > 1: - need_intersect = True - break if rschema.inlined: try: var = rel.children[1].children[0].variable @@ -147,7 +140,6 @@ except CantSelectPrincipal: stinfo['invariant'] = False rqlst.need_distinct = need_distinct - rqlst.need_intersect = need_intersect return has_text_query @@ -207,12 +199,12 @@ return principal -def set_qdata(union, noinvariant): +def set_qdata(getrschema, union, noinvariant): """recursive function to set querier data on variables in the syntax tree """ for select in union.children: for subquery in select.with_: - set_qdata(subquery.query, noinvariant) + set_qdata(getrschema, subquery.query, noinvariant) for var in select.defined_vars.itervalues(): if var.stinfo['invariant']: if var in noinvariant and not var.stinfo['principal'].r_type == 'has_text': @@ -221,6 +213,23 @@ var._q_invariant = True else: var._q_invariant = False + for rel in select.iget_nodes(Relation): + if rel.neged(strict=True) and not rel.is_types_restriction(): + rschema = getrschema(rel.r_type) + if not rschema.is_final(): + # if one of the relation's variable is ambiguous but not + # invariant, an intersection will be necessary + for vref in rel.get_nodes(VariableRef): + var = vref.variable + if (not var._q_invariant and var.valuable_references() == 1 + and len(var.stinfo['possibletypes']) > 1): + select.need_intersect = True + break + else: + continue + break + else: + select.need_intersect = False class SQLGenAnnotator(object): diff -r cd792cfda071 -r 334df77b38f5 server/securityhooks.py --- a/server/securityhooks.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/securityhooks.py Wed Jan 28 10:30:06 2009 +0100 @@ -2,7 +2,7 @@ the user connected to a session :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" diff -r cd792cfda071 -r 334df77b38f5 server/sources/native.py --- a/server/sources/native.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/sources/native.py Wed Jan 28 10:30:06 2009 +0100 @@ -188,7 +188,7 @@ rqlst.restricted_vars = () rqlst.children[0].solutions = self._sols self.repo.querier.sqlgen_annotate(rqlst) - set_qdata(rqlst, ()) + set_qdata(self.schema.rschema, rqlst, ()) return rqlst def set_schema(self, schema): diff -r cd792cfda071 -r 334df77b38f5 server/sources/rql2sql.py --- a/server/sources/rql2sql.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/sources/rql2sql.py Wed Jan 28 10:30:06 2009 +0100 @@ -488,7 +488,8 @@ sql.insert(1, 'FROM (SELECT 1) AS _T') sqls.append('\n'.join(sql)) if select.need_intersect: - if distinct: + # XXX use getattr for lgc bw compat, remove once 0.37.3 is out + if distinct or not getattr(self.dbms_helper, 'intersect_all_support', True): return '\nINTERSECT\n'.join(sqls) else: return '\nINTERSECT ALL\n'.join(sqls) diff -r cd792cfda071 -r 334df77b38f5 server/test/unittest_migractions.py --- a/server/test/unittest_migractions.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/test/unittest_migractions.py Wed Jan 28 10:30:06 2009 +0100 @@ -134,7 +134,7 @@ self.assertEquals([str(rs) for rs in self.schema['Folder2'].object_relations()], ['filed_under2', 'identity']) self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()), - ['Affaire', 'Card', 'Division', 'ECache', 'Email', 'EmailThread', 'File', + ['Affaire', 'Card', 'Division', 'Email', 'EmailThread', 'File', 'Folder2', 'Image', 'Note', 'Personne', 'Societe', 'SubDivision']) self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) eschema = self.schema.eschema('Folder2') @@ -161,7 +161,7 @@ self.mh.cmd_add_relation_type('filed_under2') self.failUnless('filed_under2' in self.schema) self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()), - ['Affaire', 'Card', 'Division', 'ECache', 'Email', 'EmailThread', 'File', + ['Affaire', 'Card', 'Division', 'Email', 'EmailThread', 'File', 'Folder2', 'Image', 'Note', 'Personne', 'Societe', 'SubDivision']) self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',)) @@ -364,23 +364,36 @@ def test_add_remove_cube(self): cubes = set(self.config.cubes()) schema = self.repo.schema + self.assertEquals(sorted(schema['see_also']._rproperties.keys()), + sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), + ('Bookmark', 'Bookmark'), ('Bookmark', 'Note'), + ('Note', 'Note'), ('Note', 'Bookmark')])) try: - self.mh.cmd_remove_cube('email') - # file was there because it's an email dependancy, should have been removed - cubes.remove('email') - cubes.remove('file') - self.assertEquals(set(self.config.cubes()), cubes) - for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', - 'sender', 'in_thread', 'reply_to', 'data_format'): - self.failIf(ertype in schema, ertype) - self.assertEquals(sorted(schema['see_also']._rproperties.keys()), - [('Folder', 'Folder')]) - self.assertEquals(schema['see_also'].subjects(), ('Folder',)) - self.assertEquals(schema['see_also'].objects(), ('Folder',)) - self.assertEquals(self.execute('Any X WHERE X pkey "system.version.email"').rowcount, 0) - self.assertEquals(self.execute('Any X WHERE X pkey "system.version.file"').rowcount, 0) - self.failIf('email' in self.config.cubes()) - self.failIf('file' in self.config.cubes()) + try: + self.mh.cmd_remove_cube('email') + # file was there because it's an email dependancy, should have been removed + cubes.remove('email') + cubes.remove('file') + self.assertEquals(set(self.config.cubes()), cubes) + for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image', + 'sender', 'in_thread', 'reply_to', 'data_format'): + self.failIf(ertype in schema, ertype) + self.assertEquals(sorted(schema['see_also']._rproperties.keys()), + sorted([('Folder', 'Folder'), + ('Bookmark', 'Bookmark'), + ('Bookmark', 'Note'), + ('Note', 'Note'), + ('Note', 'Bookmark')])) + self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'Folder', 'Note']) + self.assertEquals(sorted(schema['see_also'].objects()), ['Bookmark', 'Folder', 'Note']) + self.assertEquals(self.execute('Any X WHERE X pkey "system.version.email"').rowcount, 0) + self.assertEquals(self.execute('Any X WHERE X pkey "system.version.file"').rowcount, 0) + self.failIf('email' in self.config.cubes()) + self.failIf('file' in self.config.cubes()) + except : + import traceback + traceback.print_exc() + raise finally: self.mh.cmd_add_cube('email') cubes.add('email') @@ -390,9 +403,13 @@ 'sender', 'in_thread', 'reply_to', 'data_format'): self.failUnless(ertype in schema, ertype) self.assertEquals(sorted(schema['see_also']._rproperties.keys()), - [('EmailThread', 'EmailThread'), ('Folder', 'Folder')]) - self.assertEquals(sorted(schema['see_also'].subjects()), ['EmailThread', 'Folder']) - self.assertEquals(sorted(schema['see_also'].objects()), ['EmailThread', 'Folder']) + sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'), + ('Bookmark', 'Bookmark'), + ('Bookmark', 'Note'), + ('Note', 'Note'), + ('Note', 'Bookmark')])) + self.assertEquals(sorted(schema['see_also'].subjects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) + self.assertEquals(sorted(schema['see_also'].objects()), ['Bookmark', 'EmailThread', 'Folder', 'Note']) from cubes.email.__pkginfo__ import version as email_version from cubes.file.__pkginfo__ import version as file_version self.assertEquals(self.execute('Any V WHERE X value V, X pkey "system.version.email"')[0][0], diff -r cd792cfda071 -r 334df77b38f5 server/test/unittest_querier.py --- a/server/test/unittest_querier.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/test/unittest_querier.py Wed Jan 28 10:30:06 2009 +0100 @@ -454,7 +454,7 @@ 'WHERE RT name N, RDEF relation_type RT ' 'HAVING COUNT(RDEF) > 10') self.assertListEquals(rset.rows, - [[u'description', 11], ['in_basket', 12], + [[u'description', 11], ['in_basket', 11], [u'name', 13], [u'created_by', 33], [u'creation_date', 33], [u'is', 33], [u'is_instance_of', 33], [u'modification_date', 33], [u'owned_by', 33]]) diff -r cd792cfda071 -r 334df77b38f5 server/test/unittest_rql2sql.py --- a/server/test/unittest_rql2sql.py Wed Jan 28 10:29:39 2009 +0100 +++ b/server/test/unittest_rql2sql.py Wed Jan 28 10:30:06 2009 +0100 @@ -156,11 +156,6 @@ ] ADVANCED= [ - ('Any X WHERE X is ET, ET eid 2', - '''SELECT rel_is0.eid_from -FROM is_relation AS rel_is0 -WHERE rel_is0.eid_to=2'''), - ("Societe S WHERE S nom 'Logilab' OR S nom 'Caesium'", '''SELECT S.eid @@ -1064,7 +1059,57 @@ ] +INTERSECT = [ + ('Any SN WHERE NOT X in_state S, S name SN', + '''SELECT DISTINCT S.name +FROM Affaire AS X, State AS S +WHERE (X.in_state IS NULL OR X.in_state!=S.eid) +INTERSECT +SELECT DISTINCT S.name +FROM EUser AS X, State AS S +WHERE (X.in_state IS NULL OR X.in_state!=S.eid) +INTERSECT +SELECT DISTINCT S.name +FROM Note AS X, State AS S +WHERE (X.in_state IS NULL OR X.in_state!=S.eid)'''), + ('Any PN WHERE NOT X travaille S, X nom PN, S is IN(Division, Societe)', + '''SELECT X.nom +FROM Personne AS X +WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0,Division AS S WHERE rel_travaille0.eid_from=X.eid AND rel_travaille0.eid_to=S.eid) +INTERSECT ALL +SELECT X.nom +FROM Personne AS X +WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0,Societe AS S WHERE rel_travaille0.eid_from=X.eid AND rel_travaille0.eid_to=S.eid)'''), + + ('Any PN WHERE NOT X travaille S, S nom PN, S is IN(Division, Societe)', + '''SELECT S.nom +FROM Division AS S +WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_to=S.eid) +UNION ALL +SELECT S.nom +FROM Societe AS S +WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_to=S.eid)'''), + + ('Personne X WHERE NOT X travaille S, S nom "chouette"', + '''SELECT X.eid +FROM Division AS S, Personne AS X +WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=X.eid AND rel_travaille0.eid_to=S.eid) AND S.nom=chouette +UNION ALL +SELECT X.eid +FROM Personne AS X, Societe AS S +WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=X.eid AND rel_travaille0.eid_to=S.eid) AND S.nom=chouette +UNION ALL +SELECT X.eid +FROM Personne AS X, SubDivision AS S +WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=X.eid AND rel_travaille0.eid_to=S.eid) AND S.nom=chouette'''), + + ('Any X WHERE X is ET, ET eid 2', + '''SELECT rel_is0.eid_from +FROM is_relation AS rel_is0 +WHERE rel_is0.eid_to=2'''), + + ] from logilab.common.adbh import ADV_FUNC_HELPER_DIRECTORY class PostgresSQLGeneratorTC(RQLGeneratorTC): @@ -1196,6 +1241,10 @@ def test_negation(self): for t in self._parse(NEGATIONS): yield t + + def test_intersection(self): + for t in self._parse(INTERSECT): + yield t def test_union(self): for t in self._parse(( @@ -1370,7 +1419,7 @@ self.o = SQLGenerator(schema, dbms_helper) def _norm_sql(self, sql): - return sql.strip().replace(' ILIKE ', ' LIKE ') + return sql.strip().replace(' ILIKE ', ' LIKE ').replace('\nINTERSECT ALL\n', '\nINTERSECT\n') def test_union(self): for t in self._parse(( diff -r cd792cfda071 -r 334df77b38f5 web/box.py --- a/web/box.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/box.py Wed Jan 28 10:30:06 2009 +0100 @@ -14,9 +14,9 @@ accepts_registerer, extresources_registerer, etype_rtype_priority_registerer) from cubicweb.common.selectors import ( - etype_rtype_selector, one_line_rset, accept, accept_rtype_selector, + etype_rtype_selector, one_line_rset, accept, has_relation, primary_view, match_context_prop, has_related_entities, - _rqlcondition_selector) + _rql_condition) from cubicweb.common.view import Template from cubicweb.common.appobject import ReloadableMixIn @@ -152,8 +152,7 @@ __registerer__ = accepts_registerer __selectors__ = (one_line_rset, primary_view, match_context_prop, etype_rtype_selector, - accept_rtype_selector, accept, - _rqlcondition_selector) + has_relation, accept, _rql_condition) accepts = ('Any',) context = 'incontext' condition = None diff -r cd792cfda071 -r 334df77b38f5 web/data/cubicweb.lazy.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/data/cubicweb.lazy.js Wed Jan 28 10:30:06 2009 +0100 @@ -0,0 +1,22 @@ + +function load_now(eltsel, holesel) { + var lazydiv = jQuery(eltsel); + var hole = lazydiv.children(holesel); + if (hole.length == 0) /* the hole is already filled */ + return; + var vid_eid = lazydiv.attr('cubicweb__loadurl'); + /* XXX see what could be done with jquery.loadxhtml(...) */ + var later = async_rawremote_exec('lazily', vid_eid); + later.addCallback(function(req) { + var div = lazydiv[0]; + div.appendChild(getDomFromResponse(req)); + div.removeChild(hole[0]); + }); + later.addErrback(function(err) { + log(err); + }); +} + +function trigger_load(divid) { + jQuery('#lazy-' + divid).trigger('load_' + divid); +} \ No newline at end of file diff -r cd792cfda071 -r 334df77b38f5 web/data/cubicweb.tabs.js --- a/web/data/cubicweb.tabs.js Wed Jan 28 10:29:39 2009 +0100 +++ b/web/data/cubicweb.tabs.js Wed Jan 28 10:30:06 2009 +0100 @@ -2,4 +2,6 @@ // set appropriate cookie // XXX see if we can no just do it with jQuery async_remote_exec('remember_active_tab', tabname); + // trigger show + tabname event + trigger_load(tabname); } diff -r cd792cfda071 -r 334df77b38f5 web/facet.py --- a/web/facet.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/facet.py Wed Jan 28 10:30:06 2009 +0100 @@ -29,7 +29,7 @@ def prepare_facets_rqlst(rqlst, args=None): """prepare a syntax tree to generate facet filters - + * remove ORDERBY clause * cleanup selection (remove everything) * undefine unnecessary variables @@ -64,7 +64,7 @@ def get_facet(req, facetid, rqlst, mainvar): return req.vreg.object_by_id('facets', facetid, req, rqlst=rqlst, filtered_variable=mainvar) - + def filter_hiddens(w, **kwargs): for key, val in kwargs.items(): @@ -139,7 +139,7 @@ rqlst.add_group_var(newvar) rqlst.add_selected(newvar) return newvar, rel - + def _remove_relation(rqlst, rel, var): """remove a constraint relation from the syntax tree""" # remove the relation @@ -229,10 +229,10 @@ if ovarname == mainvar.name: continue if not has_path(vargraph, ovarname, mainvar.name): - toremove.add(rqlst.defined_vars[ovarname]) + toremove.add(rqlst.defined_vars[ovarname]) - - + + ## base facet classes ######################################################### class AbstractFacet(AcceptMixIn, AppRsetObject): __registerer__ = priority_registerer @@ -245,14 +245,14 @@ help=_('display order of the box')), _('context'): dict(type='String', default=None, # None <-> both - vocabulary=(_('tablefilter'), _('facetbox'), None), + vocabulary=(_('tablefilter'), _('facetbox'), ''), help=_('context where this box should be displayed')), } visible = True - context = None + context = '' needs_update = False start_unfolded = True - + @classmethod def selected(cls, req, rset=None, rqlst=None, context=None, filtered_variable=None): @@ -280,20 +280,20 @@ def operator(self): # OR between selected values by default return self.req.form.get(self.id + '_andor', 'OR') - + def get_widget(self): """return the widget instance to use to display this facet """ raise NotImplementedError - + def add_rql_restrictions(self): """add restriction for this facet into the rql syntax tree""" raise NotImplementedError - + class VocabularyFacet(AbstractFacet): needs_update = True - + def get_widget(self): """return the widget instance to use to display this facet @@ -311,12 +311,12 @@ else: wdg.append(FacetItem(self.req, label, value, value in selected)) return wdg - + def vocabulary(self): """return vocabulary for this facet, eg a list of 2-uple (label, value) """ raise NotImplementedError - + def possible_values(self): """return a list of possible values (as string since it's used to compare to a form value in javascript) for this facet @@ -325,13 +325,13 @@ def support_and(self): return False - + def rqlexec(self, rql, args=None, cachekey=None): try: return self.req.execute(rql, args, cachekey) except Unauthorized: return [] - + class RelationFacet(VocabularyFacet): __selectors__ = (one_has_relation, match_context_prop) @@ -344,10 +344,10 @@ sortfunc = None # ascendant/descendant sorting sortasc = True - + @property def title(self): - return display_name(self.req, self.rtype, form=self.role) + return display_name(self.req, self.rtype, form=self.role) def vocabulary(self): """return vocabulary for this facet, eg a list of 2-uple (label, value) @@ -367,7 +367,7 @@ finally: rqlst.recover() return self.rset_vocabulary(rset) - + def possible_values(self): """return a list of possible values (as string since it's used to compare to a form value in javascript) for this facet @@ -380,7 +380,7 @@ return [str(x) for x, in self.rqlexec(rqlst.as_string())] finally: rqlst.recover() - + def rset_vocabulary(self, rset): _ = self.req._ return [(_(label), eid) for eid, label in rset] @@ -432,7 +432,9 @@ class AttributeFacet(RelationFacet): # attribute type attrtype = 'String' - + # type of comparison: default is an exact match on the attribute value + comparator = '=' # could be '<', '<=', '>', '>=' + def vocabulary(self): """return vocabulary for this facet, eg a list of 2-uple (label, value) """ @@ -452,14 +454,14 @@ finally: rqlst.recover() return self.rset_vocabulary(rset) - + def rset_vocabulary(self, rset): _ = self.req._ return [(_(value), value) for value, in rset] def support_and(self): return False - + def add_rql_restrictions(self): """add restriction for this facet into the rql syntax tree""" value = self.req.form.get(self.id) @@ -467,16 +469,16 @@ return mainvar = self.filtered_variable self.rqlst.add_constant_restriction(mainvar, self.rtype, value, - self.attrtype) + self.attrtype, self.comparator) - + class FilterRQLBuilder(object): """called by javascript to get a rql string from filter form""" def __init__(self, req): self.req = req - + def build_rql(self):#, tablefilter=False): form = self.req.form facetids = form['facets'].split(',') @@ -490,18 +492,18 @@ toupdate.append(facetid) return select.as_string(), toupdate - + ## html widets ################################################################ class FacetVocabularyWidget(HTMLWidget): - + def __init__(self, facet): self.facet = facet self.items = [] def append(self, item): self.items.append(item) - + def _render(self): title = html_escape(self.facet.title) facetid = html_escape(self.facet.id) @@ -527,7 +529,7 @@ self.w(u'\n') self.w(u'\n') - + class FacetStringWidget(HTMLWidget): def __init__(self, facet): self.facet = facet @@ -560,7 +562,7 @@ imgsrc = self.req.datadir_url + self.selected_img else: cssclass = '' - imgsrc = self.req.datadir_url + self.unselected_img + imgsrc = self.req.datadir_url + self.unselected_img self.w(u'
\n' % (cssclass, html_escape(unicode(self.value)))) self.w(u' ' % imgsrc) @@ -571,7 +573,7 @@ class FacetSeparator(HTMLWidget): def __init__(self, label=None): self.label = label or u' ' - + def _render(self): pass diff -r cd792cfda071 -r 334df77b38f5 web/test/jstest_python.jst --- a/web/test/jstest_python.jst Wed Jan 28 10:29:39 2009 +0100 +++ b/web/test/jstest_python.jst Wed Jan 28 10:30:06 2009 +0100 @@ -1,11 +1,13 @@ +// run tests with the following command line : +// $ crosscheck jstest_python.jst crosscheck.addTest({ setup: function() { crosscheck.load("testutils.js"); crosscheck.load("../data/jquery.js"); - crosscheck.load("../data/compat.js"); - crosscheck.load("../data/python.js"); + crosscheck.load("../data/cubicweb.compat.js"); + crosscheck.load("../data/cubicweb.python.js"); }, test_basic_number_parsing: function () { diff -r cd792cfda071 -r 334df77b38f5 web/test/test_views.py --- a/web/test/test_views.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/test/test_views.py Wed Jan 28 10:30:06 2009 +0100 @@ -37,7 +37,7 @@ def test_manual_tests(self): rset = self.execute('Any P,F,S WHERE P is EUser, P firstname F, P surname S') self.view('table', rset, template=None, displayfilter=True, displaycols=[0,2]) - rset = self.execute('Any P,F,S WHERE P is EUser, P firstname F, P surname S LIMIT 1') + rset = self.execute('Any P,F,S LIMIT 1 WHERE P is EUser, P firstname F, P surname S') rset.req.form['rtype'] = 'firstname' self.view('editrelation', rset, template=None, htmlcheck=False) rset.req.form['rtype'] = 'use_email' @@ -49,7 +49,7 @@ # sortable.js should not be included by default self.failIf('jquery.tablesorter.js' in self.view('oneline', rset)) # but should be included by the tableview - rset = self.execute('Any P,F,S WHERE P is EUser, P firstname F, P surname S LIMIT 1') + rset = self.execute('Any P,F,S LIMIT 1 WHERE P is EUser, P firstname F, P surname S') self.failUnless('jquery.tablesorter.js' in self.view('table', rset)) def test_js_added_only_once(self): diff -r cd792cfda071 -r 334df77b38f5 web/test/unittest_owl.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/test/unittest_owl.py Wed Jan 28 10:30:06 2009 +0100 @@ -0,0 +1,4075 @@ +"""unittests for schema2dot""" + +import os + +from logilab.common.testlib import TestCase, unittest_main +from logilab.common.compat import set +from cubicweb.devtools.testlib import WebTest + +from lxml import etree +from StringIO import StringIO + + +class OWLTC(WebTest): + + def test_schema2owl(self): + + parser = etree.XMLParser(dtd_validation=True) + + owl= StringIO(''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +''') + + rdf = StringIO(''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ''') + + + xmlschema_rdf = etree.parse(rdf) + xmlschema_owl = etree.parse(owl) + + owlschema = etree.XMLSchema(xmlschema_owl) + valid = StringIO(''' + + + + + + + ]> + + + + + inst_jplorg2 Cubicweb OWL Ontology + + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + + n + + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + 1 + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + 1 + 1 + + + + + + 1 + 1 + + + + + + n + + + + + + n + + + + + + 1 + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + 1 + + + + + + 1 + + + + + + 1 + + + + + + 1 + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + n + + + + + + 1 + 1 + + + + + + n + + + + + + 1 + 1 + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + n + + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ''') + doc = etree.parse(valid) + owlschema.validate(doc) + +if __name__ == '__main__': + unittest_main() + diff -r cd792cfda071 -r 334df77b38f5 web/test/unittest_viewselector.py --- a/web/test/unittest_viewselector.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/test/unittest_viewselector.py Wed Jan 28 10:30:06 2009 +0100 @@ -1,6 +1,5 @@ # -*- coding: iso-8859-1 -*- """XXX rename, split, reorganize this - """ import os.path as osp @@ -15,9 +14,9 @@ from cubicweb.web._exceptions import NoSelectableObject from cubicweb.web.action import Action from cubicweb.web.views import (baseviews, tableview, baseforms, calendar, - management, embedding, actions, startup, - euser, schemaentities, xbel, vcard, - idownloadable, wdoc, debug) + management, embedding, actions, startup, + euser, schemaentities, xbel, vcard, + treeview, idownloadable, wdoc, debug) from cubicweb.entities.lib import Card from cubicweb.interfaces import IMileStone @@ -75,6 +74,7 @@ ('index', startup.IndexView), ('info', management.ProcessInformationView), ('manage', startup.ManageView), + ('owl', startup.OWLView), ('schema', startup.SchemaView), ('systemepropertiesform', management.SystemEpropertiesForm)]) # no entity but etype @@ -94,14 +94,17 @@ [('csvexport', baseviews.CSVRsetView), ('ecsvexport', baseviews.CSVEntityView), ('editable-table', tableview.EditableTableView), + ('filetree', treeview.FileTreeView), ('list', baseviews.ListView), ('oneline', baseviews.OneLineView), ('primary', baseviews.PrimaryView), + ('rsetxml', baseviews.XMLRsetView), ('rss', baseviews.RssView), ('secondary', baseviews.SecondaryView), ('security', management.SecurityManagementView), ('table', tableview.TableView), ('text', baseviews.TextView), + ('treeview', treeview.TreeView), ('xbel', xbel.XbelView), ('xml', baseviews.XmlView), ]) @@ -111,14 +114,17 @@ [('csvexport', baseviews.CSVRsetView), ('ecsvexport', baseviews.CSVEntityView), ('editable-table', tableview.EditableTableView), + ('filetree', treeview.FileTreeView), ('list', baseviews.ListView), ('oneline', baseviews.OneLineView), ('primary', baseviews.PrimaryView), + ('rsetxml', baseviews.XMLRsetView), ('rss', baseviews.RssView), ('secondary', baseviews.SecondaryView), ('security', management.SecurityManagementView), ('table', tableview.TableView), ('text', baseviews.TextView), + ('treeview', treeview.TreeView), ('xbel', xbel.XbelView), ('xml', baseviews.XmlView), ]) @@ -128,14 +134,17 @@ [('csvexport', baseviews.CSVRsetView), ('ecsvexport', baseviews.CSVEntityView), ('editable-table', tableview.EditableTableView), + ('filetree', treeview.FileTreeView), ('list', baseviews.ListView), ('oneline', baseviews.OneLineView), ('primary', baseviews.PrimaryView), + ('rsetxml', baseviews.XMLRsetView), ('rss', baseviews.RssView), ('secondary', baseviews.SecondaryView), ('security', management.SecurityManagementView), ('table', tableview.TableView), ('text', baseviews.TextView), + ('treeview', treeview.TreeView), ('xbel', xbel.XbelView), ('xml', baseviews.XmlView), ]) @@ -144,6 +153,7 @@ self.assertListEqual(self.pviews(req, rset), [('csvexport', baseviews.CSVRsetView), ('editable-table', tableview.EditableTableView), + ('rsetxml', baseviews.XMLRsetView), ('table', tableview.TableView), ]) # list of euser entities @@ -152,14 +162,17 @@ [('csvexport', baseviews.CSVRsetView), ('ecsvexport', baseviews.CSVEntityView), ('editable-table', tableview.EditableTableView), + ('filetree', treeview.FileTreeView), ('list', baseviews.ListView), ('oneline', baseviews.OneLineView), ('primary', euser.EUserPrimaryView), + ('rsetxml', baseviews.XMLRsetView), ('rss', baseviews.RssView), ('secondary', baseviews.SecondaryView), ('security', management.SecurityManagementView), ('table', tableview.TableView), ('text', baseviews.TextView), + ('treeview', treeview.TreeView), ('vcard', vcard.VCardEUserView), ('xbel', xbel.XbelView), ('xml', baseviews.XmlView), diff -r cd792cfda071 -r 334df77b38f5 web/views/basecontrollers.py --- a/web/views/basecontrollers.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/views/basecontrollers.py Wed Jan 28 10:30:06 2009 +0100 @@ -235,7 +235,7 @@ stream.write(u'
') vtitle = self.req.form.get('vtitle') if vtitle: - w(u'

%s

\n' % vtitle) + stream.write(u'

%s

\n' % vtitle) view.pagination(req, rset, view.w, not view.need_navigation) if divid == 'pageContent': stream.write(u'
') diff -r cd792cfda071 -r 334df77b38f5 web/views/baseviews.py --- a/web/views/baseviews.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/views/baseviews.py Wed Jan 28 10:30:06 2009 +0100 @@ -8,7 +8,7 @@ :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" diff -r cd792cfda071 -r 334df77b38f5 web/views/navigation.py --- a/web/views/navigation.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/views/navigation.py Wed Jan 28 10:30:06 2009 +0100 @@ -11,9 +11,9 @@ from logilab.mtconverter import html_escape from cubicweb.interfaces import IPrevNext -from cubicweb.common.selectors import (paginated_rset, sortedrset_selector, - primary_view, match_context_prop, - one_line_rset, implement_interface) +from cubicweb.common.selectors import (paginated_rset, sorted_rset, + primary_view, match_context_prop, + one_line_rset, implement_interface) from cubicweb.common.uilib import cut from cubicweb.web.component import EntityVComponent, NavigationComponent @@ -49,7 +49,7 @@ """sorted navigation apply if navigation is needed (according to page size) and if the result set is sorted """ - __selectors__ = (paginated_rset, sortedrset_selector) + __selectors__ = (paginated_rset, sorted_rset) # number of considered chars to build page links nb_chars = 5 diff -r cd792cfda071 -r 334df77b38f5 web/views/startup.py --- a/web/views/startup.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/views/startup.py Wed Jan 28 10:30:06 2009 +0100 @@ -15,6 +15,24 @@ _ = unicode +OWL_CARD_MAP = {'1': '', + '?': '1', + '+': '1', + '*': '' + } + +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' + } class ManageView(StartupView): id = 'manage' @@ -190,3 +208,162 @@ skipmeta=skipmeta) self.w(ureport_as_html(layout)) + +class OWLView(StartupView): + id = 'owl' + title = _('owl') + templatable =False + + def call(self): + skipmeta = int(self.req.form.get('skipmeta', True)) + self.visit_schemaOWL(display_relations=True, + skiprels=('is', 'is_instance_of', 'identity', + 'owned_by', 'created_by'), + skipmeta=skipmeta) + + + def visit_schemaOWL(self, display_relations=0, + skiprels=(), skipmeta=True): + """get a layout for a whole schema""" + self.w(u''' + + + + + + + ]> + + + + + %s Cubicweb OWL Ontology + + + + ''' % (self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name, self.schema.name)) + 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] + keys = [(eschema.type, eschema) for eschema in entities] + self.w(u'') + for key, eschema in sorted(keys): + self.visit_entityschemaOWL(eschema, skiprels) + self.w(u'') + self.w(u'') + for key, eschema in sorted(keys): + self.visit_property_schemaOWL(eschema, skiprels) + self.w(u'') + for key, eschema in sorted(keys): + self.visit_property_object_schemaOWL(eschema, skiprels) + self.w(u'') + + def eschema_link_url(self, eschema): + return self.req.build_url('eetype/%s?vid=eschema' % eschema) + + def rschema_link_url(self, rschema): + return self.req.build_url('ertype/%s?vid=eschema' % rschema) + + def possible_views(self, etype): + rset = self.req.etype_rset(etype) + return [v for v in self._possible_views(self.req, rset) + if v.category != 'startupview'] + + def stereotype(self, name): + return Span((' <<%s>>' % name,), klass='stereotype') + + def visit_entityschemaOWL(self, eschema, skiprels=()): + """get a layout for an entity OWL schema""" + etype = eschema.type + + if eschema.meta: + self.stereotype('meta') + self.w(u''' + '''%eschema, stereotype) + else: + self.w(u''' + '''% eschema) + + self.w(u'') + for rschema, targetschemas, role in eschema.relation_definitions(): + if rschema.type in skiprels: + continue + if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): + continue + for oeschema in targetschemas: + label = rschema.type + if role == 'subject': + card = rschema.rproperty(eschema, oeschema, 'cardinality')[0] + else: + card = rschema.rproperty(oeschema, eschema, 'cardinality')[1] + self.w(u''' + + + %s + + + ''' % (label, OWL_CARD_MAP[card])) + + self.w(u'') + + 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''' + + + + + ''' + + % aname) + self.w(u'') + + def visit_property_schemaOWL(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 + if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')): + continue + rschemaurl = self.rschema_link_url(rschema) + for oeschema in targetschemas: + label = rschema.type + self.w(u''' + + + + + ''' % (label, eschema, oeschema.type )) + + def visit_property_object_schemaOWL(self, eschema, skiprels=()): + + 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''' + + + ''' + % (aname, eschema, OWL_CARD_MAP_DATA[card_data])) + + diff -r cd792cfda071 -r 334df77b38f5 web/views/tabs.py --- a/web/views/tabs.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/views/tabs.py Wed Jan 28 10:30:06 2009 +0100 @@ -10,24 +10,77 @@ from logilab.mtconverter import html_escape from cubicweb import NoSelectableObject, role +from cubicweb.common.view import EntityView from cubicweb.common.selectors import has_related_entities -from cubicweb.common.view import EntityView + +from cubicweb.common.utils import HTMLHead + +# the prepend hack only work for 1-level lazy views +# a whole lot different thing must be done otherwise +def prepend_post_inline_script(self, content): + self.post_inlined_scripts.insert(0, content) +HTMLHead.prepend_post_inline_script = prepend_post_inline_script + +class LazyViewMixin(object): -class TabsMixIn(object): - - def active_tab(self, default): + def lazyview(self, vid, eid=None, show_spinbox=True, w=None): + """a lazy version of wview + first version only support lazy viewing for an entity at a time + """ + w = w or self.w + self.req.add_js('cubicweb.lazy.js') + eid = eid if eid else '' + w(u'
' % (vid, vid, eid)) + if show_spinbox: + w(u'' % vid) + w(u'
') + self.req.html_headers.prepend_post_inline_script(u""" +jQuery(document).ready(function () { + $('#lazy-%(vid)s').bind('%(event)s', function(event) { + load_now('#lazy-%(vid)s', '#%(vid)s-hole'); + });});""" % {'event' : 'load_%s' % vid, + 'vid' : vid}) + + def forceview(self, vid): + """trigger an event that will force immediate loading of the view + on dom readyness + """ + self.req.add_js('.lazy.js') + self.req.html_headers.add_post_inline_script(u""" +jQuery(document).ready(function() { + trigger_load('%(vid)s');}) +""" % {'vid' : vid}) + +class TabsMixin(LazyViewMixin): + + def active_tab(self, tabs, default): cookie = self.req.get_cookie() activetab = cookie.get('active_tab') if activetab is None: cookie['active_tab'] = default self.req.set_cookie(cookie, 'active_tab') - return default - return activetab.value + tab = default + else: + tab = activetab.value + return tab if tab in tabs else default - def render_tabs(self, tabs, default, **kwargs): + def prune_tabs(self, tabs): + selected_tabs = [] + for tab in tabs: + try: + tabview = self.vreg.select_view(tab, self.req, self.rset) + selected_tabs.append(tab) + except NoSelectableObject: + continue + return selected_tabs + + def render_tabs(self, tabs, default, entity): self.req.add_css('ui.tabs.css') - self.req.add_js( ('ui.core.js', 'ui.tabs.js', 'cubicweb.tabs.js') ) - active_tab = self.active_tab(default) + self.req.add_js(('ui.core.js', 'ui.tabs.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js')) + # prune tabs : not all are to be shown + tabs = self.prune_tabs(tabs) + # select a tab + active_tab = self.active_tab(tabs, default) self.req.html_headers.add_post_inline_script(u""" jQuery(document).ready(function() { jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s }); @@ -39,13 +92,7 @@ w = self.w w(u'
') w(u'') w(u'
') - # XXX ajaxify ! - for tabview in tabviews: - w(u'
' % tabview.id) - tabview.dispatch(w=self.w, **kwargs) - w(u'
') + for tab in tabs: + w(u'
' % tab) + self.lazyview(tab, entity.eid) + w(u'
') + + +from cubicweb.web.views.basecontrollers import JSonController +class TabsController(JSonController): + + def js_remember_active_tab(self, tabname): + cookie = self.req.get_cookie() + cookie['active_tab'] = tabname + self.req.set_cookie(cookie, 'active_tab') + + def js_lazily(self, vid_eid): + vid, eid = vid_eid.split('-') + rset = self.req.eid_rset(eid) if eid else None + view = self.vreg.select_view(vid, self.req, rset) + return self._set_content_type(view, view.dispatch()) - -class EntityRelationTab(EntityView): +class DataDependantTab(EntityView): + """A view you should inherit from leftmost, + to wrap another actual view displaying entity related stuff. + Such a view _must_ provide the rtype, target and vid attributes : + + Example : + + class ProjectScreenshotsView(EntityRelationView): + "display project's screenshots" + id = title = _('projectscreenshots') + accepts = ('Project',) + rtype = 'screenshot' + target = 'object' + vid = 'gallery' + __selectors__ = EntityRelationView.__selectors__ + (one_line_rset,) + + + This is the view we want to have in a tab, only if there is something to show. + Then, just define as below, and declare this being the tab content : + + class ProjectScreenshotTab(DataDependantTab, ProjectScreenshotsView): + id = 'screenshots_tab' + """ __selectors__ = EntityView.__selectors__ + (has_related_entities,) vid = 'list' diff -r cd792cfda071 -r 334df77b38f5 web/views/treeview.py --- a/web/views/treeview.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/views/treeview.py Wed Jan 28 10:30:06 2009 +0100 @@ -9,8 +9,9 @@ class TreeView(EntityView): id = 'treeview' accepts = ('Any',) - fstree = False itemvid = 'treeitemview' + css_classes = 'treeview widget' + title = _('tree view') def call(self, subvid=None): if subvid is None and 'subvid' in self.req.form: @@ -19,17 +20,14 @@ subvid = 'oneline' self.req.add_css('jquery.treeview.css') self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js', 'cubicweb.widgets.js')) - css_classes = 'treeview widget' - if self.fstree: - css_classes += ' filetree' # XXX noautoload is a quick hack to avoid treeview to be rebuilt # after a json query and avoid double toggling bugs. # Need to find a way to do that cleanly. if 'noautoload' in self.req.form: - self.w(u'
    ' % css_classes) + self.w(u'
      ' % self.css_classes) else: self.w(u'
        ' - % css_classes) + % self.css_classes) for rowidx in xrange(len(self.rset)): self.wview(self.itemvid, self.rset, row=rowidx, col=0, vid=subvid, parentvid=self.id) @@ -40,14 +38,15 @@ """specific version of the treeview to display file trees """ id = 'filetree' - fstree = True + css_classes = 'treeview widget filetree' + title = _('file tree view') def call(self, subvid=None): super(FileTreeView, self).call(subvid='filetree-oneline') -class FileItemInnerView(OneLineView): +class FileItemInnerView(EntityView): """inner view used by the TreeItemView instead of oneline view This view adds an enclosing with some specific CSS classes @@ -58,10 +57,10 @@ def cell_call(self, row, col): entity = self.entity(row, col) if ITree.is_implemented_by(entity.__class__) and not entity.is_leaf(): - self.w(u'%s' % entity.view('oneline')) + self.w(u'
        %s
        ' % entity.view('oneline')) else: # XXX define specific CSS classes according to mime types - self.w(u'%s' % entity.view('oneline')) + self.w(u'
        %s
        ' % entity.view('oneline')) class DefaultTreeViewItemView(EntityView): @@ -76,7 +75,7 @@ if row == len(self.rset) - 1: self.w(u'
      • %s
      • ' % itemview) else: - self.w(u'
      • %s
      • ' % itemview) + self.w(u'
      • %s
      • ' % itemview) class TreeViewItemView(EntityView): diff -r cd792cfda071 -r 334df77b38f5 web/webconfig.py --- a/web/webconfig.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/webconfig.py Wed Jan 28 10:30:06 2009 +0100 @@ -1,7 +1,7 @@ """common web configuration for twisted/modpython applications :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" @@ -349,6 +349,6 @@ stream.close() def static_file_del(self, rpath): - if static_file_exists(rpath): + if self.static_file_exists(rpath): os.remove(join(self.static_directory, rpath)) diff -r cd792cfda071 -r 334df77b38f5 web/widgets.py --- a/web/widgets.py Wed Jan 28 10:29:39 2009 +0100 +++ b/web/widgets.py Wed Jan 28 10:30:06 2009 +0100 @@ -732,12 +732,13 @@ formatstr = req.property_value(self.format_key) return now().strftime(formatstr) - def add_localized_infos(self, req): + @classmethod + def add_localized_infos(cls, req): """inserts JS variables defining localized months and days""" # import here to avoid dependancy from cubicweb-common to simplejson _ = req._ - monthnames = [_(mname) for mname in self.monthnames] - daynames = [_(dname) for dname in self.daynames] + monthnames = [_(mname) for mname in cls.monthnames] + daynames = [_(dname) for dname in cls.daynames] req.html_headers.define_var('MONTHNAMES', monthnames) req.html_headers.define_var('DAYNAMES', daynames)