floodprotection.py 680 B

12345678910111213141516171819
  1. from django.utils import timezone
  2. from django.utils.translation import ugettext as _
  3. from misago.threads.posting import PostingMiddleware, PostingInterrupt
  4. MIN_POSTING_PAUSE = 3
  5. class FloodProtectionMiddleware(PostingMiddleware):
  6. def interrupt_posting(self, form):
  7. message = _("You can't post message so quickly after previous one.")
  8. if self.user.last_posted_on:
  9. previous_post = timezone.now() - self.user.last_posted_on
  10. if previous_post.total_seconds() < MIN_POSTING_PAUSE:
  11. raise PostingInterrupt(message)
  12. self.user.last_posted_on = timezone.now()
  13. self.user.update_fields.append('last_posted_on')