# HG changeset patch # User neko259 # Date 2013-11-08 20:18:31 # Node ID 1472a0a6853e6c7201b9fab961debfc14bf56a00 # Parent d16f9b448738c8403138bace3de87c31325c67c6 Added ban reasons. Added write-only bans. diff --git a/boards/middlewares.py b/boards/middlewares.py --- a/boards/middlewares.py +++ b/boards/middlewares.py @@ -11,7 +11,9 @@ class BanMiddleware: if view_func != views.you_are_banned: ip = utils.get_client_ip(request) - is_banned = Ban.objects.filter(ip=ip).exists() + bans = Ban.objects.filter(ip=ip) - if is_banned: - return redirect(views.you_are_banned) \ No newline at end of file + if bans.exists(): + ban = bans[0] + if not ban.can_read: + return redirect(views.you_are_banned) \ No newline at end of file diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -16,6 +16,10 @@ import thumbs import re +BAN_REASON_MAX_LENGTH = 200 + +BAN_REASON_AUTO = 'Auto' + IMAGE_THUMB_SIZE = (200, 150) TITLE_MAX_LENGTH = 50 @@ -416,6 +420,9 @@ class Setting(models.Model): class Ban(models.Model): ip = models.GenericIPAddressField() + reason = models.CharField(default=BAN_REASON_AUTO, + max_length=BAN_REASON_MAX_LENGTH) + can_read = models.BooleanField(default=True) def __unicode__(self): return self.ip diff --git a/boards/templates/boards/base.html b/boards/templates/boards/base.html --- a/boards/templates/boards/base.html +++ b/boards/templates/boards/base.html @@ -34,7 +34,7 @@ {% trans "All threads" %} {% for tag in tags %} #{{ tag.name }} + >#{{ tag.name }}, {% endfor %} [...] diff --git a/boards/templates/boards/posting_general.html b/boards/templates/boards/posting_general.html --- a/boards/templates/boards/posting_general.html +++ b/boards/templates/boards/posting_general.html @@ -91,7 +91,8 @@ {% for tag in thread.thread.get_tags %} - #{{ tag.name }} + #{{ tag.name }}{% if not forloop.last %},{% endif %} {% endfor %} {% endif %} diff --git a/boards/templates/boards/staticpages/banned.html b/boards/templates/boards/staticpages/banned.html --- a/boards/templates/boards/staticpages/banned.html +++ b/boards/templates/boards/staticpages/banned.html @@ -9,4 +9,5 @@ {% block staticcontent %}

{% trans 'Your IP address has been banned. Contact the administrator' %}

+

{{ ban_reason }}

{% endblock %} \ No newline at end of file diff --git a/boards/templates/boards/thread.html b/boards/templates/boards/thread.html --- a/boards/templates/boards/thread.html +++ b/boards/templates/boards/thread.html @@ -76,12 +76,13 @@ {% endif %} - {% if post.id == posts.0.id %} + {% if forloop.first %}
{% for tag in post.get_tags %} - #{{ tag.name }} + #{{ tag.name }}{% if not forloop.last %},{% endif %} {% endfor %}
diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -22,6 +22,8 @@ from boards.utils import get_client_ip import neboard import re +BAN_REASON_SPAM = 'Autoban: spam bot' + def index(request, page=0): context = _init_default_context(request) @@ -317,7 +319,10 @@ def ban(request, post_id): if user.is_moderator(): # TODO Show confirmation page before ban - Ban.objects.get_or_create(ip=post.poster_ip) + ban, created = Ban.objects.get_or_create(ip=post.poster_ip) + if created: + ban.reason = 'Banned for post ' + str(post_id) + ban.save() return _redirect_to_next(request) @@ -326,6 +331,9 @@ def you_are_banned(request): """Show the page that notifies that user is banned""" context = _init_default_context(request) + + ban = get_object_or_404(Ban, ip=utils.get_client_ip(request)) + context['ban_reason'] = ban.reason return render(request, 'boards/staticpages/banned.html', context) @@ -470,11 +478,16 @@ def _redirect_to_next(request): return redirect(index) +@transaction.commit_on_success def _ban_current_user(request): """Add current user to the IP ban list""" ip = utils.get_client_ip(request) - Ban.objects.get_or_create(ip=ip) + ban, created = Ban.objects.get_or_create(ip=ip) + if created: + ban.can_read = False + ban.reason = BAN_REASON_SPAM + ban.save() def _remove_invalid_links(text): diff --git a/todo.txt b/todo.txt --- a/todo.txt +++ b/todo.txt @@ -4,6 +4,8 @@ [DONE] Better django admin pages to simplify admin operations [DONE] Regen script to update all posts [DONE] Remove jump links from refmaps +[DONE] Ban reasons. Split bans into 2 types "read-only" and "read +denied". Use second only for autoban for spam [NOT STARTED] Tree view (JS) [NOT STARTED] Adding tags to images filename @@ -20,8 +22,6 @@ [NOT STARTED] Clean up tests and make them run ALWAYS [NOT STARTED] Save image thumbnails size to the separate field [NOT STARTED] Whitelist functionality. Permin autoban of an address -[NOT STARTED] Ban reasons. Split bans into 2 types "read-only" and "read -denied". Use second only for autoban for spam = Bugs = [DONE] Fix bug with creating threads from tag view