'Persists the revision and returns it.
Takes the view request and document of the revision.
Does some specific things when the revision is fully saved.'

def save(self, document, **kwargs):

    is_first_edit = (not self.request.user.wiki_revisions().exists())
    kwargs['commit'] = False
    if (self.section_id and self.instance and self.instance.document):
        doc = Document.objects.get(pk=self.instance.document.id)
        old_rev = doc.current_revision
        new_rev = super(RevisionForm, self).save(**kwargs)
        new_rev.document = document
        new_rev.creator = self.request.user
        new_rev.toc_depth = old_rev.toc_depth
        new_rev.save()
        new_rev.review_tags.set(*list(old_rev.review_tags.names()))
    else:
        new_rev = super(RevisionForm, self).save(**kwargs)
        new_rev.document = document
        new_rev.creator = self.request.user
        new_rev.toc_depth = self.cleaned_data['toc_depth']
        new_rev.save()
        new_rev.review_tags.set(*self.cleaned_data['review_tags'])
        new_rev.localization_tags.set(*self.cleaned_data['localization_tags'])
        if waffle.switch_is_active('store_revision_ips'):
            RevisionIP.objects.log(revision=new_rev, headers=self.request.META, data=json.dumps(self.akismet_parameters(), indent=2, sort_keys=True))
        if is_first_edit:
            send_first_edit_email.delay(new_rev.pk)
        document.schedule_rendering('max-age=0')
        EditDocumentEvent(new_rev).fire(exclude=new_rev.creator)
    return new_rev
