##// END OF EJS Templates
Added ban reasons. Added write-only bans.
neko259 -
r340:1472a0a6 default
parent child Browse files
Show More
@@ -11,7 +11,9 b' class BanMiddleware:'
11 11
12 12 if view_func != views.you_are_banned:
13 13 ip = utils.get_client_ip(request)
14 is_banned = Ban.objects.filter(ip=ip).exists()
14 bans = Ban.objects.filter(ip=ip)
15 15
16 if is_banned:
17 return redirect(views.you_are_banned) No newline at end of file
16 if bans.exists():
17 ban = bans[0]
18 if not ban.can_read:
19 return redirect(views.you_are_banned) No newline at end of file
@@ -16,6 +16,10 b' import thumbs'
16 16
17 17 import re
18 18
19 BAN_REASON_MAX_LENGTH = 200
20
21 BAN_REASON_AUTO = 'Auto'
22
19 23 IMAGE_THUMB_SIZE = (200, 150)
20 24
21 25 TITLE_MAX_LENGTH = 50
@@ -416,6 +420,9 b' class Setting(models.Model):'
416 420 class Ban(models.Model):
417 421
418 422 ip = models.GenericIPAddressField()
423 reason = models.CharField(default=BAN_REASON_AUTO,
424 max_length=BAN_REASON_MAX_LENGTH)
425 can_read = models.BooleanField(default=True)
419 426
420 427 def __unicode__(self):
421 428 return self.ip
@@ -34,7 +34,7 b''
34 34 <a class="link" href="{% url 'index' %}">{% trans "All threads" %}</a>
35 35 {% for tag in tags %}
36 36 <a class="tag" href="{% url 'tag' tag_name=tag.name %}"
37 >#{{ tag.name }}</a>
37 >#{{ tag.name }}</a>,
38 38 {% endfor %}
39 39 <a class="tag" href="{% url 'tags' %}" title="{% trans 'Tag management' %}"
40 40 >[...]</a>
@@ -91,7 +91,8 b''
91 91 {% for tag in thread.thread.get_tags %}
92 92 <a class="tag" href="
93 93 {% url 'tag' tag_name=tag.name %}">
94 #{{ tag.name }}</a>
94 #{{ tag.name }}</a
95 >{% if not forloop.last %},{% endif %}
95 96 {% endfor %}
96 97 </span>
97 98 {% endif %}
@@ -9,4 +9,5 b''
9 9 {% block staticcontent %}
10 10 <p><img src="{{ STATIC_URL }}images/banned.png" width="200" /></p>
11 11 <p>{% trans 'Your IP address has been banned. Contact the administrator' %}</p>
12 <p>{{ ban_reason }}</p>
12 13 {% endblock %} No newline at end of file
@@ -76,12 +76,13 b''
76 76 </div>
77 77 {% endif %}
78 78 </div>
79 {% if post.id == posts.0.id %}
79 {% if forloop.first %}
80 80 <div class="metadata">
81 81 <span class="tags">
82 82 {% for tag in post.get_tags %}
83 83 <a class="tag" href="{% url 'tag' tag.name %}">
84 #{{ tag.name }}</a>
84 #{{ tag.name }}</a
85 >{% if not forloop.last %},{% endif %}
85 86 {% endfor %}
86 87 </span>
87 88 </div>
@@ -22,6 +22,8 b' from boards.utils import get_client_ip'
22 22 import neboard
23 23 import re
24 24
25 BAN_REASON_SPAM = 'Autoban: spam bot'
26
25 27
26 28 def index(request, page=0):
27 29 context = _init_default_context(request)
@@ -317,7 +319,10 b' def ban(request, post_id):'
317 319
318 320 if user.is_moderator():
319 321 # TODO Show confirmation page before ban
320 Ban.objects.get_or_create(ip=post.poster_ip)
322 ban, created = Ban.objects.get_or_create(ip=post.poster_ip)
323 if created:
324 ban.reason = 'Banned for post ' + str(post_id)
325 ban.save()
321 326
322 327 return _redirect_to_next(request)
323 328
@@ -326,6 +331,9 b' def you_are_banned(request):'
326 331 """Show the page that notifies that user is banned"""
327 332
328 333 context = _init_default_context(request)
334
335 ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
336 context['ban_reason'] = ban.reason
329 337 return render(request, 'boards/staticpages/banned.html', context)
330 338
331 339
@@ -470,11 +478,16 b' def _redirect_to_next(request):'
470 478 return redirect(index)
471 479
472 480
481 @transaction.commit_on_success
473 482 def _ban_current_user(request):
474 483 """Add current user to the IP ban list"""
475 484
476 485 ip = utils.get_client_ip(request)
477 Ban.objects.get_or_create(ip=ip)
486 ban, created = Ban.objects.get_or_create(ip=ip)
487 if created:
488 ban.can_read = False
489 ban.reason = BAN_REASON_SPAM
490 ban.save()
478 491
479 492
480 493 def _remove_invalid_links(text):
@@ -4,6 +4,8 b''
4 4 [DONE] Better django admin pages to simplify admin operations
5 5 [DONE] Regen script to update all posts
6 6 [DONE] Remove jump links from refmaps
7 [DONE] Ban reasons. Split bans into 2 types "read-only" and "read
8 denied". Use second only for autoban for spam
7 9
8 10 [NOT STARTED] Tree view (JS)
9 11 [NOT STARTED] Adding tags to images filename
@@ -20,8 +22,6 b''
20 22 [NOT STARTED] Clean up tests and make them run ALWAYS
21 23 [NOT STARTED] Save image thumbnails size to the separate field
22 24 [NOT STARTED] Whitelist functionality. Permin autoban of an address
23 [NOT STARTED] Ban reasons. Split bans into 2 types "read-only" and "read
24 denied". Use second only for autoban for spam
25 25
26 26 = Bugs =
27 27 [DONE] Fix bug with creating threads from tag view
General Comments 0
You need to be logged in to leave comments. Login now