Show More
@@ -14,10 +14,12 b' from boards import utils' | |||||
14 | from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \ |
|
14 | from boards.forms import ThreadForm, PostForm, SettingsForm, PlainErrorList, \ | |
15 | ThreadCaptchaForm, PostCaptchaForm, LoginForm, ModeratorSettingsForm |
|
15 | ThreadCaptchaForm, PostCaptchaForm, LoginForm, ModeratorSettingsForm | |
16 |
|
16 | |||
17 | from boards.models import Post, Tag, Ban, User, RANK_USER, SETTING_MODERATE |
|
17 | from boards.models import Post, Tag, Ban, User, RANK_USER, SETTING_MODERATE, \ | |
|
18 | REGEX_REPLY | |||
18 | from boards import authors |
|
19 | from boards import authors | |
19 | from boards.utils import get_client_ip |
|
20 | from boards.utils import get_client_ip | |
20 | import neboard |
|
21 | import neboard | |
|
22 | import re | |||
21 |
|
23 | |||
22 |
|
24 | |||
23 | def index(request, page=0): |
|
25 | def index(request, page=0): | |
@@ -70,6 +72,8 b' def _new_post(request, form, thread_id=b' | |||||
70 | title = data['title'] |
|
72 | title = data['title'] | |
71 | text = data['text'] |
|
73 | text = data['text'] | |
72 |
|
74 | |||
|
75 | text = _remove_invalid_links(text) | |||
|
76 | ||||
73 | if 'image' in data.keys(): |
|
77 | if 'image' in data.keys(): | |
74 | image = data['image'] |
|
78 | image = data['image'] | |
75 | else: |
|
79 | else: | |
@@ -457,3 +461,18 b' def _ban_current_user(request):' | |||||
457 |
|
461 | |||
458 | ip = utils.get_client_ip(request) |
|
462 | ip = utils.get_client_ip(request) | |
459 | Ban.objects.get_or_create(ip=ip) |
|
463 | Ban.objects.get_or_create(ip=ip) | |
|
464 | ||||
|
465 | ||||
|
466 | def _remove_invalid_links(text): | |||
|
467 | """ | |||
|
468 | Replace invalid links in posts so that they won't be parsed. | |||
|
469 | Invalid links are links to non-existent posts | |||
|
470 | """ | |||
|
471 | ||||
|
472 | for reply_number in re.finditer(REGEX_REPLY, text): | |||
|
473 | id = reply_number.group(1) | |||
|
474 | post = Post.objects.filter(id=id) | |||
|
475 | if not post.exists(): | |||
|
476 | text = string.replace(text, '>>' + id, id) | |||
|
477 | ||||
|
478 | return text |
General Comments 0
You need to be logged in to leave comments.
Login now