[rql2sql] fix generated sql for eid comparison. closes #1638695
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""base application's entities class implementation: `AnyEntity`"""__docformat__="restructuredtext en"fromwarningsimportwarnfromlogilab.common.deprecationimportdeprecatedfromlogilab.common.decoratorsimportcachedfromcubicwebimportUnauthorized,typed_eidfromcubicweb.entityimportEntityclassAnyEntity(Entity):"""an entity instance has e_schema automagically set on the class and instances have access to their issuing cursor """__regid__='Any'__implements__=()@classmethoddefcw_create_url(cls,req,**kwargs):""" return the url of the entity creation form for this entity type"""returnreq.build_url('add/%s'%cls.__regid__,**kwargs)# meta data api ###########################################################defdc_title(self):"""return a suitable *unicode* title for this entity"""forrschema,attrschemainself.e_schema.attribute_definitions():ifrschema.meta:continuevalue=self.cw_attr_value(rschema.type)ifvalue:# make the value printable (dates, floats, bytes, etc.)returnself.printable_value(rschema.type,value,attrschema.type,format='text/plain')returnu'%s #%s'%(self.dc_type(),self.eid)defdc_long_title(self):"""return a more detailled title for this entity"""returnself.dc_title()defdc_description(self,format='text/plain'):"""return a suitable description for this entity"""if'description'inself.e_schema.subjrels:returnself.printable_value('description',format=format)returnu''defdc_authors(self):"""return a suitable description for the author(s) of the entity"""try:return', '.join(u.name()foruinself.owned_by)exceptUnauthorized:returnu''defdc_creator(self):"""return a suitable description for the creator of the entity"""ifself.creator:returnself.creator.name()returnu''defdc_date(self,date_format=None):# XXX default to ISO 8601 ?"""return latest modification date of this entity"""returnself._cw.format_date(self.modification_date,date_format=date_format)defdc_type(self,form=''):"""return the display name for the type of this entity (translated)"""returnself.e_schema.display_name(self._cw,form)defdc_language(self):"""return language used by this entity (translated)"""# check if entities has internationalizable attributes# XXX one is enough or check if all String attributes are internationalizable?forrschema,attrschemainself.e_schema.attribute_definitions():ifrschema.rdef(self.e_schema,attrschema).internationalizable:returnself._cw._(self._cw.user.property_value('ui.language'))returnself._cw._(self._cw.vreg.property_value('ui.language'))@propertydefcreator(self):"""return the CWUser entity which has created this entity, or None if unknown or if the curent user doesn't has access to this euser """try:returnself.created_by[0]except(Unauthorized,IndexError):returnNone# abstractions making the whole things (well, some at least) working ######defsortvalue(self,rtype=None):"""return a value which can be used to sort this entity or given entity's attribute """ifrtypeisNone:returnself.dc_title().lower()value=self.cw_attr_value(rtype)# do not restrict to `unicode` because Bytes will return a `str` valueifisinstance(value,basestring):returnself.printable_value(rtype,format='text/plain').lower()returnvalue# edition helper functions ################################################deflinked_to(self,rtype,role,remove=True):"""if entity should be linked to another using '__linkto' form param for the given relation/role, return eids of related entities This method is consuming matching link-to information from form params if `remove` is True (by default). Computed values are stored into a `cw_linkto` attribute, a dictionary with (relation, role) as key and linked eids as value. """try:returnself.cw_linkto[(rtype,role)]exceptAttributeError:self.cw_linkto={}exceptKeyError:passlinktos=list(self._cw.list_form_param('__linkto'))linkedto=[]forlinktoinlinktos[:]:ltrtype,eid,ltrole=linkto.split(':')ifrtype==ltrtypeandrole==ltrole:# delete __linkto from form param to avoid it being added as# hidden inputifremove:linktos.remove(linkto)self._cw.form['__linkto']=linktoslinkedto.append(typed_eid(eid))self.cw_linkto[(rtype,role)]=linkedtoreturnlinkedto# server side helpers ###################################################### XXX: store a reference to the AnyEntity class since it is hijacked in goa# configuration and we need the actual reference to avoid infinite loops# in mroANYENTITY=AnyEntitydeffetch_config(fetchattrs,mainattr=None,pclass=AnyEntity,order='ASC'):ifpclassisANYENTITY:pclass=AnyEntity# AnyEntity and ANYENTITY may be different classesifpclassisnotNone:fetchattrs+=pclass.fetch_attrsifmainattrisNone:mainattr=fetchattrs[0]@classmethoddeffetch_order(cls,attr,var):ifattr==mainattr:return'%s%s'%(var,order)returnNonereturnfetchattrs,fetch_order