# HG changeset patch # User neko259 # Date 2015-08-25 17:55:08 # Node ID a2eaff61a1699adcc3ff9329e4de562cbc5a7ced # Parent ced75ab05d0c6611a009ce12a68be56f7ffdfc32 Reflinks to OPs are bold now. Refactored reflinks to build using the same code. Refactored autoescaping diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -130,7 +130,7 @@ def render_reflink(tag_name, value, opti try: post = boards.models.Post.objects.get(id=post_id) - result = '>>%s' % (post.get_absolute_url(), post_id) + result = post.get_link_view() except ObjectDoesNotExist: pass diff --git a/boards/migrations/0025_auto_20150825_2049.py b/boards/migrations/0025_auto_20150825_2049.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0025_auto_20150825_2049.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations +from boards.models import Post + + +class Migration(migrations.Migration): + + def refuild_refmap(apps, schema_editor): + for post in Post.objects.all(): + post.build_refmap() + post.save(update_fields=['refmap']) + + dependencies = [ + ('boards', '0024_post_tripcode'), + ] + + operations = [ + migrations.RunPython(refuild_refmap), + ] diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -61,8 +61,6 @@ POST_VIEW_PARAMS = ( 'mode_tree', ) -REFMAP_STR = '>>{}' - IMAGE_TYPES = ( 'jpeg', 'jpg', @@ -230,7 +228,7 @@ class Post(models.Model, Viewable): the server from recalculating the map on every post show. """ - post_urls = [REFMAP_STR.format(refpost.get_absolute_url(), refpost.id) + post_urls = [refpost.get_link_view() for refpost in self.referenced_posts.all()] self.refmap = ', '.join(post_urls) @@ -444,3 +442,15 @@ class Post(models.Model, Viewable): def get_tripcode(self): if self.tripcode: return Tripcode(self.tripcode) + + def get_link_view(self): + """ + Gets view of a reflink to the post. + """ + + result = '>>{}'.format(self.get_absolute_url(), + self.id) + if self.is_opening(): + result = '{}'.format(result) + + return result diff --git a/boards/templates/boards/all_threads.html b/boards/templates/boards/all_threads.html --- a/boards/templates/boards/all_threads.html +++ b/boards/templates/boards/all_threads.html @@ -64,25 +64,19 @@ {% endif %} - {% autoescape off %} - {{ tag.get_view }} - {% endautoescape %} + {{ tag.get_view|safe }} {% if moderator %} | {% trans 'Edit tag' %} {% endif %} {% if tag.get_description %} - {% autoescape off %} -

{{ tag.get_description }}

- {% endautoescape %} +

{{ tag.get_description|safe }}

{% endif %}

{% 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 %}

{% if related_tags %}

{% trans 'Related tags:' %} {% for rel_tag in related_tags %} - {% autoescape off %} - {{ rel_tag.get_view }}{% if not forloop.last %}, {% else %}.{% endif %} - {% endautoescape %} + {{ rel_tag.get_view|safe }}{% if not forloop.last %}, {% else %}.{% endif %} {% endfor %}

{% endif %} diff --git a/boards/templates/boards/post.html b/boards/templates/boards/post.html --- a/boards/templates/boards/post.html +++ b/boards/templates/boards/post.html @@ -36,7 +36,7 @@ {% else %} {% if need_op_data %} {% with thread.get_opening_post as op %} - {% trans " in " %}>>{{ op.id }} {{ op.get_title|striptags|truncatewords:5 }} + {% trans " in " %}{{ op.get_link_view|safe }} {{ op.get_title|striptags|truncatewords:5 }} {% endwith %} {% endif %} {% endif %} @@ -59,16 +59,12 @@ {% endcomment %} {% if post.images.exists %} {% with post.images.first as image %} - {% autoescape off %} - {{ image.get_view }} - {% endautoescape %} + {{ image.get_view|safe }} {% endwith %} {% endif %} {% if post.attachments.exists %} {% with post.attachments.first as file %} - {% autoescape off %} - {{ file.get_view }} - {% endautoescape %} + {{ file.get_view|safe }} {% endwith %} {% endif %} {% comment %} @@ -92,9 +88,7 @@ {% else %}
- {% autoescape off %} - {% trans "Replies" %}: {{ post.refmap }} - {% endautoescape %} + {% trans "Replies" %}: {{ post.refmap|safe }}
{% endif %} {% endif %} @@ -108,9 +102,7 @@ {{ thread.get_images_count }} {% trans 'images' %}. {% endif %} - {% autoescape off %} - {{ thread.get_tag_url_list }} - {% endautoescape %} + {{ thread.get_tag_url_list|safe }} {% endif %} diff --git a/boards/templates/boards/settings.html b/boards/templates/boards/settings.html --- a/boards/templates/boards/settings.html +++ b/boards/templates/boards/settings.html @@ -18,9 +18,7 @@ {% if hidden_tags %}

{% trans 'Hidden tags:' %} {% for tag in hidden_tags %} - {% autoescape off %} - {{ tag.get_view }} - {% endautoescape %} + {{ tag.get_view|safe }} {% endfor %}

{% else %} diff --git a/boards/templates/boards/tag.html b/boards/templates/boards/tag.html --- a/boards/templates/boards/tag.html +++ b/boards/templates/boards/tag.html @@ -1,5 +1,3 @@
- {% autoescape off %} - {{ tag.get_view }} - {% endautoescape %} + {{ tag.get_view|safe }}