From ef1fc6690881b6753e775de09160d95772bdebb0 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Wed, 25 Sep 2019 14:49:39 +0200 Subject: [PATCH] Improve Colleges views: list, detail --- .../templates/colleges/college_detail.html | 75 +++++++++++++++ colleges/templates/colleges/colleges.html | 96 +++++++------------ colleges/templatetags/colleges_extras.py | 15 +++ colleges/urls.py | 5 + colleges/views.py | 29 ++++-- journals/context_processors.py | 2 +- journals/templates/journals/journals.html | 84 +++++++--------- journals/templatetags/journals_extras.py | 15 ++- scipost/constants.py | 33 +++++-- .../templates/scipost/_disciplines_table.html | 22 +++++ scipost/templates/scipost/navbar.html | 2 +- scipost/templatetags/scipost_extras.py | 8 +- 12 files changed, 258 insertions(+), 128 deletions(-) create mode 100644 colleges/templates/colleges/college_detail.html create mode 100644 scipost/templates/scipost/_disciplines_table.html diff --git a/colleges/templates/colleges/college_detail.html b/colleges/templates/colleges/college_detail.html new file mode 100644 index 000000000..1feebb19c --- /dev/null +++ b/colleges/templates/colleges/college_detail.html @@ -0,0 +1,75 @@ +{% extends 'colleges/base.html' %} + +{% load staticfiles %} +{% load scipost_extras %} +{% load colleges_extras %} +{% load add_get_parameters %} + +{% block breadcrumb_items %} + {{ block.super }} + <a href="{% url 'colleges:colleges' %}" class="breadcrumb-item">Colleges</a> + <span class="breadcrumb-item">Editorial College ({{ discipline|get_discipline_display }})</span> +{% endblock %} + +{% block pagetitle %}: Fellowships{% endblock pagetitle %} + +{% block content %} + + {% if perms.scipost.can_manage_college_composition %} + <div class="adminLinks"> + <h3>Links for users with permission <em>scipost.can_manage_college_composition</em>:</h3> + <ul> + <li><a href="{% url 'colleges:potential_fellowships' %}">Potential Fellowships</a></li> + <li><a href="{% url 'colleges:fellowships' %}">Fellowships</a></li> + </ul> + </div> + {% endif %} + + + <h2 class="highlight">Editorial College ({{ discipline|get_discipline_display }})</h2> + + <div class="row"> + <div class="col-12"> + <button class="btn btn-primary" data-toggle="toggle-show" data-target="#specializations-{{ discipline }}">Select by specialization</button> + <button class="btn btn-primary" style="display: none;" data-toggle="toggle-show" data-target="#specializations-{{ discipline }}">Show full list of Fellows in {{ discipline }}</button> + <div id="specializations-{{ discipline }}" class="card bg-white border-default all-specializations mt-2" style="display: none"> + <div class="card-body"> + <p><em class="text-muted mt-2">Hover to highlight or click to select</em></p> + + <div class="row"> + <div class="col-md-6"> + {% with total_count=object_list|length %} + {% for code in specializations %} + <div class="specialization" data-specialization="{{ code.0|lower }}">{{ code.0 }} - {{ code.1 }}</div> + {% if forloop.counter|is_modulo_one_half:total_count %} + </div> + <div class="col-md-6"> + {% endif %} + {% endfor %} + {% endwith %} + </div> + </div> + </div> + </div> + </div> + </div> + + <div class="row search-contributors" data-contributors="{{ discipline|lower }}"> + <div class="col-12"> + <div class="card-columns"> + {% for fellowship in object_list %} + <div class="card contributor mb-1"> + {% include 'scipost/_contributor_short.html' with fellowship=fellowship %} + </div> + {% endfor %} + </div> + </div> + </div> + + +{% endblock content %} + +{% block footer_script %} + {{ block.super }} + <script src="{% static 'colleges/colleges.js' %}"></script> +{% endblock %} diff --git a/colleges/templates/colleges/colleges.html b/colleges/templates/colleges/colleges.html index 1d50e2d6b..c47ae1d0c 100644 --- a/colleges/templates/colleges/colleges.html +++ b/colleges/templates/colleges/colleges.html @@ -2,6 +2,7 @@ {% load staticfiles %} {% load scipost_extras %} +{% load colleges_extras %} {% load add_get_parameters %} {% block breadcrumb_items %} @@ -42,67 +43,44 @@ </div> </div> - <div class="accordion" id="accordionEditorialColleges"> - - {% for discipline,fellowships in disciplines.items %} - <div class="card"> - <div class="card-header text-center" id="editorial_college_{{ discipline|lower }}"> - <h1> - {{ discipline }} - </h1> - <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapse_editorial_college_{{ discipline|lower }}" aria-expanded="false" aria-controls="collapse_editorial_college_{{ discipline|lower }}"> - <em><small>Click to expand/collapse</small></em> - </button> - </div> + <div class="row"> + <div class="col-1"></div> + <div class="col-10"> + <h4>On this page: you will find all Editorial Colleges we have assembled, listed by branch of knowledge/field of study.</h4> + <br> + {% include 'scipost/_disciplines_table.html' %} + <br> + <p> + Does your field not have a College yet? Help us to form one by + <a href="mailto:admin@scipost.org">sending us your suggestions</a> for potential Fellows. + </p> + </div> + </div> - <div id="collapse_editorial_college_{{ discipline|lower }}" class="collapse" aria-labelledby="editorial_college_{{ discipline|lower }}" data-parent="#accordionEditorialColleges"> - <div class="card-body"> - <div class="row"> - <div class="col-12"> - <button class="btn btn-primary" data-toggle="toggle-show" data-target="#specializations-{{ discipline|lower }}">Select by specialization</button> - <button class="btn btn-primary" style="display: none;" data-toggle="toggle-show" data-target="#specializations-{{ discipline|lower }}">Show full list of Fellows in {{ discipline }}</button> - <div id="specializations-{{ discipline|lower }}" class="card bg-white border-default all-specializations mt-2" style="display: none"> - <div class="card-body"> - <p><em class="text-muted mt-2">Hover to highlight or click to select</em></p> + <hr> - <div class="row"> - <div class="col-md-6"> - {% with total_count=fellowships.1|length %} - {% for code in fellowships.1 %} - <div class="specialization" data-specialization="{{ code.0|lower }}">{{ code.0 }} - {{ code.1 }}</div> - {% if forloop.counter|is_modulo_one_half:total_count %} - </div> - <div class="col-md-6"> - {% endif %} - {% endfor %} - {% endwith %} - </div> - </div> - </div> - </div> - </div> - </div> + {% for branch in scipost_disciplines %} + <h2 class="highlight" id="{{ branch.0|cut:' ' }}">{{ branch.0 }}</h2> + {% with object_list|fellowships_in_branch:branch.0 as fellowships_branch %} + {% if fellowships_branch|length > 0 %} + {% for discipline in branch.1 %} + {% with fellowships_branch|fellowships_in_discipline:discipline.0 as fellowships_disc %} + {% if fellowships_disc|length > 0 %} + <a href={% url 'colleges:college_detail' discipline=discipline.0 %}><button type="button" class="btn btn-primary">{{ discipline.1 }}</button></a> + {% endif %} + {% endwith %} + {% endfor %} + {% if not forloop.last %} + <hr> + {% endif %} + {% else %} + <p> + There are no Colleges yet in this branch of academia. + <strong>Help us to get started: nominate potential Fellows by <a href="mailto:admin@scipost.org">emailing us</a> with your suggestions!</strong> + </p> + {% endif %} + {% endwith %} + {% endfor %} - <div class="row search-contributors" data-contributors="{{ discipline|lower }}"> - <div class="col-12"> - <div class="card-columns"> - {% for fellowship in fellowships.0 %} - <div class="card contributor mb-1"> - {% include 'scipost/_contributor_short.html' with fellowship=fellowship %} - </div> - {% endfor %} - </div> - </div> - </div> - </div> - </div> - </div> - {% endfor %} - </div> {% endblock content %} - -{% block footer_script %} - {{ block.super }} - <script src="{% static 'colleges/colleges.js' %}"></script> -{% endblock %} diff --git a/colleges/templatetags/colleges_extras.py b/colleges/templatetags/colleges_extras.py index 3a9b26c02..21f42d8c4 100644 --- a/colleges/templatetags/colleges_extras.py +++ b/colleges/templatetags/colleges_extras.py @@ -18,11 +18,26 @@ from ..constants import ( from ..models import Fellowship from common.utils import hslColorWheel +from scipost.constants import SCIPOST_DISCIPLINES register = template.Library() +@register.filter(name='fellowships_in_branch') +def fellowships_in_branch(fellowships, branch_name): + matching_disciplines = () + for branch in SCIPOST_DISCIPLINES: + if branch[0] == branch_name: + matching_disciplines = [d[0] for d in branch[1]] + return fellowships.filter(contributor__profile__discipline__in=matching_disciplines) + + +@register.filter(name='fellowships_in_discipline') +def fellowships_in_discipline(fellowships, discipline): + return fellowships.filter(contributor__profile__discipline=discipline) + + @register.filter(name='potfelstatuscolor') def potfelstatuscolor(status): color = '#333333' diff --git a/colleges/urls.py b/colleges/urls.py index 9c542cbcf..83b89bbcc 100644 --- a/colleges/urls.py +++ b/colleges/urls.py @@ -17,6 +17,11 @@ urlpatterns = [ views.EditorialCollegesView.as_view(), name='colleges' ), + url( + r'^(?P<discipline>[a-zA-Z]+)/$', + views.EditorialCollegeDetailView.as_view(), + name='college_detail' + ), # Fellowships url( r'^fellowships/(?P<contributor_id>[0-9]+)/add/$', diff --git a/colleges/views.py b/colleges/views.py index cb4381951..2d3bd8ab2 100644 --- a/colleges/views.py +++ b/colleges/views.py @@ -29,7 +29,8 @@ from .forms import FellowshipForm, FellowshipRemoveSubmissionForm,\ PotentialFellowshipForm, PotentialFellowshipStatusForm, PotentialFellowshipEventForm from .models import Fellowship, PotentialFellowship, PotentialFellowshipEvent -from scipost.constants import SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS, subject_areas_raw_dict +from scipost.constants import SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS,\ + subject_areas_raw_dict, specializations_dict from scipost.mixins import PermissionsMixin, PaginationMixin, RequestViewMixin from scipost.models import Contributor @@ -41,17 +42,29 @@ class EditorialCollegesView(ListView): template_name = 'colleges/colleges.html' def get_queryset(self): - queryset = Fellowship.objects.none() + queryset = Fellowship.objects.active().regular() return queryset def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) - context['disciplines'] = {} - for discipline in SCIPOST_DISCIPLINES: - qs = Fellowship.objects.active().regular().filter( - contributor__profile__discipline=discipline[0]) - if qs: - context['disciplines'][discipline[1]] = (qs, subject_areas_raw_dict[discipline[1]]) + context['fellowships'] = Fellowship.objects.active().regular() + return context + + +class EditorialCollegeDetailView(ListView): + model = Fellowship + template_name = 'colleges/college_detail.html' + + def get_queryset(self): + queryset = Fellowship.objects.active().regular().filter( + contributor__profile__discipline=self.kwargs.get('discipline')) + return queryset + + def get_context_data(self, *args, **kwargs): + context = super().get_context_data(*args, **kwargs) + discipline = self.kwargs.get('discipline') + context['discipline'] = discipline + context['specializations'] = specializations_dict[discipline] return context diff --git a/journals/context_processors.py b/journals/context_processors.py index a1569fba3..813ff7114 100644 --- a/journals/context_processors.py +++ b/journals/context_processors.py @@ -8,6 +8,6 @@ from .models import Journal def journals_processor(request): """Append all Journals to the context of all views.""" return { - 'disciplines': SCIPOST_DISCIPLINES, + 'scipost_disciplines': SCIPOST_DISCIPLINES, 'journals': Journal.objects.order_by('name') } diff --git a/journals/templates/journals/journals.html b/journals/templates/journals/journals.html index 4525e290e..ba59086fa 100644 --- a/journals/templates/journals/journals.html +++ b/journals/templates/journals/journals.html @@ -31,28 +31,7 @@ <div class="col-10"> <h4>On this page: you will find all Journals we operate, listed by branch of knowledge/field of study.</h4> <br> - <table class="table table-bordered"> - <thead class="thead-dark"> - <tr> - <th>Branch</th> - <th>Fields</th> - </tr> - </thead> - <tbody> - {% for discipline in disciplines %} - <tr> - <td> - <a href="#{{ discipline.0|cut:' ' }}">{{ discipline.0 }}</a> - </td> - <td> - {% for subdiscipline in discipline.1 %} - {{ subdiscipline.1 }}{% if not forloop.last %}, {% endif %} - {% endfor %} - </td> - </tr> - {% endfor %} - </tbody> - </table> + {% include 'scipost/_disciplines_table.html' %} <br> <p>Does your field not have a Journal yet? Help us to form an Editorial College by <a href="mailto:admin@scipost.org">sending us your suggestions</a> for potential Fellows @@ -62,35 +41,44 @@ <hr> - {% for discipline in disciplines %} - <h2 class="highlight" id="{{ discipline.0|cut:' ' }}">{{ discipline.0 }}</h2> - {% for subdiscipline in discipline.1 %} - {% with journals|in_discipline:subdiscipline.0 as journals_subdisc %} - {% if journals_subdisc|length > 0 %} - <h3 class="highlight">{{ subdiscipline.1 }}</h3> - <div class="card-columns"> - {% for journal in journals_subdisc %} - {% if journal.active or perms.scipost.can_view_pool %} - <div class="card"> - <div class="card-header {{ journal.doi_label }}"> - <a href="{{ journal.get_absolute_url }}">{{ journal.name }}</a> - {% if journal.has_DOAJ_Seal %} - <a href="https://doaj.org" class="float-right"><img src="{% static 'scipost/images/DOAJ_Seal_logo_big.png' %}" alt="DOAJ Seal" width="20em"></a> - {% endif %} - </div> - <div class="card-body"> - {{ journal.blurb|automarkup }} - </div> + {% for branch in scipost_disciplines %} + <h2 class="highlight" id="{{ branch.0|cut:' ' }}">{{ branch.0 }}</h2> + {% with journals|journals_in_branch:branch.0 as journals_branch %} + {% if journals_branch|length > 0 %} + {% for discipline in branch.1 %} + {% with journals_branch|journals_in_discipline:discipline.0 as journals_disc %} + {% if journals_disc|length > 0 %} + <h3 class="highlight">{{ discipline.1 }}</h3> + <div class="card-columns"> + {% for journal in journals_disc %} + {% if journal.active or perms.scipost.can_view_pool %} + <div class="card"> + <div class="card-header {{ journal.doi_label }}"> + <a href="{{ journal.get_absolute_url }}">{{ journal.name }}</a> + {% if journal.has_DOAJ_Seal %} + <a href="https://doaj.org" class="float-right"><img src="{% static 'scipost/images/DOAJ_Seal_logo_big.png' %}" alt="DOAJ Seal" width="20em"></a> + {% endif %} + </div> + <div class="card-body"> + {{ journal.blurb|automarkup }} + </div> + </div> + {% endif %} + {% endfor %} </div> {% endif %} - {% endfor %} - </div> + {% endwith %} + {% endfor %} + {% if not forloop.last %} + <hr> {% endif %} - {% endwith %} - {% endfor %} - {% if not forloop.last %} - <hr> - {% endif %} + {% else %} + <p> + There are no Journals yet in this branch of academia. + <strong>Help us to get started: nominate potential Fellows by <a href="mailto:admin@scipost.org">emailing us</a> with your suggestions!</strong> + </p> + {% endif %} + {% endwith %} {% endfor %} diff --git a/journals/templatetags/journals_extras.py b/journals/templatetags/journals_extras.py index d045a8dc0..cabd7b588 100644 --- a/journals/templatetags/journals_extras.py +++ b/journals/templatetags/journals_extras.py @@ -5,12 +5,23 @@ __license__ = "AGPL v3" from django import template from journals.helpers import paper_nr_string +from scipost.constants import SCIPOST_DISCIPLINES + register = template.Library() -@register.filter(name='in_discipline') -def in_discipline(journals, discipline): +@register.filter(name='journals_in_branch') +def journals_in_branch(journals, branch_name): + matching_disciplines = () + for branch in SCIPOST_DISCIPLINES: + if branch[0] == branch_name: + matching_disciplines = [d[0] for d in branch[1]] + return journals.filter(discipline__in=matching_disciplines) + + +@register.filter(name='journals_in_discipline') +def journals_in_discipline(journals, discipline): return journals.filter(discipline=discipline) diff --git a/scipost/constants.py b/scipost/constants.py index 0500c71a3..2d8cf178d 100644 --- a/scipost/constants.py +++ b/scipost/constants.py @@ -14,7 +14,7 @@ DISCIPLINE_ASTRONOMY = 'astronomy' DISCIPLINE_ASTROPHYSICS = 'astrophysics' DISCIPLINE_BIOLOGY = 'biology' DISCIPLINE_CHEMISTRY = 'chemistry' -DISCIPLINE_EARTHSCIENCE = 'earthscience' 'Earth and Environmental Sciences' +DISCIPLINE_EARTHSCIENCE = 'earthscience' DISCIPLINE_ENGINEERING_MULTI = 'multidiscip-eng' DISCIPLINE_CIVILENGINEERING = 'civileng' @@ -28,11 +28,11 @@ DISCIPLINE_INDUSTRIALENGINEERING = 'industrialeng' DISCIPLINE_MEDICAL_MULTI = 'multidiscip-med' DISCIPLINE_MEDICINE = 'medicine' -DISCIPLINE_CLINICAL = 'clinical' 'Clinical Medicine' -DISCIPLINE_HEALTH = 'health' 'Health Sciences' +DISCIPLINE_CLINICAL = 'clinical' +DISCIPLINE_HEALTH = 'health' DISCIPLINE_AGRICULTURAL_MULTI = 'multidiscip-agri' -DISCIPLINE_AGRICULTURAL = 'agricultural' 'Agriculture, Forestry and Fisheries' +DISCIPLINE_AGRICULTURAL = 'agricultural' DISCIPLINE_VETERINARY = 'veterinary' DISCIPLINE_MULTI_SOCIAL = 'multidiscip-social' @@ -46,10 +46,10 @@ DISCIPLINE_PSYCHOLOGY = 'psychology' DISCIPLINE_SOCIOLOGY = 'sociology' DISCIPLINE_MULTI_HUMANITIES = 'multidiscip-hum' -DISCIPLINE_ART = 'art' 'Art (arts, history or arts, performing arts, music)' -DISCIPLINE_HISTORY = 'history' 'History and Archeology' -DISCIPLINE_LITERATURE = 'literature' 'Language and Literature' -DISCIPLINE_PHILOSOPHY = 'philosophy' 'Philosophy, Ethics and Religion' +DISCIPLINE_ART = 'art' +DISCIPLINE_HISTORY = 'history' +DISCIPLINE_LITERATURE = 'literature' +DISCIPLINE_PHILOSOPHY = 'philosophy' # This classification more or less follows the document @@ -132,6 +132,13 @@ SCIPOST_DISCIPLINES = ( ) ) +# Utility dict to translate the discipline db names to human-readable ones +# (this is needed because [Choice]ArrayField does not have get_FOO_display. +disciplines_dict = {} +for branch in SCIPOST_DISCIPLINES: + for disc in branch[1]: + disciplines_dict[disc[0]] = disc[1] + # The subject areas should use the long version of the discipline as first tuple item # for each element in the list (so 'Physics' and not 'physics', etc). @@ -259,6 +266,16 @@ subject_areas_dict = {} for k in subject_areas_raw_dict.keys(): subject_areas_dict.update(dict(subject_areas_raw_dict[k])) +# Other dictionary of dictionaries with discipline as key +# { 'physics': { 'Phys:AE': 'Atomic ...' } } +specializations_dict = {} +for a in SCIPOST_SUBJECT_AREAS: + # Match the specifier with the discipline db code + for branch in SCIPOST_DISCIPLINES: + for disc in branch[1]: + if disc[1] == a[0]: + specializations_dict[disc[0]] = a[1] + APPROACH_THEORETICAL = 'theoretical' APPROACH_EXPERIMENTAL = 'experimental' diff --git a/scipost/templates/scipost/_disciplines_table.html b/scipost/templates/scipost/_disciplines_table.html new file mode 100644 index 000000000..21377f7f2 --- /dev/null +++ b/scipost/templates/scipost/_disciplines_table.html @@ -0,0 +1,22 @@ +<table class="table table-bordered"> + <thead class="thead-dark"> + <tr> + <th>Branch</th> + <th>Fields</th> + </tr> + </thead> + <tbody> + {% for branch in scipost_disciplines %} + <tr> + <td> + <a href="#{{ branch.0|cut:' ' }}">{{ branch.0 }}</a> + </td> + <td> + {% for discipline in branch.1 %} + {{ discipline.1 }}{% if not forloop.last %}, {% endif %} + {% endfor %} + </td> + </tr> + {% endfor %} + </tbody> +</table> diff --git a/scipost/templates/scipost/navbar.html b/scipost/templates/scipost/navbar.html index e9b6e4e6b..f55281201 100644 --- a/scipost/templates/scipost/navbar.html +++ b/scipost/templates/scipost/navbar.html @@ -49,7 +49,7 @@ </div> <div class="col-md-8"> {% for subdiscipline in discipline.1 %} - {% with journals|in_discipline:subdiscipline.0 as journals_subdisc %} + {% with journals|journals_in_discipline:subdiscipline.0 as journals_subdisc %} {% if journals_subdisc|length > 0 %} <div class="row"> <div class="col-md-4"> diff --git a/scipost/templatetags/scipost_extras.py b/scipost/templatetags/scipost_extras.py index 498d239ba..f83023d22 100644 --- a/scipost/templatetags/scipost_extras.py +++ b/scipost/templatetags/scipost_extras.py @@ -5,7 +5,7 @@ __license__ = "AGPL v3" from django import template from django.contrib.contenttypes.models import ContentType -from ..constants import subject_areas_dict +from ..constants import disciplines_dict, subject_areas_dict from ..models import Contributor register = template.Library() @@ -70,6 +70,12 @@ def is_modulo_one_third(counter, total): return is_modulo(counter, total, 3) +@register.filter(name='get_discipline_display') +def get_discipline_display(discipline): + # Translate the discipline db codename to human-readable name + return disciplines_dict[discipline] + + @register.filter(name='get_specialization_code') def get_specialization_code(code): # Get the specialization code without the main subject identifier -- GitLab