Show More
@@ -130,6 +130,22 b' def render_reflink(tag_name, value, opti' | |||||
130 | return '>>%s' % value |
|
130 | return '>>%s' % value | |
131 |
|
131 | |||
132 |
|
132 | |||
|
133 | def render_multithread(tag_name, value, options, parent, context): | |||
|
134 | result = '>>>%s' % value | |||
|
135 | ||||
|
136 | if REFLINK_PATTERN.match(value): | |||
|
137 | post_id = int(value) | |||
|
138 | ||||
|
139 | posts = boards.models.Post.objects.filter(id=post_id) | |||
|
140 | if posts.exists(): | |||
|
141 | post = posts[0] | |||
|
142 | ||||
|
143 | if post.is_opening(): | |||
|
144 | result = '<a href="%s">>>>%s</a>' % (post.get_url(), post_id) | |||
|
145 | ||||
|
146 | return result | |||
|
147 | ||||
|
148 | ||||
133 | def render_quote(tag_name, value, options, parent, context): |
|
149 | def render_quote(tag_name, value, options, parent, context): | |
134 | source = '' |
|
150 | source = '' | |
135 | if 'source' in options: |
|
151 | if 'source' in options: | |
@@ -163,6 +179,7 b' def bbcode_extended(markup):' | |||||
163 | # browsers except firefox, when the div's does. |
|
179 | # browsers except firefox, when the div's does. | |
164 | parser = bbcode.Parser(newline='<div class="br"></div>') |
|
180 | parser = bbcode.Parser(newline='<div class="br"></div>') | |
165 | parser.add_formatter('post', render_reflink, strip=True) |
|
181 | parser.add_formatter('post', render_reflink, strip=True) | |
|
182 | parser.add_formatter('thread', render_multithread, strip=True) | |||
166 | parser.add_formatter('quote', render_quote, strip=True) |
|
183 | parser.add_formatter('quote', render_quote, strip=True) | |
167 | parser.add_formatter('user', render_notification, strip=True) |
|
184 | parser.add_formatter('user', render_notification, strip=True) | |
168 | parser.add_simple_formatter('comment', |
|
185 | parser.add_simple_formatter('comment', |
@@ -43,6 +43,7 b" NO_IP = '0.0.0.0'" | |||||
43 | UNKNOWN_UA = '' |
|
43 | UNKNOWN_UA = '' | |
44 |
|
44 | |||
45 | REGEX_REPLY = re.compile(r'\[post\](\d+)\[/post\]') |
|
45 | REGEX_REPLY = re.compile(r'\[post\](\d+)\[/post\]') | |
|
46 | REGEX_MULTI_THREAD = re.compile(r'\[thread\](\d+)\[/thread\]') | |||
46 | REGEX_URL = re.compile(r'https?\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?') |
|
47 | REGEX_URL = re.compile(r'https?\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?') | |
47 | REGEX_NOTIFICATION = re.compile(r'\[user\](\w+)\[/user\]') |
|
48 | REGEX_NOTIFICATION = re.compile(r'\[user\](\w+)\[/user\]') | |
48 |
|
49 | |||
@@ -63,7 +64,8 b" DIFF_TYPE_HTML = 'html'" | |||||
63 | DIFF_TYPE_JSON = 'json' |
|
64 | DIFF_TYPE_JSON = 'json' | |
64 |
|
65 | |||
65 | PREPARSE_PATTERNS = { |
|
66 | PREPARSE_PATTERNS = { | |
66 |
r'>>(\d+)': r'[ |
|
67 | r'>>>(\d+)': r'[thread]\1[/thread]', # Multi-thread post ">>>123" | |
|
68 | r'(?<!>)>>(\d+)': r'[post]\1[/post]', # Reflink ">>123" | |||
67 | r'^>([^>].+)': r'[quote]\1[/quote]', # Quote ">text" |
|
69 | r'^>([^>].+)': r'[quote]\1[/quote]', # Quote ">text" | |
68 | r'^//(.+)': r'[comment]\1[/comment]', # Comment "//text" |
|
70 | r'^//(.+)': r'[comment]\1[/comment]', # Comment "//text" | |
69 | r'\B@(\w+)': r'[user]\1[/user]', # User notification "@user" |
|
71 | r'\B@(\w+)': r'[user]\1[/user]', # User notification "@user" | |
@@ -119,6 +121,7 b' class PostManager(models.Manager):' | |||||
119 | thread.save() |
|
121 | thread.save() | |
120 |
|
122 | |||
121 | post.connect_replies() |
|
123 | post.connect_replies() | |
|
124 | post.connect_threads() | |||
122 | post.connect_notifications() |
|
125 | post.connect_notifications() | |
123 |
|
126 | |||
124 | return post |
|
127 | return post | |
@@ -450,4 +453,20 b' class Post(models.Model, Viewable):' | |||||
450 | thread.last_edit_time = self.pub_time |
|
453 | thread.last_edit_time = self.pub_time | |
451 | thread.save(update_fields=['last_edit_time', 'bumpable']) |
|
454 | thread.save(update_fields=['last_edit_time', 'bumpable']) | |
452 |
|
455 | |||
453 | self.threads.add(thread) |
|
456 | def connect_threads(self): | |
|
457 | for reply_number in re.finditer(REGEX_MULTI_THREAD, self.get_raw_text()): | |||
|
458 | post_id = reply_number.group(1) | |||
|
459 | ref_post = Post.objects.filter(id=post_id) | |||
|
460 | if ref_post.count() > 0: | |||
|
461 | referenced_post = ref_post[0] | |||
|
462 | ||||
|
463 | if referenced_post.is_opening(): | |||
|
464 | referenced_threads = referenced_post.get_threads().all() | |||
|
465 | for thread in referenced_threads: | |||
|
466 | if thread.can_bump(): | |||
|
467 | thread.update_bump_status() | |||
|
468 | ||||
|
469 | thread.last_edit_time = self.pub_time | |||
|
470 | thread.save(update_fields=['last_edit_time', 'bumpable']) | |||
|
471 | ||||
|
472 | self.threads.add(thread) |
General Comments 0
You need to be logged in to leave comments.
Login now