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

Default ban message and note about expiration

Rafał Pitoń 11 лет назад
Родитель
Сommit
a638ea0e95
2 измененных файлов с 11 добавлено и 2 удалено
  1. 10 1
      misago/users/decorators.py
  2. 1 1
      misago/users/views/register.py

+ 10 - 1
misago/users/decorators.py

@@ -1,5 +1,7 @@
 from django.core.exceptions import PermissionDenied
+from django.template.defaultfilters import date as format_date
 from django.utils.translation import gettext_lazy as _
+
 from misago.users.bans import is_ip_banned
 
 
@@ -27,7 +29,14 @@ def deny_banned_ips(f):
     def decorator(request, *args, **kwargs):
         ban = is_ip_banned(request)
         if ban:
-            raise PermissionDenied(ban.get('message'))
+            default_message = _("Your IP address has been banned.")
+            ban_message = ban.get('message') or default_message
+            if ban.get('valid_until'):
+                ban_expires = format_date(ban['valid_until'])
+                expiration_message = _("This ban will expire on %(date)s.")
+                expiration_message = expiration_message % {'date': ban_expires}
+                ban_message = '%s\n\n%s' % (ban_message, expiration_message)
+            raise PermissionDenied(ban_message)
         else:
             return f(request, *args, **kwargs)
     return decorator

+ 1 - 1
misago/users/views/register.py

@@ -7,7 +7,7 @@ def register_decorator(f):
         if settings.account_activation == 'disabled':
             return registrations_off(request)
         else:
-            return register(request)
+            return f(request)
     return decorator