stephenmcd/mezzanine — pull request #334 by AlexHill (2012-07-26 07:52:21+00:00)
Title: Preserve URL structure when moving Pages

**Problem**
At the moment `Page.reset_slugs()` totally rebuilds the URL/slug tree when a page is moved. If I have a page called "Legal Stuff" with slug "about/legal" and I move it, `reset_slugs()` sets the slug to None and `get_slug()` generates a slug from the title, "<parent>/legal-stuff". The user loses their custom slug - and this happens for every descendant page.

**Solution**
This change preserves any custom slugs when moving pages around by just finding pages whose slugs start with the parent's slug, and replacing that part with the new parent's slug, preserving the rest. These pages do not necessarily form a subtree of the page tree (though they nearly always will in practise).

It adds a method `Page.set_slug()` to achieve this, which is called by another new method `Page.set_parent()`.

**Limitations**
What it doesn't do yet, because I'm not sure how best to do it, is call `set_slug()` when a Page is saved in the admin, so that simple changes to a slug also propagate down the tree. The problem is that one way or another we need to know the old slug, so `Model.save()` and `ModelAdmin.save_model()` are too late unless we hit the database again.

Any ideas? I have a few but overriding `Page.__setattr__()` is probably not the wisest path to go down. :)