common/__init__.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 01 Dec 2009 08:43:37 +0100
branchstable
changeset 3953 19aefd78f61b
parent 2203 efdd3a9f9028
child 4023 eae23c40627a
child 4212 ab6573088b4a
permissions -rw-r--r--
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None) to fix a pitfall in form_render prototype: there is no way to distinguish between arguments that should be given to build_context from arguments that should be given to the renderer. This was problematic for instance with inlined form where a 'title' argument is given for the renderer, but is also used as default value for field whose name is 'title'...

"""Common subpackage of cubicweb : defines library functions used both on the
hg stserver side and on the client side

:organization: Logilab
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""

from logilab.common.adbh import FunctionDescr

from cubicweb._exceptions import * # bw compat

from rql.utils import register_function, iter_funcnode_variables

class COMMA_JOIN(FunctionDescr):
    supported_backends = ('postgres', 'sqlite',)
    rtype = 'String'

    @classmethod
    def st_description(cls, funcnode, mainindex, tr):
        return ', '.join(sorted(term.get_description(mainindex, tr)
                                for term in iter_funcnode_variables(funcnode)))

register_function(COMMA_JOIN)  # XXX do not expose?


class CONCAT_STRINGS(COMMA_JOIN):
    aggregat = True

register_function(CONCAT_STRINGS) # XXX bw compat

class GROUP_CONCAT(CONCAT_STRINGS):
    supported_backends = ('mysql', 'postgres', 'sqlite',)

register_function(GROUP_CONCAT)


class LIMIT_SIZE(FunctionDescr):
    supported_backends = ('postgres', 'sqlite',)
    rtype = 'String'

    @classmethod
    def st_description(cls, funcnode, mainindex, tr):
        return funcnode.children[0].get_description(mainindex, tr)

register_function(LIMIT_SIZE)


class TEXT_LIMIT_SIZE(LIMIT_SIZE):
    supported_backends = ('mysql', 'postgres', 'sqlite',)

register_function(TEXT_LIMIT_SIZE)