elbaschid/django-url-tracker — pull request #3 by saulshanabrook (2013-02-16 20:46:25+00:00)
Title: Allow Tracking of Multiple URLs per Model

I wanted to be able to track not only the url of the model, but also say the url of a file upload. So that if the file path is changed, there will be a redirect in place. However, currently, the `django-url-tracker` sets attributes on the model to maintain state between signals. Therefore in order to allow multiple urls per model, these attributes would have to be expanded. Maybe something like this.

```python
model._old_url = {
'get_absolute_url': 'that/url',
'get_image_url': 'another/url,
}
```

However I decided that adding the extra complexity of creating a new data structure on each model could be avoided. Instead of saving the urls between signals on the model, I decided to create different functions for each of the urls. So for instance, the pre_save signal for `get_image_url` will call a [partial function](http://docs.python.org/2/library/functools.html#functools.partial) of `lookup_previous_url` with `absolute_url_method='get_image_url'`. That way the signal calls a function that already knows the `absolute_url_method` and doesn't have to check the model for any attributes.

Maintaining the `old_url` between `pre_save` and `post_save` signals is handled differently. The `post_save` signal somehow has to know the `old_url`, which is determined in the `pre_save`. If it can not look to the model, that means that `pre_save` signal creates a `post_save` signal inside of it, with a partial function that passes in the `absolute_url_method` and the `old_url`. Then, when the `post_save` signal calls that partial function, it deactivates itself, so it's not left around for next time.