SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 419a19c6 authored by Geert Kapteijns's avatar Geert Kapteijns
Browse files

Extract ThesisLink#header_as_table to partial template

Markup logic should be in templates, not in model layer.

Partial template is named _header_as_table to signal
that it is ment to be included into other templates
(analogous to the private method naming convention.)
The full text of several of the thesis link's fields
(domain, subject_area, etc.) are fetched from constant dicts
in custom filters defined in theses.templatetags.theses_extras.
parent 7c9d5de8
No related branches found
No related tags found
No related merge requests found
......@@ -69,45 +69,6 @@ class ThesisLink(models.Model):
def __str__(self):
return self.title
def header_as_table(self):
context = Context({
'title': self.title, 'author': self.author,
'pub_link': self.pub_link, 'institution': self.institution,
'supervisor': self.supervisor, 'defense_date': self.defense_date})
header = (
'<table>'
'<tr><td>Title: </td><td>&nbsp;</td><td>{{ title }}</td></tr>'
'<tr><td>Author: </td><td>&nbsp;</td><td>{{ author }}</td></tr>'
'<tr><td>As Contributor: </td><td>&nbsp;</td>')
if self.author_as_cont.all():
for auth in self.author_as_cont.all():
header += (
'<td><a href="/contributor/' + str(auth.id) + '">' +
auth.user.first_name + ' ' + auth.user.last_name +
'</a></td>')
else:
header += '<td>(not claimed)</td>'
header += (
'</tr>'
'<tr><td>Type: </td><td></td><td>' + self.THESIS_TYPES_DICT[self.type] +
'</td></tr>'
'<tr><td>Discipline: </td><td></td><td>' +
disciplines_dict[self.discipline] + '</td></tr>'
'<tr><td>Domain: </td><td></td><td>' +
journals_domains_dict[self.domain] + '</td></tr>'
'<tr><td>Subject area: </td><td></td><td>' +
subject_areas_dict[self.subject_area] + '</td></tr>'
'<tr><td>URL: </td><td>&nbsp;</td><td><a href="{{ pub_link }}" '
'target="_blank">{{ pub_link }}</a></td></tr>'
'<tr><td>Degree granting institution: </td><td>&nbsp;</td>'
'<td>{{ institution }}</td></tr>'
'<tr><td>Supervisor(s): </td><td></td><td>{{ supervisor }}'
'</td></tr>' '<tr><td>Defense date: </td><td>&nbsp;</td>'
'<td>{{ defense_date }}</td></tr>'
'</table>')
template = Template(header)
return template.render(context)
def header_as_li(self):
context = Context({
'id': self.id, 'title': self.title, 'author': self.author,
......
{% load theses_extras %}
<table>
<tr>
<td>Title: </td><td>&nbsp;</td><td>{{ title }}</td>
</tr>
<tr>
<td>Author: </td><td>&nbsp;</td><td>{{ author }}</td>
</tr>
<tr>
<td>As Contributor: </td><td>&nbsp;</td>
{% if thesislink.author_as_cont.all %}
{% for author in thesislink.author_as_cont.all %}
<td><a href= {% url 'scipost:contributor_info' author.id %}>
author.user.first_name author.user.last_name
</a></td>
{% endfor %}
{% else %}
<td>(not claimed)</td>
{% endif %}
</tr>
<tr>
<td>Type: </td><td></td><td> {{ thesislink|type }}</td>
</tr>
<tr>
<td>Discipline: </td><td></td><td>{{ thesislink|discipline }}</td>
</tr>
<tr>
<td>Domain: </td><td></td><td>{{ thesislink|domain }}</td>
</tr>
<tr>
<td>Subject area: </td><td></td><td> {{ thesislink|subject_area }} </td>
</tr>
<tr>
<td>URL: </td><td>&nbsp;</td><td><a href="{{ pub_link }}" target="_blank">{{ thesislink.pub_link }}</a></td>
</tr>
<tr>
<td>Degree granting institution: </td><td>&nbsp;</td><td>{{ thesislink.institution }}</td>
</tr>
<tr>
<td>Supervisor(s): </td><td></td><td>{{ thesislink.supervisor }}</td>
</tr>
<tr>
<td>Defense date: </td><td>&nbsp;</td><td>{{ thesislink.defense_date }}</td>
</tr>
</table>
......@@ -44,7 +44,8 @@
<h2>Thesis information: </h2>
</div>
</div>
{{ thesislink.header_as_table }}
{% include "./_header_as_table.html" with thesislink=thesislink %}
{# {{ thesislink.header_as_table }}#}
<h3>Abstract:</h3>
<p>{{ thesislink.abstract }}</p>
......
from django import template
from scipost.constants import SCIPOST_DISCIPLINES, subject_areas_dict, disciplines_dict
from journals.models import journals_domains_dict
register = template.Library()
@register.filter
def type(thesislink):
return thesislink.THESIS_TYPES_DICT[thesislink.type]
@register.filter
def discipline(thesislink):
return disciplines_dict[thesislink.discipline]
@register.filter
def domain(thesislink):
return journals_domains_dict[thesislink.domain]
@register.filter
def subject_area(thesislink):
return subject_areas_dict[thesislink.subject_area]
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