Show More
@@ -2,6 +2,7 b'' | |||||
2 |
|
2 | |||
3 | import re |
|
3 | import re | |
4 | import bbcode |
|
4 | import bbcode | |
|
5 | from django.core.exceptions import ObjectDoesNotExist | |||
5 | from django.core.urlresolvers import reverse |
|
6 | from django.core.urlresolvers import reverse | |
6 |
|
7 | |||
7 | import boards |
|
8 | import boards | |
@@ -116,18 +117,19 b' class CodePattern(TextFormatter):' | |||||
116 |
|
117 | |||
117 |
|
118 | |||
118 | def render_reflink(tag_name, value, options, parent, context): |
|
119 | def render_reflink(tag_name, value, options, parent, context): | |
119 | if not REFLINK_PATTERN.match(value): |
|
120 | result = '>>%s' % value | |
120 | return '>>%s' % value |
|
|||
121 |
|
121 | |||
122 | post_id = int(value) |
|
122 | if REFLINK_PATTERN.match(value): | |
|
123 | post_id = int(value) | |||
123 |
|
124 | |||
124 | posts = boards.models.Post.objects.filter(id=post_id) |
|
125 | try: | |
125 | if posts.exists(): |
|
126 | post = boards.models.Post.objects.get(id=post_id) | |
126 | post = posts[0] |
|
|||
127 |
|
127 | |||
128 |
|
|
128 | result = '<a href="%s">>>%s</a>' % (post.get_url(), post_id) | |
129 | else: |
|
129 | except ObjectDoesNotExist: | |
130 | return '>>%s' % value |
|
130 | pass | |
|
131 | ||||
|
132 | return result | |||
131 |
|
133 | |||
132 |
|
134 | |||
133 | def render_multithread(tag_name, value, options, parent, context): |
|
135 | def render_multithread(tag_name, value, options, parent, context): | |
@@ -136,12 +138,13 b' def render_multithread(tag_name, value, ' | |||||
136 | if REFLINK_PATTERN.match(value): |
|
138 | if REFLINK_PATTERN.match(value): | |
137 | post_id = int(value) |
|
139 | post_id = int(value) | |
138 |
|
140 | |||
139 | posts = boards.models.Post.objects.filter(id=post_id) |
|
141 | try: | |
140 | if posts.exists(): |
|
142 | post = boards.models.Post.objects.get(id=post_id) | |
141 | post = posts[0] |
|
|||
142 |
|
143 | |||
143 | if post.is_opening(): |
|
144 | if post.is_opening(): | |
144 | result = '<a href="%s">>>>%s</a>' % (post.get_url(), post_id) |
|
145 | result = '<a href="%s">>>>%s</a>' % (post.get_url(), post_id) | |
|
146 | except ObjectDoesNotExist: | |||
|
147 | pass | |||
145 |
|
148 | |||
146 | return result |
|
149 | return result | |
147 |
|
150 |
@@ -6,6 +6,7 b' import re' | |||||
6 | from urllib.parse import unquote |
|
6 | from urllib.parse import unquote | |
7 |
|
7 | |||
8 | from adjacent import Client |
|
8 | from adjacent import Client | |
|
9 | from django.core.exceptions import ObjectDoesNotExist | |||
9 | from django.core.urlresolvers import reverse |
|
10 | from django.core.urlresolvers import reverse | |
10 | from django.db import models, transaction |
|
11 | from django.db import models, transaction | |
11 | from django.db.models import TextField |
|
12 | from django.db.models import TextField | |
@@ -395,12 +396,16 b' class Post(models.Model, Viewable):' | |||||
395 | if recursive: |
|
396 | if recursive: | |
396 | for reply_number in re.finditer(REGEX_REPLY, self.get_raw_text()): |
|
397 | for reply_number in re.finditer(REGEX_REPLY, self.get_raw_text()): | |
397 | post_id = reply_number.group(1) |
|
398 | post_id = reply_number.group(1) | |
398 | ref_post = Post.objects.filter(id=post_id)[0] |
|
399 | ||
|
400 | try: | |||
|
401 | ref_post = Post.objects.get(id=post_id) | |||
399 |
|
402 | |||
400 | # If post is in this thread, its thread was already notified. |
|
403 | # If post is in this thread, its thread was already notified. | |
401 | # Otherwise, notify its thread separately. |
|
404 | # Otherwise, notify its thread separately. | |
402 | if ref_post.get_thread().id != thread_id: |
|
405 | if ref_post.get_thread().id != thread_id: | |
403 | ref_post.send_to_websocket(request, recursive=False) |
|
406 | ref_post.send_to_websocket(request, recursive=False) | |
|
407 | except ObjectDoesNotExist: | |||
|
408 | pass | |||
404 |
|
409 | |||
405 | def save(self, force_insert=False, force_update=False, using=None, |
|
410 | def save(self, force_insert=False, force_update=False, using=None, | |
406 | update_fields=None): |
|
411 | update_fields=None): | |
@@ -437,9 +442,10 b' class Post(models.Model, Viewable):' | |||||
437 |
|
442 | |||
438 | for reply_number in re.finditer(REGEX_REPLY, self.get_raw_text()): |
|
443 | for reply_number in re.finditer(REGEX_REPLY, self.get_raw_text()): | |
439 | post_id = reply_number.group(1) |
|
444 | post_id = reply_number.group(1) | |
440 | ref_post = Post.objects.filter(id=post_id) |
|
445 | ||
441 | if ref_post.count() > 0: |
|
446 | try: | |
442 |
referenced_post = |
|
447 | referenced_post = Post.objects.get(id=post_id) | |
|
448 | ||||
443 | referenced_post.referenced_posts.add(self) |
|
449 | referenced_post.referenced_posts.add(self) | |
444 | referenced_post.last_edit_time = self.pub_time |
|
450 | referenced_post.last_edit_time = self.pub_time | |
445 | referenced_post.build_refmap() |
|
451 | referenced_post.build_refmap() | |
@@ -452,13 +458,20 b' class Post(models.Model, Viewable):' | |||||
452 |
|
458 | |||
453 | thread.last_edit_time = self.pub_time |
|
459 | thread.last_edit_time = self.pub_time | |
454 | thread.save(update_fields=['last_edit_time', 'bumpable']) |
|
460 | thread.save(update_fields=['last_edit_time', 'bumpable']) | |
|
461 | except ObjectDoesNotExist: | |||
|
462 | pass | |||
455 |
|
463 | |||
456 | def connect_threads(self): |
|
464 | def connect_threads(self): | |
|
465 | """ | |||
|
466 | If the referenced post is an OP in another thread, | |||
|
467 | make this post multi-thread. | |||
|
468 | """ | |||
|
469 | ||||
457 | for reply_number in re.finditer(REGEX_MULTI_THREAD, self.get_raw_text()): |
|
470 | for reply_number in re.finditer(REGEX_MULTI_THREAD, self.get_raw_text()): | |
458 | post_id = reply_number.group(1) |
|
471 | post_id = reply_number.group(1) | |
459 | ref_post = Post.objects.filter(id=post_id) |
|
472 | ||
460 | if ref_post.count() > 0: |
|
473 | try: | |
461 |
referenced_post = |
|
474 | referenced_post = Post.objects.get(id=post_id) | |
462 |
|
475 | |||
463 | if referenced_post.is_opening(): |
|
476 | if referenced_post.is_opening(): | |
464 | referenced_threads = referenced_post.get_threads().all() |
|
477 | referenced_threads = referenced_post.get_threads().all() | |
@@ -470,3 +483,5 b' class Post(models.Model, Viewable):' | |||||
470 | thread.save(update_fields=['last_edit_time', 'bumpable']) |
|
483 | thread.save(update_fields=['last_edit_time', 'bumpable']) | |
471 |
|
484 | |||
472 | self.threads.add(thread) |
|
485 | self.threads.add(thread) | |
|
486 | except ObjectDoesNotExist: | |||
|
487 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now