From 05e255c64869be6d0c7da53d74c333534eefa4ff Mon Sep 17 00:00:00 2001
From: Geert Kapteijns <ghkapteijns@gmail.com>
Date: Tue, 14 Feb 2017 21:24:41 +0100
Subject: [PATCH] Extract thesislink_header_as_li to partial template

---
 theses/models.py                              | 20 -------------------
 .../theses/_thesislink_header_as_li.html      | 12 +++++++++++
 theses/templates/theses/theses.html           |  6 +++---
 3 files changed, 15 insertions(+), 23 deletions(-)
 create mode 100644 theses/templates/theses/_thesislink_header_as_li.html

diff --git a/theses/models.py b/theses/models.py
index 368005d64..69fb37790 100644
--- a/theses/models.py
+++ b/theses/models.py
@@ -67,26 +67,6 @@ class ThesisLink(models.Model):
     def __str__(self):
         return self.title
 
-    def header_as_li(self):
-        context = Context({
-            'id': self.id, 'title': self.title, 'author': self.author,
-            'pub_link': self.pub_link, 'institution': self.institution,
-            'supervisor': self.supervisor, 'defense_date': self.defense_date,
-            'latest_activity': self.latest_activity.strftime('%Y-%m-%d %H:%M')})
-
-        header = (
-            '<li><p><a href="/thesis/{{ id }}" '
-            'class="pubtitleli">{{ title }}</a></p>'
-            '<p>' + self.THESIS_TYPES_DICT[self.type] + ' thesis by {{ author }} '
-            '(supervisor(s): {{ supervisor }}) in ' +
-            disciplines_dict[self.discipline] + ', ' +
-            journals_domains_dict[self.domain] + ' ' +
-            subject_areas_dict[self.subject_area] + '</p>'
-            '<p>Defense date: {{ defense_date }} - '
-            'Latest activity: {{ latest_activity }}</p></li>')
-        template = Template(header)
-        return template.render(context)
-
     def simple_header_as_li(self):
         # for Lists
         context = Context({
diff --git a/theses/templates/theses/_thesislink_header_as_li.html b/theses/templates/theses/_thesislink_header_as_li.html
new file mode 100644
index 000000000..bb6f85035
--- /dev/null
+++ b/theses/templates/theses/_thesislink_header_as_li.html
@@ -0,0 +1,12 @@
+{% load theses_extras %}
+
+<li>
+    <p>
+        <a href="{% url 'theses:thesis' thesislink_id=thesislink.id %}" class="pubtitleli">{{ thesislink.title }}</a>
+    </p>
+    <p>{{ thesislink|type }} thesis by {{ thesislink.author }}
+    (supervisor(s): {{ thesislink.supervisor }}) in
+    {{ thesislink|discipline }}, {{ thesislink|domain }} {{ thesislink|subject_area }}.
+    </p>
+    <p>Defense date: {{ thesislink.defense_date }}. Latest activity: {{ thesislink.latest_activity|date:"DATE_FORMAT" }}.</p>
+</li>
diff --git a/theses/templates/theses/theses.html b/theses/templates/theses/theses.html
index ff8bd344f..e50560f5f 100644
--- a/theses/templates/theses/theses.html
+++ b/theses/templates/theses/theses.html
@@ -47,7 +47,7 @@
         {% if thesislink_search_list %}
           <ul>
             {% for thesislink in thesislink_search_list %}
-            {{ thesislink.header_as_li }}
+                {% include 'theses/_thesislink_header_as_li.html' with thesislink=thesislink %}
             {% endfor %}
           </ul>
         {% elif form.has_changed %}
@@ -64,7 +64,7 @@
       <h2>Recently active Thesis Links:</h2>
       <ul>
         {% for thesislink in thesislink_recent_list %}
-        {{ thesislink.header_as_li }}
+            {% include 'theses/_thesislink_header_as_li.html' with thesislink=thesislink %}
         {% endfor %}
       </ul>
     </div>
@@ -78,7 +78,7 @@
       <h2>Thesis Links in {{ discipline }} in the last {{ nrweeksback }} week{% if nrweeksback == '1' %}{% else %}s{% endif %}:</h2>
       <ul>
         {% for thesislink in thesislink_browse_list %}
-        {{ thesislink.header_as_li }}
+            {% include 'theses/_thesislink_header_as_li.html' with thesislink=thesislink %}
         {% endfor %}
       </ul>
     </div>
-- 
GitLab