cubicweb/entities/__init__.py
changeset 12567 26744ad37953
parent 12506 d97f9b8df92a
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """base application's entities class implementation: `AnyEntity`"""
    18 """base application's entities class implementation: `AnyEntity`"""
    19 
    19 
    20 from six import text_type, string_types
       
    21 
       
    22 from logilab.common.decorators import classproperty
    20 from logilab.common.decorators import classproperty
    23 
    21 
    24 from cubicweb import Unauthorized
    22 from cubicweb import Unauthorized
    25 from cubicweb.entity import Entity
    23 from cubicweb.entity import Entity
    26 
    24 
    32     __regid__ = 'Any'
    30     __regid__ = 'Any'
    33 
    31 
    34     @classproperty
    32     @classproperty
    35     def cw_etype(cls):
    33     def cw_etype(cls):
    36         """entity type as a unicode string"""
    34         """entity type as a unicode string"""
    37         return text_type(cls.__regid__)
    35         return cls.__regid__
    38 
    36 
    39     @classmethod
    37     @classmethod
    40     def cw_create_url(cls, req, **kwargs):
    38     def cw_create_url(cls, req, **kwargs):
    41         """ return the url of the entity creation form for this entity type"""
    39         """ return the url of the entity creation form for this entity type"""
    42         return req.build_url('add/%s' % cls.__regid__, **kwargs)
    40         return req.build_url('add/%s' % cls.__regid__, **kwargs)
   109         entity's attribute
   107         entity's attribute
   110         """
   108         """
   111         if rtype is None:
   109         if rtype is None:
   112             return self.dc_title().lower()
   110             return self.dc_title().lower()
   113         value = self.cw_attr_value(rtype)
   111         value = self.cw_attr_value(rtype)
   114         # do not restrict to `unicode` because Bytes will return a `str` value
   112         # do not restrict to `str` because Bytes will return a `str` value
   115         if isinstance(value, string_types):
   113         if isinstance(value, str):
   116             return self.printable_value(rtype, format='text/plain').lower()
   114             return self.printable_value(rtype, format='text/plain').lower()
   117         return value
   115         return value
   118 
   116 
   119 
   117 
   120 def fetch_config(fetchattrs, mainattr=None, pclass=AnyEntity, order='ASC'):
   118 def fetch_config(fetchattrs, mainattr=None, pclass=AnyEntity, order='ASC'):