From 9042eefd260976d3d349570f1da9ce75d5be2e5c Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Tue, 12 Apr 2016 22:08:37 +0200
Subject: [PATCH] Use templates to render all HTML snippets in models; remove
 safe filter from all templates

---
 commentaries/models.py                        |  48 +++--
 .../templates/commentaries/commentaries.html  |   6 +-
 .../commentaries/commentary_detail.html       |   2 +-
 comments/models.py                            | 169 +++++++++++-------
 .../templates/comments/reply_to_comment.html  |  12 +-
 .../templates/comments/reply_to_report.html   |   2 +-
 .../comments/vet_submitted_comments.html      |   6 +-
 scipost/models.py                             |  76 +++++---
 .../templates/scipost/claim_authorships.html  |   6 +-
 scipost/templates/scipost/comments_block.html |  12 +-
 .../templates/scipost/contributor_info.html   |  12 +-
 scipost/templates/scipost/personal_page.html  |  12 +-
 .../scipost/vet_authorship_claims.html        |   6 +-
 .../scipost/vet_registration_requests.html    |   2 +-
 submissions/models.py                         | 137 +++++++-------
 .../accept_or_decline_assignments.html        |   2 +-
 .../accept_or_decline_ref_invitations.html    |   2 +-
 .../submissions/assign_submissions.html       |   4 +-
 .../templates/submissions/communication.html  |   2 +-
 .../templates/submissions/editorial_page.html |   2 +-
 .../submissions/eic_recommendation.html       |   2 +-
 .../templates/submissions/select_referee.html |   2 +-
 .../submissions/submission_detail.html        |  14 +-
 .../templates/submissions/submissions.html    |   6 +-
 .../templates/submissions/submit_report.html  |   2 +-
 submissions/views.py                          |   4 +-
 theses/models.py                              |  33 ++--
 theses/templates/theses/theses.html           |   6 +-
 theses/templates/theses/thesis_detail.html    |   2 +-
 .../theses/vet_thesislink_requests.html       |   2 +-
 30 files changed, 351 insertions(+), 242 deletions(-)

diff --git a/commentaries/models.py b/commentaries/models.py
index 24fb2e917..fc2145174 100644
--- a/commentaries/models.py
+++ b/commentaries/models.py
@@ -1,7 +1,7 @@
 from django.utils import timezone
 from django.db import models
 from django.contrib.auth.models import User
-
+from django.template import Template, Context
 
 from journals.models import SCIPOST_JOURNALS_DOMAINS, SCIPOST_JOURNALS_SPECIALIZATIONS
 from scipost.models import Contributor
@@ -40,36 +40,56 @@ class Commentary(models.Model):
     def __str__ (self):
         return self.pub_title
 
-    def header_as_table (self):
+
+    def header_as_table(self):
         # for display in Commentary page itself
         header = '<table>'
-        header += '<tr><td>Title: </td><td>&nbsp;</td><td>' + self.pub_title + '</td></tr>'
-        header += '<tr><td>Author(s): </td><td>&nbsp;</td><td>' + self.author_list + '</td></tr>'
+        header += '<tr><td>Title: </td><td>&nbsp;</td><td>{{ pub_title }}</td></tr>'
+        header += '<tr><td>Author(s): </td><td>&nbsp;</td><td>{{ author_list }}</td></tr>'
         header += '<tr><td>As Contributors: </td><td>&nbsp;</td>'
         if self.authors.all():
             header += '<td>'
             for auth in self.authors.all():
                 header += '<a href="/contributor/' + str(auth.id) + '">' + auth.user.first_name + ' ' + auth.user.last_name + '</a>,&nbsp;'
-            header += '<td>'
+            header += '</td>'
         else:
             header += '<td>(none claimed)</td>'
         header += '</tr>'
         if self.type == 'published':
-            header += '<tr><td>DOI: </td><td>&nbsp;</td><td><a href="' + self.pub_DOI_link + '" target="_blank">' + self.pub_DOI_link + '</a></td></tr>'
+            header += '<tr><td>DOI: </td><td>&nbsp;</td><td><a href="{{ pub_DOI_link }}" target="_blank">{{ pub_DOI_link }}</a></td></tr>'
         elif self.type == 'preprint':
-            header += '<tr><td>arxiv Link: </td><td>&nbsp;</td><td><a href="' + self.arxiv_link + '">' + self.arxiv_link + '</a></td></tr>'
-        header += '<tr><td>Date: </td><td>&nbsp;</td><td>' + str(self.pub_date) + '</td></tr>'
+            header += '<tr><td>arxiv Link: </td><td>&nbsp;</td><td><a href="{{ arxiv_link }}">{{ arxiv_link }}</a></td></tr>'
+        if self.pub_date:
+            header += '<tr><td>Date: </td><td>&nbsp;</td><td>{{ pub_date }}</td></tr>'
         header += '</table>'
-        return header
+        template = Template(header)
+        context = Context({
+                'pub_title': self.pub_title, 'author_list': self.author_list, 
+                })
+        if self.type == 'published':
+            context['pub_DOI_link'] = self.pub_DOI_link
+            context['pub_date'] = self.pub_date
+        elif self.type == 'preprint':
+            context['arxiv_link'] = self.arxiv_link
+        return template.render(context)
+
 
     def header_as_li (self):
         # for display in search lists
         header = '<li><div class="flex-container">'
-        #header += '<div class="flex-whitebox0"><p><a href="/commentary/' + str(self.id) + '" class="pubtitleli">' + self.pub_title + '</a></p>'
-        header += '<div class="flex-whitebox0"><p><a href="' + self.scipost_url() + '" class="pubtitleli">' + self.pub_title + '</a></p>'
-        header += '<p>by ' + self.author_list + '</p><p> (published ' + str(self.pub_date) + ') - latest activity: ' + self.latest_activity.strftime('%Y-%m-%d %H:%M') + '</p></div>'
-        header += '</div></li>'
-        return header
+        header += '<div class="flex-whitebox0"><p><a href="{{ scipost_url }}" class="pubtitleli">{{ pub_title }}</a></p>'
+        header += '<p>by {{ author_list }}</p>'
+        if self.pub_date:
+            header += '<p> (published {{ pub_date }}) - '
+        header += 'latest activity: {{ latest_activity }}</p></div></div></li>'
+        template = Template(header)
+        context = Context({'scipost_url': self.scipost_url(), 'pub_title': self.pub_title,
+                           'author_list': self.author_list, 
+                           'latest_activity': self.latest_activity.strftime('%Y-%m-%d %H:%M')})
+        if self.pub_date:
+            context['pub_date'] = str(self.pub_date)
+        return template.render(context)
+
 
     def parse_link_into_url (self):
         """ Takes the arXiv nr or DOI and turns it into the url suffix """
diff --git a/commentaries/templates/commentaries/commentaries.html b/commentaries/templates/commentaries/commentaries.html
index 570c1ef46..5e6aeefbe 100644
--- a/commentaries/templates/commentaries/commentaries.html
+++ b/commentaries/templates/commentaries/commentaries.html
@@ -42,7 +42,7 @@
   <h3>Search results:</h3>
   <ul>
     {% for commentary in commentary_search_list %}
-    {{ commentary.header_as_li|safe }}
+    {{ commentary.header_as_li }}
     {% endfor %}
   </ul>
   {% elif form.has_changed %}
@@ -57,7 +57,7 @@
   <h2>Recently active Commentaries:</h2>
   <ul>  
     {% for commentary in commentary_recent_list %}
-    {{ commentary.header_as_li|safe }}
+    {{ commentary.header_as_li }}
     {% endfor %}
   </ul>
 </section>
@@ -69,7 +69,7 @@
   <h2>Commentaries in {{ discipline }} in the last {{ nrweeksback }} weeks:</h2>
   <ul>
     {% for commentary in commentary_browse_list %}
-    {{ commentary.header_as_li|safe }}
+    {{ commentary.header_as_li }}
     {% endfor %}
   </ul>
   {% endif %}
diff --git a/commentaries/templates/commentaries/commentary_detail.html b/commentaries/templates/commentaries/commentary_detail.html
index 5e5c841a5..511be9842 100644
--- a/commentaries/templates/commentaries/commentary_detail.html
+++ b/commentaries/templates/commentaries/commentary_detail.html
@@ -32,7 +32,7 @@
       <h2>Original publication: </h2>
     </div>
   </div>
-  {{ commentary.header_as_table|safe }}
+  {{ commentary.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ commentary.pub_abstract }}</p>
   
diff --git a/comments/models.py b/comments/models.py
index b85c7d939..d109bbd70 100644
--- a/comments/models.py
+++ b/comments/models.py
@@ -2,6 +2,8 @@ from django.utils import timezone
 from django.db import models
 from django.contrib.auth.models import User
 from django.shortcuts import get_object_or_404
+from django.template import Template, Context
+from django.utils.safestring import mark_safe
 
 from .models import *
 
@@ -92,116 +94,149 @@ class Comment(models.Model):
 
 
     def opinions_as_ul(self):
-        output = '<ul class="opinionsDisplay">'
-        output += '<li style="background-color: #000099">Agree ' + str(self.nr_A) + '</li>'
-        output += '<li style="background-color: #555555">Not sure ' + str(self.nr_N) + '</li>'
-        output += '<li style="background-color: #990000">Disagree ' + str(self.nr_D) + '</li>'
-        output += '</ul>'
-        return output
+        template = Template('''
+        <ul class="opinionsDisplay">
+        <li style="background-color: #000099">Agree {{ nr_A }}</li>
+        <li style="background-color: #555555">Not sure {{ nr_N }}</li>
+        <li style="background-color: #990000">Disagree {{ nr_D }}</li>
+        </ul>
+        ''')
+        context = Context ({'nr_A': self.nr_A, 'nr_N': self.nr_N, 'nr_D': self.nr_D})
+        return template.render(context)
 
+    
     def opinions_as_ul_tiny(self):
-        output = '<ul class="opinionsDisplay">'
-        output += '<li style="background-color: #000099; font-size: 8px; padding: 2px;">' + str(self.nr_A) + '</li>'
-        output += '<li style="background-color: #555555; font-size: 8px; padding: 2px;">' + str(self.nr_N) + '</li>'
-        output += '<li style="background-color: #990000; font-size: 8px; padding: 2px;">' + str(self.nr_D) + '</li>'
-        output += '</ul>'
-        return output
+        template = Template('''
+        <ul class="opinionsDisplay">
+        <li style="background-color: #000099; font-size: 8px; padding: 2px;">Agree {{ nr_A }}</li>
+        <li style="background-color: #555555; font-size: 8px; padding: 2px;">Not sure {{ nr_N }}</li>
+        <li style="background-color: #990000; font-size: 8px; padding: 2px;">Disagree {{ nr_D }}</li>
+        </ul>
+        ''')
+        context = Context ({'nr_A': self.nr_A, 'nr_N': self.nr_N, 'nr_D': self.nr_D})
+        return template.render(context)
 
 
     def print_identifier (self):
         # for display 
         output = '<div class="commentid">\n'
-        output += '<h3><a id="comment_id' + str(self.id) + '"></a>'
+        output += '<h3><a id="comment_id{{ id }}"></a>'
+        context = Context({'id': self.id})
         if self.is_author_reply:
             output += 'Author '
         if not self.anonymous:
-            output += (' <a href="/contributor/' + str(self.author.id) + '">' +
-                       self.author.user.first_name + ' ' + self.author.user.last_name + '</a> on ')
-#        output += self.date_submitted.strftime("%Y-%m-%d")
-#        if self.in_reply_to:
-#            output += (', in reply to <a href="#comment_id' + str(self.in_reply_to_id) + '" style="font-size: 80%">' + 
-#                       str(self.in_reply_to.author.user.first_name) + ' ' + 
-#                       str(self.in_reply_to.author.user.last_name) + ' on ' + 
-#                       self.in_reply_to.date_submitted.strftime("%Y-%m-%d") + '</a>')
-        output += self.date_submitted.strftime("%Y-%m-%d")
+            output += ' <a href="/contributor/{{ author_id }}">{{ first_name }} {{ last_name }}</a> on '
+            context['author_id'] = self.author.id
+            context['first_name'] = self.author.user.first_name
+            context['last_name'] = self.author.user.last_name
+        output += '{{ date_submitted }}'
+        context['date_submitted'] = self.date_submitted.strftime("%Y-%m-%d")
         if self.in_reply_to_comment:
-            output += (' (in reply to <a href="#comment_id' + str(self.in_reply_to_comment_id) + '">' + 
-                       str(self.in_reply_to_comment.author.user.first_name) + ' ' + 
-                       str(self.in_reply_to_comment.author.user.last_name)  + ' on ' + 
-                       self.in_reply_to_comment.date_submitted.strftime("%Y-%m-%d") + '</a>)')
+            output += (' (in reply to <a href="#comment_id{{ in_reply_to_comment_id }}">' + 
+                       '{{ in_reply_to_comment_first_name }} {{ in_reply_to_comment_last_name }} on ' + 
+                       '{{ in_reply_to_comment_date }}</a>)')
+            context['in_reply_to_comment_id'] = self.in_reply_to_comment_id
+            context['in_reply_to_comment_first_name'] = self.in_reply_to_comment.author.user.first_name
+            context['in_reply_to_comment_last_name'] = self.in_reply_to_comment.author.user.last_name
+            context['in_reply_to_comment_date'] = self.in_reply_to_comment.date_submitted.strftime("%Y-%m-%d")
         elif self.in_reply_to_report:
-            output += (' (in reply to <a href="#report_id' + str(self.in_reply_to_report_id) + '">')
+            output += ' (in reply to <a href="#report_id{{ in_reply_to_report_id }}">'
+            context['in_reply_to_report_id'] = self.in_reply_to_report_id
             if not self.in_reply_to_report.anonymous:
-                output += (str(self.in_reply_to_report.author.user.first_name) + ' ' + 
-                           str(self.in_reply_to_report.author.user.last_name))
+                output += '{{ in_reply_to_report_first_name }} {{ in_reply_to_report_last_name}}'
+                context['in_reply_to_report_first_name'] = self.in_reply_to_report.author.user.first_name
+                context['in_reply_to_report_last_name'] = self.in_reply_to_report.author.user.last_name
             else:
-                output += 'Report ' + str(self.in_reply_to_report_id)
-            output += '</a> on ' + self.in_reply_to_report.date_submitted.strftime("%Y-%m-%d") + '</a>)'
+                output += 'Report {{ in_reply_to_report_id }}'
+                context['in_reply_to_report_id'] = self.in_reply_to_report_id
+            output += ' on {{ date_submitted }}</a>)'
+            context['date_submitted'] = self.in_reply_to_report.date_submitted.strftime("%Y-%m-%d")
         output += '</h3></div>'
-        return output
+        template = Template(output)
+        return template.render(context)
+
 
     def print_identifier_for_vetting (self):
         # for display, same as print_identifier but named even if anonymous, not linked 
         output = '<div class="commentid">\n'
         output += '<h3>'
+        context = Context()
         if self.is_author_reply:
             output += 'Author '
-        output += (' <a href="/contributor/' + str(self.author.id) + '">' +
-                   self.author.user.first_name + ' ' + self.author.user.last_name + '</a> on ')
-        output += self.date_submitted.strftime("%Y-%m-%d")
+        output += ' <a href="/contributor/{{ author_id }}">{{ first_name }}{{ last_name }}</a> on '
+        context['author_id'] = self.author.id
+        context['first_name'] = self.author.user.first_name
+        context['last_name'] = self.author.user.last_name
+        output += '{{ date_submitted }}'
+        context['date_submitted'] = self.date_submitted.strftime("%Y-%m-%d")
         if self.in_reply_to_comment:
-            output += (' (in reply to <a href="#comment_id' + str(self.in_reply_to_comment_id) + '">' + 
-                       str(self.in_reply_to_comment.author.user.first_name) + ' ' + 
-                       str(self.in_reply_to_comment.author.user.last_name)  + ' on ' + 
-                       self.in_reply_to_comment.date_submitted.strftime("%Y-%m-%d") + '</a>)')
+            output += (' (in reply to <a href="#comment_id{{ in_reply_to_comment_id }}">' + 
+                       '{{ in_reply_to_comment_first_name }} {{ in_reply_to_comment_last_name }} on ' + 
+                       '{{ in_reply_to_comment_date }}</a>)')
+            context['in_reply_to_comment_id'] = self.in_reply_to_comment_id
+            context['in_reply_to_comment_first_name'] = self.in_reply_to_comment.author.user.first_name
+            context['in_reply_to_comment_last_name'] = self.in_reply_to_comment.author.user.last_name
+            context['in_reply_to_comment_date'] = self.in_reply_to_comment.date_submitted.strftime("%Y-%m-%d")            
         elif self.in_reply_to_report:
-            output += (' (in reply to <a href="#report_id' + str(self.in_reply_to_report_id) + '">')
+            output += ' (in reply to <a href="#report_id{{ in_reply_to_report_id }}">'
+            context['in_reply_to_report_id'] = self.in_reply_to_report_id
             if not self.in_reply_to_report.anonymous:
-                output += (str(self.in_reply_to_report.author.user.first_name) + ' ' + 
-                           str(self.in_reply_to_report.author.user.last_name))
+                output += '{{ in_reply_to_report_first_name }} {{ in_reply_to_report_last_name}}'
+                context['in_reply_to_report_first_name'] = self.in_reply_to_report.author.user.first_name
+                context['in_reply_to_report_last_name'] = self.in_reply_to_report.author.user.last_name
             else:
-                output += 'Report ' + str(self.in_reply_to_report_id)
-            output += ' on ' + self.in_reply_to_report.date_submitted.strftime("%Y-%m-%d") + '</a>)'
+                output += 'Report {{ in_reply_to_report_id }}'
+                context['in_reply_to_report_id'] = self.in_reply_to_report_id
+            output += '</a> on {{ date_submitted }})'
+            context['date_submitted'] = self.in_reply_to_report.date_submitted.strftime("%Y-%m-%d")
         output += '</h3></div>'
-        return output
-
+        template = Template(output)
+        return template.render(context)
 
 
     def header_as_li (self):
         # for search lists
         header = '<li><div class="flex-container">'
         header += '<div class="flex-whitebox0">'
-        header += 'Nr ' + str(self.id)
+        header += 'Nr {{ id }}'
+        context = Context({'id': self.id})
         header += ', <div class="opinionsDisplay">' + self.opinions_as_ul_tiny() + '</div>'
         if self.status <= 0:
             header += ', status: <span style="color:red">' + comment_status_dict[self.status] + '</span>'
         text_cut = self.comment_text[:50]
         if len(self.comment_text) > 50:
             text_cut += '...'
+        context['id'] = self.id
+        context['text_cut'] = text_cut
+        context['date_submitted'] = self.date_submitted.strftime("%Y-%m-%d")
         header += ': '
         if self.submission is not None:
-            header += ('<a href="/submission/' + str(self.submission.id) + 
-                       '#comment_id' + str(self.id) + '"> \"' + text_cut + '\"</a>' + 
-                       '<p>submitted on ' + self.date_submitted.strftime("%Y-%m-%d"))
-            header += (' in submission on <a href="/submission/' + str(self.submission.id) + 
-                       '" class="pubtitleli">' + self.submission.title + '</a> by ' + 
-                       self.submission.author_list + '</p>')
+            header += ('<a href="/submission/{{ submission_id }}#comment_id{{ id }}"> \"{{ text_cut }}\"</a>' + 
+                       '<p>submitted on {{ date_submitted }}')
+            header += (' in submission on <a href="/submission/{{ submission_id }}" class="pubtitleli">' + 
+                       '{{ submission_title }}</a> by {{ submission_author_list }}</p>')
+            context['submission_id'] = self.submission.id
+            context['submission_title'] = self.submission.title
+            context['submission_author_list'] = self.submission.author_list
         if self.commentary is not None:
-            header += ('<a href="/commentary/' + str(self.commentary.id) + 
-                       '#comment_id' + str(self.id) + '"> \"' + text_cut + 
-                       '\"</a><p>submitted on ' + self.date_submitted.strftime("%Y-%m-%d"))
-            header += (' in commentary on <a href="/commentary/' + str(self.commentary.id) + 
-                       '" class="pubtitleli">' + self.commentary.pub_title + 
-                       '</a> by ' + self.commentary.author_list + '</p>')
+            header += ('<a href="/commentary/{{ commentary_id }}#comment_id{{ id }}"> \"{{ text_cut }}\"</a>' +
+                       '<p>submitted on {{ date_submitted }}')
+            header += (' in commentary on <a href="/commentary/{{ commentary_id }}" class="pubtitleli">' + 
+                       '{{ commentary_pub_title }}</a> by {{ commentary_author_list }}</p>')
+            context['commentary_id'] = self.commentary.id
+            context['commentary_pub_title'] = self.commentary.pub_title
+            context['commentary_author_list'] = self.commentary.author_list
         if self.thesislink is not None:
-            header += ('<a href="/thesis/' + str(self.thesislink.id) + 
-                       '#comment_id' + str(self.id) + '"> \"' + text_cut + 
-                       '\"</a><p>submitted on ' + self.date_submitted.strftime("%Y-%m-%d"))
-            header += (' in thesislink on <a href="/thesis/' + str(self.thesislink.id) + 
-                       '" class="pubtitleli">' + self.thesislink.title + 
-                       '</a> by ' + self.thesislink.author + '</p>')
+            header += ('<a href="/thesis/{{ thesislink_id }}#comment_id{{ id }}"> \"{{ text_cut }}\"</a>' +
+                       '<p>submitted on {{ date_submitted }}')
+            header += (' in thesislink on <a href="/thesis/{{ thesislink_id }}" class="pubtitleli">' + 
+                       '{{ thesislink_title }}</a> by {{ thesislink_author }}</p>')
+            context['thesislink_id'] = self.thesis.link.id
+            context['thesislink_title'] = self.thesislink.title
+            context['thesislink_author'] = self.thesislink.author
         header += '</div></div></li>'
-        return header
+        template = Template(header)
+        return template.render(context)
 
     def categories_as_ul(self):
         output = '<div class="commentcategorydisplay"><h4>Category:</h4><ul>'
@@ -224,6 +259,6 @@ class Comment(models.Model):
         if self.is_sug:
             output += '<li>suggestion for further work</li>'
         output += '</ul></div>'
-        return output
+        return mark_safe(output)
 
 
diff --git a/comments/templates/comments/reply_to_comment.html b/comments/templates/comments/reply_to_comment.html
index 2bbd40fec..66f437c20 100644
--- a/comments/templates/comments/reply_to_comment.html
+++ b/comments/templates/comments/reply_to_comment.html
@@ -11,19 +11,19 @@
   <hr class="hr12">
   {% if comment.commentary %}
   <h1>The Commentary concerned:</h1>
-  {{ commentary.header_as_table|safe }}
+  {{ commentary.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ commentary.pub_abstract }}</p>
   {% endif %}
   {% if comment.submission %}
   <h1>The Submission concerned:</h1>
-  {{ submission.header_as_table|safe }}
+  {{ submission.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ submission.abstract }}</p>
   {% endif %}  
   {% if comment.thesislink %}
   <h1>The Thesis concerned:</h1>
-  {{ thesislink.header_as_table|safe }}
+  {{ thesislink.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ thesislink.abstract }}</p>
   {% endif %}  
@@ -34,10 +34,10 @@
 
    <div class="flex-container">
       <div class="flex-commentbox">
-	{{ comment.print_identifier|safe }}
-	{{ comment.categories_as_ul|safe }}
+	{{ comment.print_identifier }}
+	{{ comment.categories_as_ul }}
         <div class="opinionsDisplay">
-	  {{ comment.opinions_as_ul|safe }}
+	  {{ comment.opinions_as_ul }}
 	</div>
       </div>
    </div>
diff --git a/comments/templates/comments/reply_to_report.html b/comments/templates/comments/reply_to_report.html
index 633d6a36c..674fa21c4 100644
--- a/comments/templates/comments/reply_to_report.html
+++ b/comments/templates/comments/reply_to_report.html
@@ -15,7 +15,7 @@
 
   <hr class="hr12">
   <h1>The Submission concerned:</h1>
-  {{ report.submission.header_as_table|safe }}
+  {{ report.submission.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ report.submission.abstract }}</p>
   <br>
diff --git a/comments/templates/comments/vet_submitted_comments.html b/comments/templates/comments/vet_submitted_comments.html
index b67175c11..c2315a3ec 100644
--- a/comments/templates/comments/vet_submitted_comments.html
+++ b/comments/templates/comments/vet_submitted_comments.html
@@ -17,13 +17,13 @@
 
   {% if comment_to_vet.commentary %}
   <h3>From Commentary (<a href="{% url 'commentaries:commentary' arxiv_or_DOI_string=comment_to_vet.commentary.arxiv_or_DOI_string %}">link</a>)</h3>
-  {{ comment_to_vet.commentary.header_as_table|safe }}
+  {{ comment_to_vet.commentary.header_as_table }}
   <br />
   {% endif %}
 
   {% if comment_to_vet.submission %}
   <h3>From Submission (<a href="{% url 'submissions:submission' submission_id=comment_to_vet.submission.id %}">link</a>)</h3>
-  {{ comment_to_vet.submission.header_as_table|safe }}
+  {{ comment_to_vet.submission.header_as_table }}
   <br />
   {% endif %}
 
@@ -33,7 +33,7 @@
 
   <div class="row">
     <div class="col-8">
-      {{ comment_to_vet.print_identifier_for_vetting|safe }}
+      {{ comment_to_vet.print_identifier_for_vetting }}
       <h3>Comment text:</h3>
       <p>{{ comment_to_vet.comment_text }}</p>
       {% if comment_to_vet.remarks_for_editors %}
diff --git a/scipost/models.py b/scipost/models.py
index c948c49ce..fe9ffb812 100644
--- a/scipost/models.py
+++ b/scipost/models.py
@@ -2,6 +2,7 @@ from django.utils import timezone
 from django.db import models
 from django.contrib.auth.models import User, Group
 from django.contrib.postgres.fields import JSONField
+from django.template import Template, Context
 
 from django_countries.fields import CountryField
 
@@ -76,33 +77,59 @@ class Contributor(models.Model):
     def __str__ (self):
         return self.user.last_name + ', ' + self.user.first_name
 
-    def private_info_as_table (self):
-        output = '<table>'
-        output += '<tr><td>Title: </td><td>&nbsp;</td><td>' + title_dict[self.title] + '</td></tr>'
-        output += '<tr><td>First name: </td><td>&nbsp;</td><td>' + self.user.first_name + '</td></tr>'
-        output += '<tr><td>Last name: </td><td>&nbsp;</td><td>' + self.user.last_name + '</td></tr>'
-        output += '<tr><td>Email: </td><td>&nbsp;</td><td>' + self.user.email + '</td></tr>'
-        output += '<tr><td>ORCID id: </td><td>&nbsp;</td><td>' + self.orcid_id + '</td></tr>'
-        output += '<tr><td>Country of employment: </td><td>&nbsp;</td><td>' + str(self.country_of_employment.name) + '</td></tr>'
-        output += '<tr><td>Affiliation: </td><td>&nbsp;</td><td>' + self.affiliation + '</td></tr>'
-        output += '<tr><td>Address: </td><td>&nbsp;</td><td>' + self.address + '</td></tr>'
-        output += '<tr><td>Personal web page: </td><td>&nbsp;</td><td>' + self.personalwebpage + '</td></tr>'
-        output += '</table>'
-        return output
 
-    def public_info_as_table (self):
-        output = '<table>'
-        output += '<tr><td>Title: </td><td>&nbsp;</td><td>' + title_dict[self.title] + '</td></tr>'
-        output += '<tr><td>First name: </td><td>&nbsp;</td><td>' + self.user.first_name + '</td></tr>'
-        output += '<tr><td>Last name: </td><td>&nbsp;</td><td>' + self.user.last_name + '</td></tr>'
-        output += '<tr><td>ORCID id: </td><td>&nbsp;</td><td>' + self.orcid_id + '</td></tr>'
-        output += '<tr><td>Country of employment: </td><td>&nbsp;</td><td>' + str(self.country_of_employment.name) + '</td></tr>'
-        output += '<tr><td>Affiliation: </td><td>&nbsp;</td><td>' + self.affiliation + '</td></tr>'
-        output += '<tr><td>Personal web page: </td><td>&nbsp;</td><td>' + self.personalwebpage + '</td></tr>'
-        output += '</table>'
-        return output
+    def private_info_as_table (self):
+        template = Template('''
+        <table>
+        <tr><td>Title: </td><td>&nbsp;</td><td>{{ title }}</td></tr>
+        <tr><td>First name: </td><td>&nbsp;</td><td>{{ first_name }}</td></tr>
+        <tr><td>Last name: </td><td>&nbsp;</td><td>{{ last_name }}</td></tr>
+        <tr><td>Email: </td><td>&nbsp;</td><td>{{ email }}</td></tr>
+        <tr><td>ORCID id: </td><td>&nbsp;</td><td>{{ orcid_id }}</td></tr>
+        <tr><td>Country of employment: </td><td>&nbsp;</td><td>{{ country_of_employment }}</td></tr>
+        <tr><td>Affiliation: </td><td>&nbsp;</td><td>{{ affiliation }}</td></tr>
+        <tr><td>Address: </td><td>&nbsp;</td><td>{{ address }}</td></tr>
+        <tr><td>Personal web page: </td><td>&nbsp;</td><td>{{ personalwebpage }}</td></tr>
+        </table>
+        ''')
+        context = Context({
+                'title': title_dict[self.title],
+                'first_name': self.user.first_name,
+                'last_name': self.user.last_name,
+                'email': self.user.email,
+                'orcid_id': self.orcid_id,
+                'country_of_employment': str(self.country_of_employment.name),
+                'affiliation': self.affiliation,
+                'address': self.address,
+                'personalwebpage': self.personalwebpage
+                })
+        return template.render(context)
 
 
+    def public_info_as_table (self):
+        template = Template('''
+        <table>
+        <tr><td>Title: </td><td>&nbsp;</td><td>{{ title }}</td></tr>
+        <tr><td>First name: </td><td>&nbsp;</td><td>{{ first_name }}</td></tr>
+        <tr><td>Last name: </td><td>&nbsp;</td><td>{{ last_name }}</td></tr>
+        <tr><td>ORCID id: </td><td>&nbsp;</td><td>{{ orcid_id }}</td></tr>
+        <tr><td>Country of employment: </td><td>&nbsp;</td><td>{{ country_of_employment }}</td></tr>
+        <tr><td>Affiliation: </td><td>&nbsp;</td><td>{{ affiliation }}</td></tr>
+        <tr><td>Personal web page: </td><td>&nbsp;</td><td>{{ personalwebpage }}</td></tr>
+        </table>
+        ''')
+        context = Context({
+                'title': title_dict[self.title],
+                'first_name': self.user.first_name,
+                'last_name': self.user.last_name,
+                'email': self.user.email,
+                'orcid_id': self.orcid_id,
+                'country_of_employment': str(self.country_of_employment.name),
+                'affiliation': self.affiliation,
+                'address': self.address,
+                'personalwebpage': self.personalwebpage
+                })
+        return template.render(context)
 
 
 
@@ -154,7 +181,6 @@ class AuthorshipClaim(models.Model):
     submission = models.ForeignKey('submissions.Submission', blank=True, null=True)
     commentary = models.ForeignKey('commentaries.Commentary', blank=True, null=True)
     thesislink = models.ForeignKey('theses.ThesisLink', blank=True, null=True)
-#    vetted = models.BooleanField(default=False)
     vetted_by = models.ForeignKey (Contributor, blank=True, null=True)
     status = models.SmallIntegerField(choices=AUTHORSHIP_CLAIM_STATUS, default=0)
     
diff --git a/scipost/templates/scipost/claim_authorships.html b/scipost/templates/scipost/claim_authorships.html
index 72aa78bc4..fc6b6e81d 100644
--- a/scipost/templates/scipost/claim_authorships.html
+++ b/scipost/templates/scipost/claim_authorships.html
@@ -21,7 +21,7 @@
   <h3>Potential authorships to claim (auto-detected)</h3>
   <ul>
     {% for sub in submission_authorships_to_claim %}
-    {{ sub.header_as_li | safe }}
+    {{ sub.header_as_li }}
     <form action="{% url 'scipost:claim_sub_authorship' submission_id=sub.id claim=1%}" method="post">
       {% csrf_token %}
       <input type="submit" value="I am an author" />
@@ -42,7 +42,7 @@
   <h3>Potential authorships to claim (auto-detected)</h3>
   <ul>
     {% for com in commentary_authorships_to_claim %}
-    {{ com.header_as_li | safe }}
+    {{ com.header_as_li }}
     <form action="{% url 'scipost:claim_com_authorship' commentary_id=com.id claim=1%}" method="post">
       {% csrf_token %}
       <input type="submit" value="I am an author" />
@@ -63,7 +63,7 @@
   <h3>Potential authorships to claim (auto-detected)</h3>
   <ul>
     {% for thesis in thesis_authorships_to_claim %}
-    {{ thesis.header_as_li | safe }}
+    {{ thesis.header_as_li }}
     <form action="{% url 'scipost:claim_thesis_authorship' thesis_id=thesis.id claim=1%}" method="post">
       {% csrf_token %}
       <input type="submit" value="I am an author" />
diff --git a/scipost/templates/scipost/comments_block.html b/scipost/templates/scipost/comments_block.html
index 3b2c427c8..e9e26b5bd 100644
--- a/scipost/templates/scipost/comments_block.html
+++ b/scipost/templates/scipost/comments_block.html
@@ -14,8 +14,8 @@
 
     <div class="flex-container">
       <div class="flex-commentbox">
-        {{ comment.print_identifier|safe }}
-        {{ comment.categories_as_ul|safe }}
+        {{ comment.print_identifier }}
+        {{ comment.categories_as_ul }}
         <div class="opinionsDisplay">
           {% if user.is_authenticated and user|is_in_group:'Registered Contributors' %}
 	  {% if user.contributor != comment.author %}
@@ -32,7 +32,7 @@
 	    <input type="submit" class="disagree" value="Disagree {{ comment.nr_D }}"/>
 	  </form>
 	  {% else %}
-	  {{ comment.opinions_as_ul|safe }}
+	  {{ comment.opinions_as_ul }}
 	  {% endif %}
           {% endif %}
         </div>
@@ -56,8 +56,8 @@
 
       <div class="flex-container">
 	<div class="flex-commentbox">
-          {{ reply.print_identifier|safe }}
-          {{ reply.categories_as_ul|safe }}
+          {{ reply.print_identifier }}
+          {{ reply.categories_as_ul }}
           <div class="opinionsDisplay">
             {% if user.is_authenticated and user|is_in_group:'Registered Contributors' %}
 	    {% if user.contributor != reply.author %}
@@ -74,7 +74,7 @@
 	      <input type="submit" class="disagree" value="Disagree {{ reply.nr_D }}"/>
 	    </form>
 	    {% else %}
-	    {{ reply.opinions_as_ul|safe }}
+	    {{ reply.opinions_as_ul }}
 	    {% endif %}
             {% endif %}
           </div>
diff --git a/scipost/templates/scipost/contributor_info.html b/scipost/templates/scipost/contributor_info.html
index c4aa1e918..dc57da5cc 100644
--- a/scipost/templates/scipost/contributor_info.html
+++ b/scipost/templates/scipost/contributor_info.html
@@ -32,7 +32,7 @@
   <div class="flex-greybox">
     <h1>Contributor info</h1>
   </div>
-  {{ contributor.public_info_as_table|safe }}
+  {{ contributor.public_info_as_table }}
 </section>
 
 {% if contributor_submissions %}
@@ -46,7 +46,7 @@
     <h3>Submissions for which this Contributor is identified as an author:</h3>
     <ul>
       {% for sub in contributor_submissions %}
-      {{ sub.header_as_li|safe }}
+      {{ sub.header_as_li }}
       {% endfor %}
     </ul>
   </div>
@@ -64,7 +64,7 @@
     <h3>Commentaries for which this Contributor is identified as an author:</h3>
     <ul>
       {% for com in contributor_commentaries %}
-      {{ com.header_as_li|safe }}
+      {{ com.header_as_li }}
       {% endfor %}
     </ul>
   </div>
@@ -82,7 +82,7 @@
     <h3>Theses for which this Contributor is identified as an author:</h3>
     <ul>
       {% for thesis in contributor_theses %}
-      {{ thesis.header_as_li|safe }}
+      {{ thesis.header_as_li }}
       {% endfor %}
     </ul>
   </div>
@@ -99,7 +99,7 @@
   <div id="mycommentslist">
     <ul>
       {% for comment in contributor_comments %}
-      {{ comment.header_as_li|safe }}
+      {{ comment.header_as_li }}
       {% endfor %}
     </ul>
   </div>
@@ -116,7 +116,7 @@
   <div id="myauthorreplieslist">
     <ul>
       {% for reply in contributor_authorreplies %}
-      {{ contributor_reply.header_as_li|safe }}
+      {{ contributor_reply.header_as_li }}
       {% endfor %}
     </ul>
   </div>
diff --git a/scipost/templates/scipost/personal_page.html b/scipost/templates/scipost/personal_page.html
index 11b784cc3..770d7163a 100644
--- a/scipost/templates/scipost/personal_page.html
+++ b/scipost/templates/scipost/personal_page.html
@@ -51,7 +51,7 @@
   <div class="row">
     <div class="col-6">
       <h3>Your personal details</h3>
-      {{ contributor.private_info_as_table|safe }}
+      {{ contributor.private_info_as_table }}
     </div>
     <div class="col-6">
       {% if request.user|is_in_group:'SciPost Administrators' %}
@@ -188,7 +188,7 @@
     <h3>Submissions for which you are identified as an author:</h3>
     <ul>
       {% for sub in own_submissions %}
-      {{ sub.header_as_li|safe }}
+      {{ sub.header_as_li }}
       {% endfor %}
     </ul>  
     {% endif %}
@@ -212,7 +212,7 @@
     <h3>Commentaries for which you are identified as an author:</h3>
     <ul>
       {% for com in own_commentaries %}
-      {{ com.header_as_li|safe }}
+      {{ com.header_as_li }}
       {% endfor %}
     </ul>  
     {% endif %}
@@ -236,7 +236,7 @@
     <h3>Theses for which you are identified as an author:</h3>
     <ul>
       {% for thesis in own_thesislinks %}
-      {{ thesis.header_as_li|safe }}
+      {{ thesis.header_as_li }}
       {% endfor %}
     </ul>
     {% endif %}
@@ -253,7 +253,7 @@
   <div id="mycommentslist">
     <ul>
       {% for own_comment in own_comments %}
-      {{ own_comment.header_as_li|safe }}
+      {{ own_comment.header_as_li }}
       {% endfor %}
     </ul>
   </div>
@@ -270,7 +270,7 @@
   <div id="myauthorreplieslist">
     <ul>
       {% for own_reply in own_authorreplies %}
-      {{ own_reply.header_as_li|safe }}
+      {{ own_reply.header_as_li }}
       {% endfor %}
     </ul>
   </div>
diff --git a/scipost/templates/scipost/vet_authorship_claims.html b/scipost/templates/scipost/vet_authorship_claims.html
index b58b4b70c..a5e85d782 100644
--- a/scipost/templates/scipost/vet_authorship_claims.html
+++ b/scipost/templates/scipost/vet_authorship_claims.html
@@ -21,13 +21,13 @@
     {% for claim in claims_to_vet %}
     {% if claim.submission %}
     <h4>Contributor {{ claim.claimant.user.first_name }} {{ claim.claimant.user.last_name }} claims to be an author of Submission:</h4>
-    {{ claim.submission.header_as_li | safe }}
+    {{ claim.submission.header_as_li }}
     {% elif claim.commentary %}
     <h4>Contributor {{ claim.claimant.user.first_name }} {{ claim.claimant.user.last_name }} claims to be an author of Submission:</h4>
-    {{ claim.commentary.header_as_li | safe }}
+    {{ claim.commentary.header_as_li }}
     {% elif claim.thesislink %}
     <h4>Contributor {{ claim.claimant.user.first_name }} {{ claim.claimant.user.last_name }} claims to be an author of Thesis:</h4>
-    {{ claim.thesislink.header_as_li | safe }}
+    {{ claim.thesislink.header_as_li }}
     {% endif %}
 
     <form action="{% url 'scipost:vet_authorship_claim' claim_id=claim.id claim=1%}" method="post">
diff --git a/scipost/templates/scipost/vet_registration_requests.html b/scipost/templates/scipost/vet_registration_requests.html
index 5ccf996e8..c552a4e62 100644
--- a/scipost/templates/scipost/vet_registration_requests.html
+++ b/scipost/templates/scipost/vet_registration_requests.html
@@ -60,7 +60,7 @@ $( document ).ready(function() {
   <hr>
   <div class="flex-container">
     <div class="flex-whitebox">
-      {{ contributor_to_vet.private_info_as_table|safe }}
+      {{ contributor_to_vet.private_info_as_table }}
     </div>
     <div class="flex-whitebox">
       <form action="{% url 'scipost:vet_registration_request_ack' contributor_id=contributor_to_vet.id %}" method="post">
diff --git a/submissions/models.py b/submissions/models.py
index 46c7bd075..488b70c6e 100644
--- a/submissions/models.py
+++ b/submissions/models.py
@@ -2,6 +2,7 @@ from django.utils import timezone
 from django.utils.safestring import mark_safe
 from django.db import models
 from django.contrib.auth.models import User
+from django.template import Template, Context
 
 from .models import *
 
@@ -71,11 +72,12 @@ class Submission(models.Model):
             return True
         return False
 
+
     def header_as_table (self):
         # for Submission page
         header = '<table>'
-        header += '<tr><td>Title: </td><td>&nbsp;</td><td>' + self.title + '</td></tr>'
-        header += '<tr><td>Author(s): </td><td>&nbsp;</td><td>' + self.author_list + '</td></tr>'
+        header += '<tr><td>Title: </td><td>&nbsp;</td><td>{{ title }}</td></tr>'
+        header += '<tr><td>Author(s): </td><td>&nbsp;</td><td>{{ author_list }}</td></tr>'
         header += '<tr><td>As Contributors: </td><td>&nbsp;</td>'
         if self.authors.all():
             for auth in self.authors.all():
@@ -83,33 +85,36 @@ class Submission(models.Model):
         else:
             header += '<td>(none claimed)</td>'
         header += '</tr>'
-        header += '<tr><td>arxiv Link: </td><td>&nbsp;</td><td><a href="' + self.arxiv_link + '" target="_blank">' + self.arxiv_link + '</a></td></tr>'
-        header += '<tr><td>Date submitted: </td><td>&nbsp;</td><td>' + str(self.submission_date) + '</td></tr>'
-        header += '<tr><td>Submitted by: </td><td>&nbsp;</td><td>' + str(self.submitted_by) + '</td></tr>'
-        header += '<tr><td>Submitted to: </td><td>&nbsp;</td><td>' + journals_submit_dict[self.submitted_to_journal] + '</td></tr>'
-        header += '<tr><td>Domain(s): </td><td>&nbsp;</td><td>' + journals_domains_dict[self.domain] + '</td></tr>'
-        header += '<tr><td>Specialization: </td><td>&nbsp;</td><td>' + journals_spec_dict[self.specialization] + '</td></tr>'
+        header += '<tr><td>arxiv Link: </td><td>&nbsp;</td><td><a href="{{ arxiv_link }}" target="_blank">{{ arxiv_link }}</a></td></tr>'
+        header += '<tr><td>Date submitted: </td><td>&nbsp;</td><td>{{ submission_date }}</td></tr>'
+        header += '<tr><td>Submitted by: </td><td>&nbsp;</td><td>{{ submitted_by }}</td></tr>'
+        header += '<tr><td>Submitted to: </td><td>&nbsp;</td><td>{{ to_journal }}</td></tr>'
+        header += '<tr><td>Domain(s): </td><td>&nbsp;</td><td>{{ domain }}</td></tr>'
+        header += '<tr><td>Specialization: </td><td>&nbsp;</td><td>{{ spec }}</td></tr>'
         header += '</table>'
-        return header
+        template = Template(header)
+        context = Context({'title': self.title, 'author_list': self.author_list,
+                           'arxiv_link': self.arxiv_link, 'submission_date': self.submission_date,
+                           'submitted_by': self.submitted_by, 'to_journal': journals_submit_dict[self.submitted_to_journal],
+                           'domain': journals_domains_dict[self.domain], 'spec': journals_spec_dict[self.specialization]})
+        return template.render(context)
+
 
     def header_as_li (self):
         # for search lists
         header = '<li><div class="flex-container">'
-        header += ('<div class="flex-whitebox0"><p><a href="/submission/' + str(self.id) + 
-                   '" class="pubtitleli">' + self.title + '</a></p>')
-        header += ('<p>by ' + self.author_list + 
-                   '</p><p> (submitted ' + str(self.submission_date) + 
-                   ' to ' + journals_submit_dict[self.submitted_to_journal] + 
-                   ') - latest activity: ' + self.latest_activity.strftime('%Y-%m-%d %H:%M') + 
-                   '</p></div>')
-        header += '</div></li>'
-        return header
+        header += '<div class="flex-whitebox0"><p><a href="/submission/{{ id }}" class="pubtitleli">{{ title }}</a></p>'
+        header += ('<p>by {{ author_list }}</p><p> (submitted {{ submission_date }} to {{ to_journal }})' +
+                   ' - latest activity: {{ latest_activity }}</p></div></div></li>')
+        context = Context({'id': self.id, 'title': self.title, 'author_list': self.author_list,
+                           'submission_date': self.submission_date, 
+                           'to_journal': journals_submit_dict[self.submitted_to_journal],
+                           'latest_activity': self.latest_activity.strftime('%Y-%m-%d %H:%M')})
+        template = Template(header)
+        return template.render(context)
 
     def status_info_as_table (self):
         header = '<table>'
-#        if self.assignment is not None:
-#            header += '<tr><td>Editor in charge: </td><td>&nbsp;</td><td>' + str(self.assignment.to) + '</td></tr>'
-#        header += '<tr><td>Assigned: </td><td>&nbsp;</td><td>' + str(self.assigned) + '</td></tr>'
         header += '<tr><td>Current status: </td><td>&nbsp;</td><td>' + submission_status_dict[self.status] + '</td></tr>'
         header += '</table>'
         return mark_safe(header)
@@ -148,16 +153,17 @@ class EditorialAssignment(models.Model):
     
     def header_as_li(self):
         header = '<li><div class="flex-container">'
-        header += ('<div class="flex-whitebox0"><p><a href="/submission/' + str(self.submission.id) +
-                   '" class="pubtitleli">' + self.submission.title + '</a></p>')
-        header += ('<p>by ' + self.submission.author_list +
-                   '</p><p> (submitted ' + str(self.submission.submission_date) +
-                   ' to ' + journals_submit_dict[self.submission.submitted_to_journal] +
-                   ')</p>')
-        header += ('<p>Status: ' + submission_status_dict[self.submission.status] + 
-                   '</p><p>Manage this Submission from its <a href="/submissions/editorial_page/' + str(self.submission.id) + '">Editorial Page</a>.</p>')
-        header += '</div></div></li>'
-        return mark_safe(header)
+        header += '<div class="flex-whitebox0"><p><a href="/submission/{{ id }}" class="pubtitleli">{{ title }}</a></p>'
+        header += '<p>by {{ author_list }}</p><p> (submitted {{ date }} to {{ to_journal }})</p>'
+        header += '<p>Status: {{ status }}</p><p>Manage this Submission from its '
+        header += '<a href="/submissions/editorial_page/{{ id }}">Editorial Page</a>.</p></div></div></li>'
+        template = Template(header)
+        context = Context({'id': self.submission.id, 'title': self.submission.title,
+                   'author_list': self.submission.author_list, 'date': self.submission.submission_date,
+                   'to_journal': journals_submit_dict[self.submission.submitted_to_journal],
+                   'status': submission_status_dict[self.submission.status]})
+        return template.render(context)
+    
 
 
 class RefereeInvitation(models.Model):
@@ -181,21 +187,24 @@ class RefereeInvitation(models.Model):
                 ', invited on ' + self.date_invited.strftime('%Y-%m-%d'))
     
     def summary_as_li(self):
-        output = '<li>' + self.first_name + ' ' + self.last_name + ', '
-        output += 'invited ' + self.date_invited.strftime('%Y-%m-%d %H:%M') + ', '
+        context = Context({'first_name': self.first_name, 'last_name': self.last_name,
+                           'date_invited': self.date_invited.strftime('%Y-%m-%d %H:%M')})
+        output = '<li>{{ first_name }} {{ last_name }}, invited {{ date_invited }}, '
         if self.accepted is not None:
             if self.accepted:
                 output += 'task accepted '
             else:
                 output += 'task declined ' 
-            output += self.date_responded.strftime('%Y-%m-%d %H:%M')
+            output += '{{ date_responded }}'
+            context['date_responded'] = self.date_responded.strftime('%Y-%m-%d %H:%M')
         else:
             output += 'response pending'
         if self.fulfilled:
             output += '; Report has been delivered'
         else:
             output += '; (no Report yet)'
-        return mark_safe(output)
+        template = Template(output)
+        return template.render(context)
     
 
 ###########
@@ -274,26 +283,28 @@ class Report(models.Model):
 
 
     def print_identifier(self):
+        context = Context({'id': self.id, 'author_id': self.author.id,
+                           'first_name': self.author.user.first_name,
+                           'last_name': self.author.user.last_name,
+                           'date_submitted': self.date_submitted.strftime("%Y-%m-%d")})
         output = '<div class="reportid">\n'
-        output += '<h3><a id="report_id' + str(self.id) + '"></a>'
+        output += '<h3><a id="report_id{{ id }}"></a>'
         if self.anonymous:
-            output += 'Anonymous Report ' + str(self.id)
+            output += 'Anonymous Report {{ id }}'
         else:
-            output += ('<a href="/contributor/' + str(self.author.id) + '">' +
-                       self.author.user.first_name + ' ' + self.author.user.last_name + '</a>')
-        output += ' on ' + self.date_submitted.strftime("%Y-%m-%d")
-        output += '</h3></div>'
-        return mark_safe(output)
+            output += '<a href="/contributor/{{ author_id }}">{{ first_name }} {{ last_name }}</a>'
+        output += ' on {{ date_submitted }}</h3></div>'
+        template = Template(output)
+        return template.render(context)
+
     
     def print_contents(self):
-        output = ('<div class="row"><div class="col-2"><p>Strengths:</p></div><div class="col-10"><p>' +
-                  self.strengths + '</p></div></div>' + 
-                  '<div class="row"><div class="col-2"><p>Weaknesses:</p></div><div class="col-10"><p>' +
-                  self.weaknesses + '</p></div></div>' +
-                  '<div class="row"><div class="col-2"><p>Report:</p></div><div class="col-10"><p>' +
-                  self.report + '</p></div></div>' +
-                  '<div class="row"><div class="col-2"><p>Requested changes:</p></div><div class="col-10"><p>' +
-                  self.requested_changes + '</p></div></div>')
+        context = Context({'strengths': self.strengths, 'weaknesses': self.weaknesses,
+                           'report': self.report, 'requested_changes': self.requested_changes})
+        output = ('<div class="row"><div class="col-2"><p>Strengths:</p></div><div class="col-10"><p>{{ strengths }}</p></div></div>' + 
+                  '<div class="row"><div class="col-2"><p>Weaknesses:</p></div><div class="col-10"><p>{{ weaknesses }}</p></div></div>' +
+                  '<div class="row"><div class="col-2"><p>Report:</p></div><div class="col-10"><p>{{ report }}</p></div></div>' +
+                  '<div class="row"><div class="col-2"><p>Requested changes:</p></div><div class="col-10"><p>{{ requested_changes }}</p></div></div>')
         output += '<div class="reportRatings"><ul>'
         output += '<li>validity: ' + ranking_choices_dict[self.validity] + '</li>'
         output += '<li>significance: ' + ranking_choices_dict[self.significance] + '</li>'
@@ -302,22 +313,27 @@ class Report(models.Model):
         output += '<li>formatting: ' + quality_spec_dict[self.formatting] + '</li>'
         output += '<li>grammar: ' + quality_spec_dict[self.grammar] + '</li>'
         output += '</ul></div>'
-        return mark_safe(output)
+        template = Template(output)
+        return template.render(context)
+    
                   
     def print_contents_for_editors(self):
+        context = Context({'id': self.id, 'author_id': self.author.id,
+                           'author_first_name': self.author.user.first_name,
+                           'author_last_name': self.author.user.last_name,
+                           'date_submitted': self.date_submitted.strftime("%Y-%m-%d")})
         output = '<div class="reportid">\n'
-        output += '<h3><a id="report_id' + str(self.id) + '"></a>'
+        output += '<h3><a id="report_id{{ id }}"></a>'
         if self.anonymous:
             output += '(chose public anonymity) '
-        output += ('<a href="/contributor/' + str(self.author.id) + '">' +
-                   self.author.user.first_name + ' ' + self.author.user.last_name + '</a>')
-        output += ' on ' + self.date_submitted.strftime("%Y-%m-%d")
-        output += '</h3></div>'
+        output += '<a href="/contributor/{{ author_id }}">{{ author_first_name }} {{ author_last_name }}</a>'
+        output += ' on {{ date_submitted }}</h3></div>'
         output += ('<div class="row"><div class="col-2">Qualification:</p></div><div class="col-10"><p>' + 
                   ref_qualif_dict[self.qualification] + '</p></div></div>')
         output += self.print_contents()
         output += '<h3>Recommendation: ' + report_rec_dict[self.recommendation] + '</h3>'
-        return mark_safe(output)
+        template = Template(output)
+        return template.render(context)
 
 
 ##########################
@@ -353,6 +369,7 @@ class EditorialCommunication(models.Model):
         return output
 
     def print_contents_as_li(self):
+        context = Context({'timestamp': self.timestamp.strftime("%Y-%m-%d %H:%M"), 'text': self.text})
         output = '<li><p>'
         if self.type == 'EtoA':
             output += 'From you to Authors'
@@ -374,9 +391,9 @@ class EditorialCommunication(models.Model):
                 pass
         elif self.type == 'StoE':
             output += 'From SciPost Ed Admin to you'
-        output += ' on ' + self.timestamp.strftime("%Y-%m-%d %H:%M") + '</p>'
-        output += '<p>' + self.text + '</p>'
-        return mark_safe(output)
+        output += ' on {{ timestamp }}</p><p>{{ text }}</p>'
+        template = Template(output)
+        return template.render(context)
 
 
 
diff --git a/submissions/templates/submissions/accept_or_decline_assignments.html b/submissions/templates/submissions/accept_or_decline_assignments.html
index d43f8d735..03ef0b5e6 100644
--- a/submissions/templates/submissions/accept_or_decline_assignments.html
+++ b/submissions/templates/submissions/accept_or_decline_assignments.html
@@ -33,7 +33,7 @@ $(document).ready(function(){
   </div>
   <br>
   <hr>
-  {{ assignment_to_consider.submission.header_as_table|safe }}
+  {{ assignment_to_consider.submission.header_as_table }}
   <br />
   <h4>Abstract:</h4>
   <p>{{ assignment_to_consider.submission.abstract }}</p>
diff --git a/submissions/templates/submissions/accept_or_decline_ref_invitations.html b/submissions/templates/submissions/accept_or_decline_ref_invitations.html
index 2b4279f14..518a01446 100644
--- a/submissions/templates/submissions/accept_or_decline_ref_invitations.html
+++ b/submissions/templates/submissions/accept_or_decline_ref_invitations.html
@@ -33,7 +33,7 @@ $(document).ready(function(){
   </div>
   <br>
   <hr>
-  {{ invitation_to_consider.submission.header_as_table|safe }}
+  {{ invitation_to_consider.submission.header_as_table }}
   <br />
   <h4>Abstract:</h4>
   <p>{{ invitation_to_consider.submission.abstract }}</p>
diff --git a/submissions/templates/submissions/assign_submissions.html b/submissions/templates/submissions/assign_submissions.html
index d2595a13b..72821ee59 100644
--- a/submissions/templates/submissions/assign_submissions.html
+++ b/submissions/templates/submissions/assign_submissions.html
@@ -14,13 +14,13 @@
 
   <br>
   <hr>
-  {{ submission_to_assign.header_as_table|safe }}
+  {{ submission_to_assign.header_as_table }}
   <br />
   <h4>Abstract:</h4>
   <p>{{ submission_to_assign.abstract }}</p>
   <br/>
   <hr/>
-  {{ submission_to_assign.status_info_as_table|safe }}
+  {{ submission_to_assign.status_info_as_table }}
 
   <br/>
   <hr>
diff --git a/submissions/templates/submissions/communication.html b/submissions/templates/submissions/communication.html
index 3471f3acb..4a6867173 100644
--- a/submissions/templates/submissions/communication.html
+++ b/submissions/templates/submissions/communication.html
@@ -26,7 +26,7 @@
   {% elif type == 'EtoS' %}
   <p>to SciPost Editorial Administrators</p>
   {% endif %}
-  <ul>{{ submission.header_as_li|safe }}</ul>
+  <ul>{{ submission.header_as_li }}</ul>
 
   <br/>
   <form action="{% url 'submissions:communication' submission_id=submission.id type=type %}" method="post">
diff --git a/submissions/templates/submissions/editorial_page.html b/submissions/templates/submissions/editorial_page.html
index 6c187817a..c794a764c 100644
--- a/submissions/templates/submissions/editorial_page.html
+++ b/submissions/templates/submissions/editorial_page.html
@@ -25,7 +25,7 @@
       <h2>Submission:</h2>
     </div>
   </div>
-  {{ submission.header_as_table|safe }}
+  {{ submission.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ submission.abstract }}</p>
 
diff --git a/submissions/templates/submissions/eic_recommendation.html b/submissions/templates/submissions/eic_recommendation.html
index 0882b36a4..5e71b37c7 100644
--- a/submissions/templates/submissions/eic_recommendation.html
+++ b/submissions/templates/submissions/eic_recommendation.html
@@ -26,7 +26,7 @@
       <h2>Submission:</h2>
     </div>
   </div>
-  {{ submission.header_as_table|safe }}
+  {{ submission.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ submission.abstract }}</p>
 
diff --git a/submissions/templates/submissions/select_referee.html b/submissions/templates/submissions/select_referee.html
index 2344cd950..4c629204d 100644
--- a/submissions/templates/submissions/select_referee.html
+++ b/submissions/templates/submissions/select_referee.html
@@ -26,7 +26,7 @@
       <h2>Submission:</h2>
     </div>
   </div>
-  {{ submission.header_as_table|safe }}
+  {{ submission.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ submission.abstract }}</p>
 
diff --git a/submissions/templates/submissions/submission_detail.html b/submissions/templates/submissions/submission_detail.html
index bc26873ce..95d8fc6c3 100644
--- a/submissions/templates/submissions/submission_detail.html
+++ b/submissions/templates/submissions/submission_detail.html
@@ -41,7 +41,7 @@
       <h2>Submission:</h2>
     </div>
   </div>
-  {{ submission.header_as_table|safe }}
+  {{ submission.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ submission.abstract }}</p>
 
@@ -94,8 +94,8 @@
 
       <div class="flex-container">
         <div class="flex-commentbox">
-          {{ reply.print_identifier|safe }}
-          {{ reply.categories_as_ul|safe }}
+          {{ reply.print_identifier }}
+          {{ reply.categories_as_ul }}
           <div class="opinionsDisplay">
             {% if user.is_authenticated and user|is_in_group:'Registered Contributors' %}
             {% if user.contributor != reply.author %}
@@ -112,7 +112,7 @@
               <input type="submit" class="disagree" value="Disagree {{ reply.nr_D }}"/>
             </form>
             {% else %}
-            {{ reply.opinions_as_ul|safe }}
+            {{ reply.opinions_as_ul }}
             {% endif %}
             {% endif %}
           </div>
@@ -166,8 +166,8 @@
 
       <div class="flex-container">
         <div class="flex-commentbox">
-          {{ reply.print_identifier|safe }}
-          {{ reply.categories_as_ul|safe }}
+          {{ reply.print_identifier }}
+          {{ reply.categories_as_ul }}
           <div class="opinionsDisplay">
             {% if user.is_authenticated and user|is_in_group:'Registered Contributors' %}
             {% if user.contributor != reply.author %}
@@ -184,7 +184,7 @@
               <input type="submit" class="disagree" value="Disagree {{ reply.nr_D }}"/>
             </form>
             {% else %}
-            {{ reply.opinions_as_ul|safe }}
+            {{ reply.opinions_as_ul }}
             {% endif %}
             {% endif %}
           </div>
diff --git a/submissions/templates/submissions/submissions.html b/submissions/templates/submissions/submissions.html
index 0aaf51455..c6ee4f481 100644
--- a/submissions/templates/submissions/submissions.html
+++ b/submissions/templates/submissions/submissions.html
@@ -43,7 +43,7 @@
   <h3>Search results:</h3>
   <ul>
     {% for submission in submission_search_list %}
-    {{ submission.header_as_li|safe }}
+    {{ submission.header_as_li }}
     {% endfor %}
   </ul>
   {% elif form.has_changed %}
@@ -58,7 +58,7 @@
   <h2>Recent Submissions:</h2>
   <ul>  
     {% for submission in submission_recent_list %}
-    {{ submission.header_as_li|safe }}
+    {{ submission.header_as_li }}
     {% endfor %}
   </ul>
 </section>
@@ -70,7 +70,7 @@
   <h2>Submissions in {{ discipline }} in the last {{ nrweeksback }} weeks:</h2>
   <ul>
     {% for submission in submission_browse_list %}
-    {{ submission.header_as_li|safe }}
+    {{ submission.header_as_li }}
     {% endfor %}
   </ul>
   {% endif %}
diff --git a/submissions/templates/submissions/submit_report.html b/submissions/templates/submissions/submit_report.html
index ca1cdbf57..cf7e26f6f 100644
--- a/submissions/templates/submissions/submit_report.html
+++ b/submissions/templates/submissions/submit_report.html
@@ -14,7 +14,7 @@
   <div class="flex-greybox">
     <h2>Submission summary and link</h2>
   </div>
-  {{ submission.header_as_table|safe }}
+  {{ submission.header_as_table }}
   <br />
   <h3>Abstract:</h3>
   <p>{{ submission.abstract }}</p>
diff --git a/submissions/views.py b/submissions/views.py
index a2defe199..b3f301fa9 100644
--- a/submissions/views.py
+++ b/submissions/views.py
@@ -86,7 +86,7 @@ def browse(request, discipline, nrweeksback):
                 title__icontains=form.cleaned_data['title_keyword'],
                 author_list__icontains=form.cleaned_data['author'],
                 abstract__icontains=form.cleaned_data['abstract_keyword'],
-                vetted=True,
+                assigned=True,
                 )
             submission_search_list.order_by('-submission_date')
         else:
@@ -96,7 +96,7 @@ def browse(request, discipline, nrweeksback):
     else:
         form = SubmissionSearchForm()
     submission_browse_list = Submission.objects.filter(
-        vetted=True, discipline=discipline, 
+        assigned=True, discipline=discipline, 
         latest_activity__gte=timezone.now() + datetime.timedelta(weeks=-int(nrweeksback))
         )
     context = {'form': form, 'discipline': discipline, 'nrweeksback': nrweeksback, 
diff --git a/theses/models.py b/theses/models.py
index d9b9aed81..032e14673 100644
--- a/theses/models.py
+++ b/theses/models.py
@@ -1,6 +1,7 @@
 from django.utils import timezone
 from django.db import models
 from django.contrib.auth.models import User
+from django.template import Template, Context
 
 from .models import *
 
@@ -42,9 +43,12 @@ class ThesisLink(models.Model):
         return self.title
 
     def header_as_table (self):
+        context = Context({'title': self.title, 'author': self.author,
+                           'pub_link': self.pub_link, 'instituation': self.institution,
+                           'supervisor': self.supervisor, 'defense_date': self.defense_date})
         header = '<table>'
-        header += '<tr><td>Title: </td><td>&nbsp;</td><td>' + self.title + '</td></tr>'
-        header += '<tr><td>Author: </td><td>&nbsp;</td><td>' + self.author + '</td></tr>'
+        header += '<tr><td>Title: </td><td>&nbsp;</td><td>{{ title }}</td></tr>'
+        header += '<tr><td>Author: </td><td>&nbsp;</td><td>{{ author }}</td></tr>'
         header += '<tr><td>As Contributor: </td><td>&nbsp;</td>'
         if self.author_as_cont.all():
             for auth in self.author_as_cont.all():
@@ -56,18 +60,25 @@ class ThesisLink(models.Model):
         header += '<tr><td>Discipline: </td><td></td><td>' + disciplines_dict[self.discipline] + '</td></tr>'
         header += '<tr><td>Domain: </td><td></td><td>' + journals_domains_dict[self.domain] + '</td></tr>'
         header += '<tr><td>Specialization: </td><td></td><td>' + journals_spec_dict[self.specialization] + '</td></tr>'
-        header += '<tr><td>URL: </td><td>&nbsp;</td><td><a href="' + self.pub_link + '" target="_blank">' + self.pub_link + '</a></td></tr>'
-        header += '<tr><td>Degree granting institution: </td><td>&nbsp;</td><td>' + self.institution + '</td></tr>'
-        header += '<tr><td>Supervisor(s): </td><td></td><td>' + self.supervisor + '</td></tr>'
-        header += '<tr><td>Defense date: </td><td>&nbsp;</td><td>' + str(self.defense_date) + '</td></tr>'
+        header += '<tr><td>URL: </td><td>&nbsp;</td><td><a href="{{ pub_link }}" target="_blank">{{ pub_link }}</a></td></tr>'
+        header += '<tr><td>Degree granting institution: </td><td>&nbsp;</td><td>{{ institution }}</td></tr>'
+        header += '<tr><td>Supervisor(s): </td><td></td><td>{{ supervisor </td></tr>'
+        header += '<tr><td>Defense date: </td><td>&nbsp;</td><td>{{ defense_date }}</td></tr>'
         header += '</table>'
-        return header
+        template = Template(header)
+        return template.render(context)
+
 
     def header_as_li (self):
+        context = Context({'id': self.id, 'title': self.title, 'author': self.author,
+                           'pub_link': self.pub_link, 'instituation': self.institution,
+                           'supervisor': self.supervisor, 'defense_date': self.defense_date,
+                           'latest_activity': self.latest_activity.strftime('%Y-%m-%d %H:%M')})
         header = '<li><div class="flex-container">'
-        header += '<div class="flex-whitebox0"><p><a href="/thesis/' + str(self.id) + '" class="pubtitleli">' + self.title + '</a></p>'
-        header += '<p>' + thesis_type_dict[self.type] + ' thesis by ' + self.author + ' (supervisor(s): ' + self.supervisor + ') in ' 
+        header += '<div class="flex-whitebox0"><p><a href="/thesis/{{ id }}" class="pubtitleli">{{ title }}</a></p>'
+        header += '<p>' + thesis_type_dict[self.type] + ' thesis by {{ author }} (supervisor(s): {{ supervisor }}) in ' 
         header += disciplines_dict[self.discipline] + ', ' + journals_domains_dict[self.domain] + ' ' + journals_spec_dict[self.specialization] + '</p>'
-        header += '<p>Defense date: ' + str(self.defense_date) + ' - Latest activity: ' + self.latest_activity.strftime('%Y-%m-%d %H:%M') + '</p></div>'
+        header += '<p>Defense date: {{ defense_date }} - Latest activity: {{ latest_activity }}</p></div>'
         header += '</div></li>'
-        return header
+        template = Template(header)
+        return template.render(context)
diff --git a/theses/templates/theses/theses.html b/theses/templates/theses/theses.html
index a665ee160..5260555e5 100644
--- a/theses/templates/theses/theses.html
+++ b/theses/templates/theses/theses.html
@@ -41,7 +41,7 @@
   <h3>Search results:</h3>
   <ul>
     {% for thesislink in thesislink_search_list %}
-    {{ thesislink.header_as_li|safe }}
+    {{ thesislink.header_as_li }}
     {% endfor %}
   </ul>
   {% elif form.has_changed %}
@@ -56,7 +56,7 @@
   <h2>Recently active Thesis Links:</h2>
   <ul>
     {% for thesislink in thesislink_recent_list %}
-    {{ thesislink.header_as_li|safe }}
+    {{ thesislink.header_as_li }}
     {% endfor %}
   </ul>
 </section>
@@ -68,7 +68,7 @@
   <h2>Thesis Links in {{ discipline }} in the last {{ nrweeksback }} weeks:</h2>
   <ul>
     {% for thesislink in thesislink_browse_list %}
-    {{ thesislink.header_as_li|safe }}
+    {{ thesislink.header_as_li }}
     {% endfor %}
   </ul>
   {% endif %}
diff --git a/theses/templates/theses/thesis_detail.html b/theses/templates/theses/thesis_detail.html
index 28fbffece..ae97cef3b 100644
--- a/theses/templates/theses/thesis_detail.html
+++ b/theses/templates/theses/thesis_detail.html
@@ -32,7 +32,7 @@
       <h2>Thesis information: </h2>
     </div>
   </div>
-  {{ thesislink.header_as_table|safe }}
+  {{ thesislink.header_as_table }}
   <h3>Abstract:</h3>
   <p>{{ thesislink.abstract }}</p>
   
diff --git a/theses/templates/theses/vet_thesislink_requests.html b/theses/templates/theses/vet_thesislink_requests.html
index cce924142..4fd2a7d9a 100644
--- a/theses/templates/theses/vet_thesislink_requests.html
+++ b/theses/templates/theses/vet_thesislink_requests.html
@@ -16,7 +16,7 @@
   <hr>
   <div class="row">
     <div class="col-8">
-      {{ thesislink_to_vet.header_as_table|safe }}
+      {{ thesislink_to_vet.header_as_table }}
       <br />
       <h4>Abstract:</h4>
       <p>{{ thesislink_to_vet.abstract }}</p>
-- 
GitLab