diff --git a/theses/models.py b/theses/models.py index 50ec6b1f47548e9f43d6f53d31d091883f4ed091..fbd5f370d030f2fe3c7e163082cefa39a258efe8 100644 --- a/theses/models.py +++ b/theses/models.py @@ -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> </td><td>{{ title }}</td></tr>' - '<tr><td>Author: </td><td> </td><td>{{ author }}</td></tr>' - '<tr><td>As Contributor: </td><td> </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> </td><td><a href="{{ pub_link }}" ' - 'target="_blank">{{ pub_link }}</a></td></tr>' - '<tr><td>Degree granting institution: </td><td> </td>' - '<td>{{ institution }}</td></tr>' - '<tr><td>Supervisor(s): </td><td></td><td>{{ supervisor }}' - '</td></tr>' '<tr><td>Defense date: </td><td> </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, diff --git a/theses/templates/theses/_header_as_table.html b/theses/templates/theses/_header_as_table.html new file mode 100644 index 0000000000000000000000000000000000000000..c6f6fb9baf701b09421fbd134b1df676bdf14b1c --- /dev/null +++ b/theses/templates/theses/_header_as_table.html @@ -0,0 +1,46 @@ +{% load theses_extras %} + +<table> + <tr> + <td>Title: </td><td> </td><td>{{ title }}</td> + </tr> + <tr> + <td>Author: </td><td> </td><td>{{ author }}</td> + </tr> + <tr> + <td>As Contributor: </td><td> </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> </td><td><a href="{{ pub_link }}" target="_blank">{{ thesislink.pub_link }}</a></td> + </tr> + <tr> + <td>Degree granting institution: </td><td> </td><td>{{ thesislink.institution }}</td> + </tr> + <tr> + <td>Supervisor(s): </td><td></td><td>{{ thesislink.supervisor }}</td> + </tr> + <tr> + <td>Defense date: </td><td> </td><td>{{ thesislink.defense_date }}</td> + </tr> +</table> diff --git a/theses/templates/theses/thesis_detail.html b/theses/templates/theses/thesis_detail.html index 541f934e1009668a521c0839c0a54fa77f9748af..45b16160beaa66b2f6f1041d0255a65c99642f2a 100644 --- a/theses/templates/theses/thesis_detail.html +++ b/theses/templates/theses/thesis_detail.html @@ -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> diff --git a/theses/templatetags/__init__.py b/theses/templatetags/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/theses/templatetags/theses_extras.py b/theses/templatetags/theses_extras.py new file mode 100644 index 0000000000000000000000000000000000000000..f3b441f41f64e3bb5a7ad23f852eb3e627fe9dec --- /dev/null +++ b/theses/templatetags/theses_extras.py @@ -0,0 +1,26 @@ +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]