Usage

To benefit from fancy URLs for a given entity (Content type in the following example)

  1. in shema.py add an entity_url_of relation with your Content entity:
class entity_url_of(RelationDefinition):
    subject = 'EntityURL'
    object = 'Content
  1. Provide the following implementation for the rest_path method in entities.py:
class Content(object):
    """customized class for content entities"""
    __regid__ = 'Content'
    def rest_path(self, use_ext_eid=False):
        return self.cw_adapt_to('IRESTPath').rest_path()
  1. If you have existing data, the following migration with activate the new urls (cubicweb-ctl shell myapp session)

    ReST / HTML errors:System Message: WARNING/2 (&lt;string&gt; , line 28)</p>

    Literal block expected; none found.

>>> add_cube('fancyurls') # add_relation_definition('EntityURL', 'entity_url_of', 'Content')
>>> for entity in rql('Any X WHERE X is Content').entities():
>>>   entity.cw_adapt_to('IRESTPath').create_entity_path()
>>> commit()
  1. If desired, you can customize URL generation or handling by implementing custom IRESTPath adapter for your entity types
source repositoryfancyurls repository
test environmentfancyurls test env
owned bysthenault
may be discussed on<not specified>
use license<not specified>