##// END OF EJS Templates
Removed django-markupfield as it is incompatible with the new migrations. Use 2 fields for storing raw and rendered text and work with them directly
neko259 -
r881:35b56a08 default
parent child Browse files
Show More
@@ -158,15 +158,16 b' def bbcode_extended(markup):'
158 parser.add_formatter('post', render_reflink, strip=True)
158 parser.add_formatter('post', render_reflink, strip=True)
159 parser.add_formatter('quote', render_quote, strip=True)
159 parser.add_formatter('quote', render_quote, strip=True)
160 parser.add_simple_formatter('comment',
160 parser.add_simple_formatter('comment',
161 u'<span class="comment">//%(value)s</span>')
161 '<span class="comment">//%(value)s</span>')
162 parser.add_simple_formatter('spoiler',
162 parser.add_simple_formatter('spoiler',
163 u'<span class="spoiler">%(value)s</span>')
163 '<span class="spoiler">%(value)s</span>')
164 # TODO Use <s> here
164 # TODO Use <s> here
165 parser.add_simple_formatter('s',
165 parser.add_simple_formatter('s',
166 u'<span class="strikethrough">%(value)s</span>')
166 '<span class="strikethrough">%(value)s</span>')
167 # TODO Why not use built-in tag?
167 # TODO Why not use built-in tag?
168 parser.add_simple_formatter('code',
168 parser.add_simple_formatter('code',
169 u'<pre><code>%(value)s</pre></code>', render_embedded=False)
169 '<pre><code>%(value)s</pre></code>',
170 render_embedded=False)
170
171
171 text = preparse_text(markup)
172 text = preparse_text(markup)
172 return parser.format(text)
173 return parser.format(text)
@@ -2,7 +2,6 b''
2 from __future__ import unicode_literals
2 from __future__ import unicode_literals
3
3
4 from django.db import models, migrations
4 from django.db import models, migrations
5 import markupfield.fields
6 import boards.models.image
5 import boards.models.image
7 import boards.models.base
6 import boards.models.base
8 import boards.thumbs
7 import boards.thumbs
@@ -32,7 +31,7 b' class Migration(migrations.Migration):'
32 ('id', models.AutoField(serialize=False, auto_created=True, primary_key=True, verbose_name='ID')),
31 ('id', models.AutoField(serialize=False, auto_created=True, primary_key=True, verbose_name='ID')),
33 ('title', models.CharField(max_length=200)),
32 ('title', models.CharField(max_length=200)),
34 ('pub_time', models.DateTimeField()),
33 ('pub_time', models.DateTimeField()),
35 ('text', markupfield.fields.MarkupField()),
34 ('text', models.TextField(null=True, blank=True)),
36 ('text_markup_type', models.CharField(choices=[('', '--'), ('bbcode', 'bbcode')], max_length=30, default='bbcode')),
35 ('text_markup_type', models.CharField(choices=[('', '--'), ('bbcode', 'bbcode')], max_length=30, default='bbcode')),
37 ('poster_ip', models.GenericIPAddressField()),
36 ('poster_ip', models.GenericIPAddressField()),
38 ('_text_rendered', models.TextField(editable=False)),
37 ('_text_rendered', models.TextField(editable=False)),
@@ -1,24 +1,25 b''
1 from datetime import datetime, timedelta, date
1 from datetime import datetime, timedelta, date
2 from datetime import time as dtime
2 from datetime import time as dtime
3 from adjacent import Client
4 import logging
3 import logging
5 import re
4 import re
6
5
6 from adjacent import Client
7 from django.core.cache import cache
7 from django.core.cache import cache
8 from django.core.urlresolvers import reverse
8 from django.core.urlresolvers import reverse
9 from django.db import models, transaction
9 from django.db import models, transaction
10 from django.shortcuts import get_object_or_404
10 from django.db.models import TextField
11 from django.template import RequestContext
11 from django.template import RequestContext
12 from django.template.loader import render_to_string
12 from django.template.loader import render_to_string
13 from django.utils import timezone
13 from django.utils import timezone
14 from markupfield.fields import MarkupField
14
15 from boards import settings
15 from boards import settings
16
16 from boards.mdx_neboard import bbcode_extended
17 from boards.models import PostImage
17 from boards.models import PostImage
18 from boards.models.base import Viewable
18 from boards.models.base import Viewable
19 from boards.models.thread import Thread
19 from boards.models.thread import Thread
20 from boards.utils import datetime_to_epoch
20 from boards.utils import datetime_to_epoch
21
21
22
22 WS_CHANNEL_THREAD = "thread:"
23 WS_CHANNEL_THREAD = "thread:"
23
24
24 APP_LABEL_BOARDS = 'boards'
25 APP_LABEL_BOARDS = 'boards'
@@ -34,8 +35,6 b' IMAGE_THUMB_SIZE = (200, 150)'
34
35
35 TITLE_MAX_LENGTH = 200
36 TITLE_MAX_LENGTH = 200
36
37
37 DEFAULT_MARKUP_TYPE = 'bbcode'
38
39 # TODO This should be removed
38 # TODO This should be removed
40 NO_IP = '0.0.0.0'
39 NO_IP = '0.0.0.0'
41
40
@@ -127,7 +126,7 b' class PostManager(models.Manager):'
127 Connects replies to a post to show them as a reflink map
126 Connects replies to a post to show them as a reflink map
128 """
127 """
129
128
130 for reply_number in re.finditer(REGEX_REPLY, post.text.raw):
129 for reply_number in re.finditer(REGEX_REPLY, post.get_raw_text()):
131 post_id = reply_number.group(1)
130 post_id = reply_number.group(1)
132 ref_post = self.filter(id=post_id)
131 ref_post = self.filter(id=post_id)
133 if ref_post.count() > 0:
132 if ref_post.count() > 0:
@@ -191,8 +190,8 b' class Post(models.Model, Viewable):'
191
190
192 title = models.CharField(max_length=TITLE_MAX_LENGTH)
191 title = models.CharField(max_length=TITLE_MAX_LENGTH)
193 pub_time = models.DateTimeField()
192 pub_time = models.DateTimeField()
194 text = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE,
193 text = TextField(blank=True, null=True)
195 escape_html=False)
194 _text_rendered = TextField(blank=True, null=True, editable=False)
196
195
197 images = models.ManyToManyField(PostImage, null=True, blank=True,
196 images = models.ManyToManyField(PostImage, null=True, blank=True,
198 related_name='ip+', db_index=True)
197 related_name='ip+', db_index=True)
@@ -220,7 +219,7 b' class Post(models.Model, Viewable):'
220
219
221 title = self.title
220 title = self.title
222 if not title:
221 if not title:
223 title = self.text.rendered
222 title = self.get_text()
224
223
225 return title
224 return title
226
225
@@ -429,8 +428,20 b' class Post(models.Model, Viewable):'
429 logger.info('Sent post #{} to channel {}'.format(self.id, channel_name))
428 logger.info('Sent post #{} to channel {}'.format(self.id, channel_name))
430
429
431 if recursive:
430 if recursive:
432 for reply_number in re.finditer(REGEX_REPLY, self.text.raw):
431 for reply_number in re.finditer(REGEX_REPLY, self.get_raw_text()):
433 post_id = reply_number.group(1)
432 post_id = reply_number.group(1)
434 ref_post = Post.objects.filter(id=post_id)[0]
433 ref_post = Post.objects.filter(id=post_id)[0]
435
434
436 ref_post.send_to_websocket(request, recursive=False)
435 ref_post.send_to_websocket(request, recursive=False)
436
437 def save(self, force_insert=False, force_update=False, using=None,
438 update_fields=None):
439 self._text_rendered = bbcode_extended(self.get_raw_text())
440
441 super().save(force_insert, force_update, using, update_fields)
442
443 def get_text(self):
444 return self._text_rendered
445
446 def get_raw_text(self):
447 return self.text
@@ -62,9 +62,9 b''
62 <div class="message">
62 <div class="message">
63 {% autoescape off %}
63 {% autoescape off %}
64 {% if truncated %}
64 {% if truncated %}
65 {{ post.text.rendered|truncatewords_html:50 }}
65 {{ post.get_text|truncatewords_html:50 }}
66 {% else %}
66 {% else %}
67 {{ post.text.rendered }}
67 {{ post.get_text }}
68 {% endif %}
68 {% endif %}
69 {% endautoescape %}
69 {% endautoescape %}
70 {% if post.is_referenced %}
70 {% if post.is_referenced %}
@@ -199,10 +199,6 b' HAYSTACK_CONNECTIONS = {'
199 },
199 },
200 }
200 }
201
201
202 MARKUP_FIELD_TYPES = (
203 ('bbcode', bbcode_extended),
204 )
205
206 THEMES = [
202 THEMES = [
207 ('md', 'Mystic Dark'),
203 ('md', 'Mystic Dark'),
208 ('md_centered', 'Mystic Dark (centered)'),
204 ('md_centered', 'Mystic Dark (centered)'),
@@ -7,23 +7,6 b' Main repository: https://bitbucket.org/n'
7
7
8 Site: http://neboard.me/
8 Site: http://neboard.me/
9
9
10 # DEPENDENCIES #
11
12 ## REQUIRED ##
13
14 * pillow
15 * django >= 1.6
16 * django_cleanup
17 * django-markupfield
18 * markdown
19 * python-markdown
20 * django-simple-captcha
21 * line-profiler
22
23 ## OPTIONAL ##
24
25 * django-debug-toolbar
26
27 # INSTALLATION #
10 # INSTALLATION #
28
11
29 1. Install all dependencies over pip or system-wide
12 1. Install all dependencies over pip or system-wide
@@ -3,6 +3,5 b' haystack'
3 pillow
3 pillow
4 django>=1.7
4 django>=1.7
5 django_cleanup
5 django_cleanup
6 django-markupfield
7 bbcode
6 bbcode
8 django_compressor No newline at end of file
7 django_compressor
General Comments 0
You need to be logged in to leave comments. Login now