##// END OF EJS Templates
Reflinks to OPs are bold now. Refactored reflinks to build using the same code. Refactored autoescaping
neko259 -
r1309:a2eaff61 default
parent child Browse files
Show More
@@ -0,0 +1,21 b''
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from django.db import migrations
5 from boards.models import Post
6
7
8 class Migration(migrations.Migration):
9
10 def refuild_refmap(apps, schema_editor):
11 for post in Post.objects.all():
12 post.build_refmap()
13 post.save(update_fields=['refmap'])
14
15 dependencies = [
16 ('boards', '0024_post_tripcode'),
17 ]
18
19 operations = [
20 migrations.RunPython(refuild_refmap),
21 ]
@@ -130,7 +130,7 b' def render_reflink(tag_name, value, opti'
130 try:
130 try:
131 post = boards.models.Post.objects.get(id=post_id)
131 post = boards.models.Post.objects.get(id=post_id)
132
132
133 result = '<a href="%s">&gt;&gt;%s</a>' % (post.get_absolute_url(), post_id)
133 result = post.get_link_view()
134 except ObjectDoesNotExist:
134 except ObjectDoesNotExist:
135 pass
135 pass
136
136
@@ -61,8 +61,6 b' POST_VIEW_PARAMS = ('
61 'mode_tree',
61 'mode_tree',
62 )
62 )
63
63
64 REFMAP_STR = '<a href="{}">&gt;&gt;{}</a>'
65
66 IMAGE_TYPES = (
64 IMAGE_TYPES = (
67 'jpeg',
65 'jpeg',
68 'jpg',
66 'jpg',
@@ -230,7 +228,7 b' class Post(models.Model, Viewable):'
230 the server from recalculating the map on every post show.
228 the server from recalculating the map on every post show.
231 """
229 """
232
230
233 post_urls = [REFMAP_STR.format(refpost.get_absolute_url(), refpost.id)
231 post_urls = [refpost.get_link_view()
234 for refpost in self.referenced_posts.all()]
232 for refpost in self.referenced_posts.all()]
235
233
236 self.refmap = ', '.join(post_urls)
234 self.refmap = ', '.join(post_urls)
@@ -444,3 +442,15 b' class Post(models.Model, Viewable):'
444 def get_tripcode(self):
442 def get_tripcode(self):
445 if self.tripcode:
443 if self.tripcode:
446 return Tripcode(self.tripcode)
444 return Tripcode(self.tripcode)
445
446 def get_link_view(self):
447 """
448 Gets view of a reflink to the post.
449 """
450
451 result = '<a href="{}">&gt;&gt;{}</a>'.format(self.get_absolute_url(),
452 self.id)
453 if self.is_opening():
454 result = '<b>{}</b>'.format(result)
455
456 return result
@@ -64,25 +64,19 b''
64 <button name="method" value="hide" class="not_fav">H</button>
64 <button name="method" value="hide" class="not_fav">H</button>
65 {% endif %}
65 {% endif %}
66 </form>
66 </form>
67 {% autoescape off %}
67 {{ tag.get_view|safe }}
68 {{ tag.get_view }}
69 {% endautoescape %}
70 {% if moderator %}
68 {% if moderator %}
71 <span class="moderator_info">| <a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a></span>
69 <span class="moderator_info">| <a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a></span>
72 {% endif %}
70 {% endif %}
73 </h2>
71 </h2>
74 {% if tag.get_description %}
72 {% if tag.get_description %}
75 {% autoescape off %}
73 <p>{{ tag.get_description|safe }}</p>
76 <p>{{ tag.get_description }}</p>
77 {% endautoescape %}
78 {% endif %}
74 {% endif %}
79 <p>{% blocktrans with active_thread_count=tag.get_active_thread_count thread_count=tag.get_thread_count post_count=tag.get_post_count %}This tag has {{ thread_count }} threads ({{ active_thread_count}} active) and {{ post_count }} posts.{% endblocktrans %}</p>
75 <p>{% blocktrans with active_thread_count=tag.get_active_thread_count thread_count=tag.get_thread_count post_count=tag.get_post_count %}This tag has {{ thread_count }} threads ({{ active_thread_count}} active) and {{ post_count }} posts.{% endblocktrans %}</p>
80 {% if related_tags %}
76 {% if related_tags %}
81 <p>{% trans 'Related tags:' %}
77 <p>{% trans 'Related tags:' %}
82 {% for rel_tag in related_tags %}
78 {% for rel_tag in related_tags %}
83 {% autoescape off %}
79 {{ rel_tag.get_view|safe }}{% if not forloop.last %}, {% else %}.{% endif %}
84 {{ rel_tag.get_view }}{% if not forloop.last %}, {% else %}.{% endif %}
85 {% endautoescape %}
86 {% endfor %}
80 {% endfor %}
87 </p>
81 </p>
88 {% endif %}
82 {% endif %}
@@ -36,7 +36,7 b''
36 {% else %}
36 {% else %}
37 {% if need_op_data %}
37 {% if need_op_data %}
38 {% with thread.get_opening_post as op %}
38 {% with thread.get_opening_post as op %}
39 {% trans " in " %}<a href="{{ op.get_absolute_url }}">&gt;&gt;{{ op.id }}</a> <span class="title">{{ op.get_title|striptags|truncatewords:5 }}</span>
39 {% trans " in " %}{{ op.get_link_view|safe }} <span class="title">{{ op.get_title|striptags|truncatewords:5 }}</span>
40 {% endwith %}
40 {% endwith %}
41 {% endif %}
41 {% endif %}
42 {% endif %}
42 {% endif %}
@@ -59,16 +59,12 b''
59 {% endcomment %}
59 {% endcomment %}
60 {% if post.images.exists %}
60 {% if post.images.exists %}
61 {% with post.images.first as image %}
61 {% with post.images.first as image %}
62 {% autoescape off %}
62 {{ image.get_view|safe }}
63 {{ image.get_view }}
64 {% endautoescape %}
65 {% endwith %}
63 {% endwith %}
66 {% endif %}
64 {% endif %}
67 {% if post.attachments.exists %}
65 {% if post.attachments.exists %}
68 {% with post.attachments.first as file %}
66 {% with post.attachments.first as file %}
69 {% autoescape off %}
67 {{ file.get_view|safe }}
70 {{ file.get_view }}
71 {% endautoescape %}
72 {% endwith %}
68 {% endwith %}
73 {% endif %}
69 {% endif %}
74 {% comment %}
70 {% comment %}
@@ -92,9 +88,7 b''
92 </div>
88 </div>
93 {% else %}
89 {% else %}
94 <div class="refmap">
90 <div class="refmap">
95 {% autoescape off %}
91 {% trans "Replies" %}: {{ post.refmap|safe }}
96 {% trans "Replies" %}: {{ post.refmap }}
97 {% endautoescape %}
98 </div>
92 </div>
99 {% endif %}
93 {% endif %}
100 {% endif %}
94 {% endif %}
@@ -108,9 +102,7 b''
108 {{ thread.get_images_count }} {% trans 'images' %}.
102 {{ thread.get_images_count }} {% trans 'images' %}.
109 {% endif %}
103 {% endif %}
110 <span class="tags">
104 <span class="tags">
111 {% autoescape off %}
105 {{ thread.get_tag_url_list|safe }}
112 {{ thread.get_tag_url_list }}
113 {% endautoescape %}
114 </span>
106 </span>
115 </div>
107 </div>
116 {% endif %}
108 {% endif %}
@@ -18,9 +18,7 b''
18 {% if hidden_tags %}
18 {% if hidden_tags %}
19 <p>{% trans 'Hidden tags:' %}
19 <p>{% trans 'Hidden tags:' %}
20 {% for tag in hidden_tags %}
20 {% for tag in hidden_tags %}
21 {% autoescape off %}
21 {{ tag.get_view|safe }}
22 {{ tag.get_view }}
23 {% endautoescape %}
24 {% endfor %}
22 {% endfor %}
25 </p>
23 </p>
26 {% else %}
24 {% else %}
@@ -1,5 +1,3 b''
1 <div class="post">
1 <div class="post">
2 {% autoescape off %}
2 {{ tag.get_view|safe }}
3 {{ tag.get_view }}
4 {% endautoescape %}
5 </div>
3 </div>
General Comments 0
You need to be logged in to leave comments. Login now