SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 61753593 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Merge branch 'commentaries/browse' into development

parents 887cd1ec d7fa5ce5
No related branches found
No related tags found
No related merge requests found
......@@ -214,13 +214,13 @@ class VetCommentaryForm(forms.Form):
class CommentarySearchForm(forms.Form):
"""Search for Commentary specified by user"""
pub_author = forms.CharField(max_length=100, required=False, label="Author(s)")
pub_title_keyword = forms.CharField(max_length=100, required=False, label="Title")
pub_abstract_keyword = forms.CharField(max_length=1000, required=False, label="Abstract")
author = forms.CharField(max_length=100, required=False, label="Author(s)")
title = forms.CharField(max_length=100, required=False, label="Title")
abstract = forms.CharField(max_length=1000, required=False, label="Abstract")
def search_results(self):
"""Return all Commentary objects according to search"""
return Commentary.objects.vetted(
pub_title__icontains=self.cleaned_data['pub_title_keyword'],
pub_abstract__icontains=self.cleaned_data['pub_abstract_keyword'],
author_list__icontains=self.cleaned_data['pub_author']).order_by('-pub_date')
pub_title__icontains=self.cleaned_data['title'],
pub_abstract__icontains=self.cleaned_data['abstract'],
author_list__icontains=self.cleaned_data['author']).order_by('-pub_date')
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
......
<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>
{% 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 %}
......@@ -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 %}
......
......@@ -5,21 +5,28 @@ from . import views
urlpatterns = [
# Commentaries
url(r'^$', views.commentaries, name='commentaries'),
url(r'^browse/(?P<discipline>[a-z]+)/(?P<nrweeksback>[0-9]+)/$', views.browse, name='browse'),
url(r'^$', views.CommentaryListView.as_view(), name='commentaries'),
url(r'^browse/(?P<discipline>[a-z]+)/(?P<nrweeksback>[0-9]+)/$',
views.CommentaryListView.as_view(), name='browse'),
url(r'^howto$', TemplateView.as_view(template_name='commentaries/howto.html'), name='howto'),
# Match a DOI-based link:
url(r'^(?P<arxiv_or_DOI_string>10.[0-9]{4,9}/[-._;()/:a-zA-Z0-9]+)/$', views.commentary_detail, name='commentary'),
url(r'^(?P<arxiv_or_DOI_string>10.[0-9]{4,9}/[-._;()/:a-zA-Z0-9]+)/$',
views.commentary_detail, name='commentary'),
# Match an arxiv-based link:
# new style identifiers:
url(r'^(?P<arxiv_or_DOI_string>arXiv:[0-9]{4,}.[0-9]{5,}(v[0-9]+)?)/$', views.commentary_detail, name='commentary'),
url(r'^(?P<arxiv_or_DOI_string>arXiv:[0-9]{4,}.[0-9]{5,}(v[0-9]+)?)/$',
views.commentary_detail, name='commentary'),
# old style identifiers:
url(r'^(?P<arxiv_or_DOI_string>arXiv:[a-z-]+/[0-9]{7,}(v[0-9]+)?)/$', views.commentary_detail, name='commentary'),
url(r'^(?P<arxiv_or_DOI_string>arXiv:[a-z-]+/[0-9]{7,}(v[0-9]+)?)/$',
views.commentary_detail, name='commentary'),
url(r'^request_commentary$', views.RequestCommentary.as_view(), name='request_commentary'),
url(r'^prefill_using_DOI$', views.prefill_using_DOI, name='prefill_using_DOI'),
url(r'^prefill_using_identifier$', views.PrefillUsingIdentifierView.as_view(), name='prefill_using_identifier'),
url(r'^vet_commentary_requests$', views.vet_commentary_requests, name='vet_commentary_requests'),
url(r'^vet_commentary_request_ack/(?P<commentary_id>[0-9]+)$', views.vet_commentary_request_ack, name='vet_commentary_request_ack'),
url(r'^prefill_using_identifier$', views.PrefillUsingIdentifierView.as_view(),
name='prefill_using_identifier'),
url(r'^vet_commentary_requests$', views.vet_commentary_requests,
name='vet_commentary_requests'),
url(r'^vet_commentary_request_ack/(?P<commentary_id>[0-9]+)$',
views.vet_commentary_request_ack, name='vet_commentary_request_ack'),
]
import datetime
import feedparser
import re
import requests
from django.utils import timezone
from django.shortcuts import get_object_or_404, render
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
......@@ -13,6 +10,7 @@ from django.core.urlresolvers import reverse, reverse_lazy
from django.shortcuts import redirect
from django.template.loader import render_to_string
from django.views.generic.edit import CreateView, FormView
from django.views.generic.list import ListView
from django.utils.decorators import method_decorator
from .models import Commentary
......@@ -39,7 +37,7 @@ class RequestCommentaryMixin(object):
kwargs['request_commentary_form'] = RequestCommentaryForm()
context = super(RequestCommentaryMixin, self).get_context_data(**kwargs)
context['existing_commentary'] = None # context['request_commentary_form'].get_existing_commentary()
context['existing_commentary'] = None
context['doiform'] = DOIToQueryForm()
context['identifierform'] = IdentifierToQueryForm()
return context
......@@ -267,33 +265,37 @@ def vet_commentary_request_ack(request, commentary_id):
return render(request, 'scipost/acknowledgement.html', context)
def commentaries(request):
"""List and search all commentaries"""
form = CommentarySearchForm(request.POST or None)
if form.is_valid() and form.has_changed():
commentary_search_list = form.search_results()
else:
commentary_search_list = []
comment_recent_list = Comment.objects.filter(status='1').order_by('-date_submitted')[:10]
commentary_recent_list = Commentary.objects.vetted().order_by('-latest_activity')[:10]
context = {
'form': form, 'commentary_search_list': commentary_search_list,
'comment_recent_list': comment_recent_list,
'commentary_recent_list': commentary_recent_list}
return render(request, 'commentaries/commentaries.html', context)
def browse(request, discipline, nrweeksback):
"""List all commentaries for discipline and period"""
commentary_browse_list = Commentary.objects.vetted(
discipline=discipline,
latest_activity__gte=timezone.now() + datetime.timedelta(weeks=-int(nrweeksback)))
context = {
'form': CommentarySearchForm(),
'discipline': discipline, 'nrweeksback': nrweeksback,
'commentary_browse_list': commentary_browse_list}
return render(request, 'commentaries/commentaries.html', context)
class CommentaryListView(ListView):
model = Commentary
form = CommentarySearchForm
paginate_by = 10
def get_queryset(self):
'''Perform search form here already to get the right pagination numbers.'''
self.form = self.form(self.request.GET)
if self.form.is_valid() and self.form.has_changed():
return self.form.search_results()
return self.model.objects.vetted().order_by('-latest_activity')
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
# Get newest comments
context['comment_list'] = Comment.objects.vetted().order_by('-date_submitted')[:10]
# Form into the context!
context['form'] = self.form
# To customize display in the template
if 'discipline' in self.kwargs:
context['discipline'] = self.kwargs['discipline']
context['nrweeksback'] = self.kwargs['nrweeksback']
context['browse'] = True
elif not any(self.request.GET[field] for field in self.request.GET):
context['recent'] = True
return context
def commentary_detail(request, arxiv_or_DOI_string):
......
from django.db import models
class CommentManager(models.Manager):
def vetted(self):
return self.filter(status__gte=1)
from django import template
from urllib.parse import urlencode
register = template.Library()
@register.simple_tag(takes_context=True)
def url_replace(context, **kwargs):
query = context['request'].GET.dict()
query.update(kwargs)
return urlencode(query)
......@@ -2,6 +2,7 @@
{% load bootstrap %}
{% load submissions_extras %}
{% load request_filters %}
{% block pagetitle %}: Submissions{% endblock pagetitle %}
......
......@@ -79,9 +79,3 @@ def required_actions(submission):
todo.append('The Report from %s has been delivered but is not yet vetted. '
'Please vet it.' % report.author)
return todo
@register.simple_tag(takes_context=True)
def url_replace(context, **kwargs):
query = context['request'].GET.dict()
query.update(kwargs)
return urlencode(query)
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