'Check that user or IP address does not perform content edits that
are not allowed.
current_revision can be any object inheriting from models.BaseRevisionMixin'

def check_spam(self):

    request = self.request
    user = None
    ip_address = None
    if request.user.is_authenticated():
        user = request.user
    else:
        ip_address = request.META.get(u'REMOTE_ADDR', None)
    if (not (user or ip_address)):
        raise forms.ValidationError(ugettext(u'Spam    protection    failed    to    find    both    a    logged    in    user    and    an    IP    address.'))
    def check_interval(from_time, max_count, interval_name):
        from_time = (timezone.now() - timedelta(minutes=settings.REVISIONS_MINUTES_LOOKBACK))
        revisions = self.revision_model.objects.filter(created__gte=from_time)
        if user:
            revisions = revisions.filter(user=user)
        if ip_address:
            revisions = revisions.filter(ip_address=ip_address)
        revisions = revisions.count()
        if (revisions >= max_count):
            raise forms.ValidationError((ugettext(u'Spam    protection:    You    are    only    allowed    to    create    or    edit    %(revisions)d    article(s)    per    %(interval_name)s.') % {u'revisions': max_count, u'interval_name': interval_name}))
    if (not settings.LOG_IPS_ANONYMOUS):
        return
    if request.user.has_perm(u'wiki.moderator'):
        return
    from_time = (timezone.now() - timedelta(minutes=settings.REVISIONS_MINUTES_LOOKBACK))
    if request.user.is_authenticated():
        per_minute = settings.REVISIONS_PER_MINUTES
    else:
        per_minute = settings.REVISIONS_PER_MINUTES_ANONYMOUS
    check_interval(from_time, per_minute, (_(u'minute') if (settings.REVISIONS_MINUTES_LOOKBACK == 1) else (_(u'%d    minutes') % settings.REVISIONS_MINUTES_LOOKBACK)))
    from_time = (timezone.now() - timedelta(minutes=60))
    if request.user.is_authenticated():
        per_hour = settings.REVISIONS_PER_MINUTES
    else:
        per_hour = settings.REVISIONS_PER_MINUTES_ANONYMOUS
    check_interval(from_time, per_hour, _(u'hour'))
