=====================
Custom URL extensions
=====================

Ella allows you to register custom actions on individual objects and/or
replace the default (rendering a template) with custom view function.

Registering your own action
===========================

To register your own action use ``ella.core.custom_urls.dispatcher``.
Supply your view function that looks like this::

    def my_action( request, url_bits, context ):
        ...
        return HttpResponse( ... )

register it under some name::

    dispatcher.register( 'my-action', my_action )
    # or for a given model only:
    dispatcher.register( 'my-action', my_action, model=Article )

Where:

    * ``url_bits`` is a list of tokens found in the URL after the token
      identifying the action (``object_url/my-action/one/two/three/`` ->
      ``['one', 'two', 'three']``).
    * ``context`` is a dictionary containing
        * ``object`` - actual object being rendered
        * ``listing`` - object's main `listing`_
        * ``category`` - current category
        * ``content_type`` - object's content_type
        * ``content_type_name`` - slugified localized name of the model (used
          in URLs)

It will then be availible on the desired URL.

.. _`listing`: ./listing.html

Replacing the ``object_detail``
===============================

In some cases you may wish to replace Ella's default behaviour when displaying
an object. This you can do via the same ``dispatcher`` with a function with a
signature of::

    def my_action( request, context ):
        ...
        return HttpResponse( ... )

Where ``context`` is the same dictionary as with custom actions.

``HitCount`` for the object is incremented even when using custom detail view.

