Skip to content
Snippets Groups Projects
Commit d005a9d0 authored by Fredrik Jonsson's avatar Fredrik Jonsson
Browse files

Make submission shortcodes in the format #1234 expand to links to the...

Make submission shortcodes in the format #1234 expand to links to the submission in reviews and comments.
parent 49f356c3
No related branches found
No related tags found
No related merge requests found
{% load activity_tags bleach_tags markdown_tags %}
{% load activity_tags bleach_tags markdown_tags submission_tags %}
<div class="feed__item feed__item--{{ activity.type }}">
<div class="feed__pre-content">
<p class="feed__label feed__label--{{ activity.type }}">{{ activity.type|capfirst }}</p>
......@@ -19,7 +19,7 @@
updated <a href="{{ activity.submission.get_absolute_url }}">{{ activity.submission.title }}</a>
{% endif %}
{{ activity.message|markdown|bleach }}
{{ activity.message|markdown|bleach|submission_links }}
{% if not submission_title and activity|user_can_see_related:request.user %}
{% with url=activity.related_object.get_absolute_url %}
......
import re
from django import template
from django.utils.safestring import mark_safe
from opentech.apply.funds.models import ApplicationSubmission
register = template.Library()
@register.filter
def submission_links(value):
regex = re.compile('[^\w]\#(\d+)[^\w]')
links = {}
for match in regex.finditer(value):
try:
submission = ApplicationSubmission.objects.get(id=match[1])
except ApplicationSubmission.DoesNotExist:
pass
else:
links[f'#{submission.id}'] = f'<a href="{submission.get_absolute_url()}">{submission.title} <span class="mid-grey-text">#{submission.id}</span></a>'
if links:
for sid, link in links.items():
value = value.replace(sid, link)
return mark_safe(value)
{% extends "base-apply.html" %}
{% load bleach_tags %}
{% load bleach_tags submission_tags %}
{% block content %}
<div class="admin-bar">
......@@ -29,8 +29,8 @@
</div>
<div class="rich-text rich-text--answers">
{{ object.get_comments_display }}
{{ object.get_comments_display|submission_links }}
{{ object.output_answers }}
{{ object.output_answers|submission_links }}
</div>
{% endblock %}
......@@ -114,3 +114,7 @@ ol {
.light-grey-bg {
background-color: $color--light-grey;
}
.mid-grey-text {
color: $color--mid-dark-grey;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment