Просмотр исходного кода

Friendlier "please wait" message in flood protection.

Ralfp 12 лет назад
Родитель
Сommit
0bb3e474d7
1 измененных файлов с 16 добавлено и 6 удалено
  1. 16 6
      misago/apps/threadtype/mixins.py

+ 16 - 6
misago/apps/threadtype/mixins.py

@@ -1,6 +1,6 @@
 from django import forms
 from django.utils import timezone
-from django.utils.translation import ungettext, ugettext_lazy as _
+from django.utils.translation import ungettext_laxy, ugettext_lazy as _
 from misago.utils.strings import slugify
 
 class FloodProtectionMixin(object):
@@ -8,8 +8,18 @@ class FloodProtectionMixin(object):
         cleaned_data = super(FloodProtectionMixin, self).clean()
         diff = timezone.now() - self.request.user.last_post
         diff = diff.seconds + (diff.days * 86400)
-        if diff < 35:
-            raise forms.ValidationError(_("You can't post one message so quickly after another. Please wait a moment and try again."))
+        flood_limit = 35
+        wait_for = flood - diff
+        if wait_for > 0:
+            if wait_for < 5:
+                raise forms.ValidationError(_("You can't post one message so quickly after another. Please wait a moment and try again."))
+            else:
+                raise forms.ValidationError(ungettext(
+                        "You can't post one message so quickly after another. Please wait %(seconds)d second and try again.",
+                        "You can't post one message so quickly after another. Please wait %(seconds)d seconds and try again.",
+                    wait_for) % {
+                        'seconds': wait_for,
+                    })
         return cleaned_data
 
 
@@ -18,13 +28,13 @@ class ValidateThreadNameMixin(object):
         data = self.cleaned_data['thread_name']
         slug = slugify(data)
         if len(slug) < self.request.settings['thread_name_min']:
-            raise forms.ValidationError(ungettext(
+            raise forms.ValidationError(ungettext_laxy(
                                                   "Thread name must contain at least one alpha-numeric character.",
                                                   "Thread name must contain at least %(count)d alpha-numeric characters.",
                                                   self.request.settings['thread_name_min']
                                                   ) % {'count': self.request.settings['thread_name_min']})
         if len(data) > self.request.settings['thread_name_max']:
-            raise forms.ValidationError(ungettext(
+            raise forms.ValidationError(ungettext_laxy(
                                                   "Thread name cannot be longer than %(count)d character.",
                                                   "Thread name cannot be longer than %(count)d characters.",
                                                   self.request.settings['thread_name_max']
@@ -36,7 +46,7 @@ class ValidatePostLengthMixin(object):
     def clean_post(self):
         data = self.cleaned_data['post']
         if len(data) < self.request.settings['post_length_min']:
-            raise forms.ValidationError(ungettext(
+            raise forms.ValidationError(ungettext_laxy(
                                                   "Post content cannot be empty.",
                                                   "Post content cannot be shorter than %(count)d characters.",
                                                   self.request.settings['post_length_min']