ella/ella — Issue #76: Pluggable backends for get_listings functionality
Author: HonzaKral
Created: 2012-02-18 01:50:10+00:00
State: open
Labels: cleanup, plugins, proposal

# Listing Handlers

I propose we create pluggable backends for listing displays. The way I envision
it working is simple - the `ListContentType` view accepts and additional GET
parameter that can specify the manager we wish to use with one being the default.

That parameter is passed to the `get_queryset_wrapper` method along with the
kwargs. This method looks up the correct backend (defaulting to current
implementation) and passes the kwargs in.

## Interface of the backend:

```python
class ListingHandler(object):
def __init__(self, category, children, content_types, offset, count, date_range):
...

def get_count(self):
"""
Number of Publishables in this query.
"""
...

def get_listings(self):
"""
Return an iterable of Listing-like dictionaries. Required fields:
- publish_from
- publishable
- category
- commercial
"""
...
```

## Configuration:

The sane default provided with ella will just use current functionality (using
`Listing` models with optional redis caching).

```python
ELLA_LISTING_HANDLERS = {
'default': 'ella.core.managers.ModelHandler',
'most_commented': 'ella_commens.handlers.MostCommentedHandler',
...
}
```

## Additional Requirements:

To facilitate sane implementations of Listing Handlers I will also create two
custom signals for ella - `content_published` and `content_unpublished` That
will be fired if a `Publishable` goes live or is taken off the site
respectively.

Note that this will require a periodic task (implemented as a management
command as well as a function to be used by celery for example) to fire the
signal for date-based `Publishable` objects as well as an additional field on
the model itself to flag already processed instances.