From 194fc234fe4583e51121e17a6c03958504024d1c Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Mon, 27 Feb 2017 00:11:40 +0100 Subject: [PATCH] Remove HTML from models --- commentaries/models.py | 33 +------ .../commentaries/commentary_header_li.html | 13 +++ ...commentaries.html => commentary_list.html} | 92 ++++++++----------- .../commentaries/request_commentary.html | 2 +- 4 files changed, 54 insertions(+), 86 deletions(-) create mode 100644 commentaries/templates/commentaries/commentary_header_li.html rename commentaries/templates/commentaries/{commentaries.html => commentary_list.html} (60%) diff --git a/commentaries/models.py b/commentaries/models.py index e42eb4164..37b54c8ca 100644 --- a/commentaries/models.py +++ b/commentaries/models.py @@ -1,6 +1,7 @@ from django.db import models from django.contrib.postgres.fields import JSONField from django.template import Template, Context +from django.template.loader import get_template from journals.models import SCIPOST_JOURNALS_DOMAINS from scipost.behaviors import ArxivCallable @@ -135,36 +136,10 @@ class Commentary(ArxivCallable, TimeStampedModel): template = Template('<a href="{{scipost_url}}" class="pubtitleli">{{pub_title}}</a>') return template.render(context) - def header_as_li(self): - # for display in search lists - 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')}) - header = ('<li>' - # '<div class="flex-container">' - # '<div class="flex-whitebox0">' - '<p><a href="{{ scipost_url }}" ' - 'class="pubtitleli">{{ pub_title }}</a></p>' - '<p>by {{ author_list }}') - if self.type == 'published': - header += ', {{ journal }} {{ volume }}, {{ pages }}' - context['journal'] = self.journal - context['volume'] = self.volume - context['pages'] = self.pages - elif self.type == 'preprint': - header += ', <a href="{{ arxiv_link }}">{{ arxiv_link }}</a>' - context['arxiv_link'] = self.arxiv_link - header += '</p>' - if self.pub_date: - header += '<p> (published {{ pub_date }}) - ' - context['pub_date'] = str(self.pub_date) - header += ('latest activity: {{ latest_activity }}</p>' - # '</div></div>' - '</li>') - template = Template(header) - - return template.render(context) + # TO BE REMOVED!!!! + template = get_template('commentaries/commentary_header_li.html') + return template.render({'object': self}) def simple_header_as_li(self): # for display in Lists diff --git a/commentaries/templates/commentaries/commentary_header_li.html b/commentaries/templates/commentaries/commentary_header_li.html new file mode 100644 index 000000000..56fd1ee2e --- /dev/null +++ b/commentaries/templates/commentaries/commentary_header_li.html @@ -0,0 +1,13 @@ +<li> + <p> + <a href="{{ object.scipost_url }}" class="pubtitleli">{{ object.pub_title }}</a> + </p> + <p> + by {{ object.author_list }} + {% if object.type == 'published' %}, {{ object.journal }} {{ object.volume }}, {{ object.pages }} + {% elif object.type == 'preprint' %}, <a href="{{ object.arxiv_link }}">{{ object.arxiv_link }}</a>{% endif %} + </p> + <p> + {% if object.pub_date %}(published {{ object.pub_date }}) - {% endif %}latest activity: {{ object.latest_activity }} + </p> +</li> diff --git a/commentaries/templates/commentaries/commentaries.html b/commentaries/templates/commentaries/commentary_list.html similarity index 60% rename from commentaries/templates/commentaries/commentaries.html rename to commentaries/templates/commentaries/commentary_list.html index d555bd005..4a420102c 100644 --- a/commentaries/templates/commentaries/commentaries.html +++ b/commentaries/templates/commentaries/commentary_list.html @@ -1,6 +1,7 @@ {% extends 'scipost/base.html' %} {% load bootstrap %} +{% load request_filters %} {% block pagetitle %}: Commentaries{% endblock pagetitle %} @@ -9,8 +10,6 @@ {% endblock headsup %} {% block content %} - - <div class="row"> <div class="col-md-4"> <div class="panel page-header-panel"> @@ -22,10 +21,9 @@ <div class="col-md-4"> <div class="panel page-header-panel"> <h2>Search SciPost Commentaries:</h2> - <form action="{% url 'commentaries:commentaries' %}" class="small" method="post"> - {% csrf_token %} + <form action="{% url 'commentaries:commentaries' %}" class="small" method="get"> {{ form|bootstrap:'4,8,sm' }} - <input class="btn btn-sm btn-secondary" type="submit" name="Submit" /> + <input class="btn btn-sm btn-secondary" type="submit"/> </form> </div> </div> @@ -39,69 +37,51 @@ </div> </div> - {% if commentary_search_list %} - <div class="row"> - <div class="col-12"> - <hr class="hr12"> - <h3>Search results:</h3> - <ul> - {% for commentary in commentary_search_list %} - {{ commentary.header_as_li }} - {% endfor %} - </ul> - </div> - </div> - {% elif form.has_changed %} - <div class="row"> - <div class="col-12"> - <h3>No match found for your search query.</h3> - </div> - </div> - {% endif %} - - - -{% if comment_recent_list %} - <div class="row"> - <div class="col-12"> +{% if not browse and recent %} +<div class="row"> + <div class="col-12"> <hr class="hr12"> <h2>Recent Comments</h2> <ul> - {% for comment in comment_recent_list %} + {% for comment in comment_list %} {{ comment.simple_header_as_li }} {% endfor %} </ul> </div> - </div> -{% endif %} - -{% if commentary_recent_list %} -<div class="row"> - <div class="col-12"> - <hr class="hr12"> - <h2>Recently active Commentaries:</h2> - <ul> - {% for commentary in commentary_recent_list %} - {{ commentary.header_as_li }} - {% endfor %} - </ul> - </div> </div> {% endif %} -{% if commentary_browse_list %} <div class="row"> <div class="col-12"> - <hr class="hr12"> - <h2>Commentaries in {{ discipline }} in the last {{ nrweeksback }} week{% if nrweeksback == '1' %}{% else %}s{% endif %}:</h2> - <ul> - {% for commentary in commentary_browse_list %} - {{ commentary.header_as_li }} - {% endfor %} - </ul> - </div> + <hr class="hr12"> + {% if recent %} + <h2>Recently active Commentaries:</h2> + {% elif browse %} + <h2>Commentaries in {{ discipline }} in the last {{ nrweeksback }} week{{ nrweeksback|pluralize }}:</h2> + {% else %} + <h2>Search results:</h3> + {% endif %} + {% if object_list %} + {% if is_paginated %} + <p> + {% if page_obj.has_previous %} + <a href="?{% url_replace page=page_obj.previous_page_number %}">Previous</a> + {% endif %} + Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}. + {% if page_obj.has_next %} + <a href="?{% url_replace page=page_obj.next_page_number %}">Next</a> + {% endif %} + </p> + {% endif %} + <ul> + {% for object in object_list %} + {% include 'commentaries/commentary_header_li.html' with object=object %} + {% endfor %} + </ul> + {% else %} + <h3>No match found for your search query.</h3> + {% endif %} + </div> </div> -{% endif %} - {% endblock content %} diff --git a/commentaries/templates/commentaries/request_commentary.html b/commentaries/templates/commentaries/request_commentary.html index 5e2444256..99409292c 100644 --- a/commentaries/templates/commentaries/request_commentary.html +++ b/commentaries/templates/commentaries/request_commentary.html @@ -84,7 +84,7 @@ {% if errormessage %} <h3 style="color: red;">Error: {{ errormessage }}</h3> {% if existing_commentary %} - <ul>{{ existing_commentary.header_as_li }}</ul> + <ul>{% include 'commentaries/commentary_header_li.html' with object=existing_commentary %}</ul> {% endif %} <br/> {% endif %} -- GitLab