'Trap setting slug and title, recording initial value.'

def __setattr__(self, name, value):

    if getattr(self, 'id', None):
        if ((name in ('slug', 'title')) and hasattr(self, name)):
            old_name = ('old_' + name)
            if (not hasattr(self, old_name)):
                if (getattr(self, name).lower() != value.lower()):
                    setattr(self, old_name, getattr(self, name))
                ttp = TEMPLATE_TITLE_PREFIX
                if ((name == 'title') and (self.title.startswith(ttp) != value.startswith(ttp))):
                    setattr(self, old_name, getattr(self, name))
            elif (value == getattr(self, old_name)):
                delattr(self, old_name)
    super(Document, self).__setattr__(name, value)
