From f66fb3d67755683fa5bfbd5cdf176186c5191e72 Mon Sep 17 00:00:00 2001
From: Jorran de Wit <jorrandewit@outlook.com>
Date: Fri, 4 May 2018 21:45:17 +0200
Subject: [PATCH] Update About page

---
 journals/constants.py                |  3 +--
 scipost/models.py                    |  2 +-
 scipost/templates/scipost/about.html | 21 ++++++++--------
 scipost/views.py                     | 36 ++++++++++++----------------
 4 files changed, 27 insertions(+), 35 deletions(-)

diff --git a/journals/constants.py b/journals/constants.py
index c98733fee..529c204ef 100644
--- a/journals/constants.py
+++ b/journals/constants.py
@@ -85,8 +85,7 @@ CC_LICENSES = (
 CC_LICENSES_URI = (
     (CCBY4, 'https://creativecommons.org/licenses/by/4.0'),
     (CCBYSA4, 'https://creativecommons.org/licenses/by-sa/4.0'),
-    (CCBYNC4, 'https://creativecommons.org/licenses/by-nc/4.0'),
-    )
+    (CCBYNC4, 'https://creativecommons.org/licenses/by-nc/4.0'))
 
 
 ISSUES_AND_VOLUMES = 'IV'
diff --git a/scipost/models.py b/scipost/models.py
index d5bc608c4..b99afdeac 100644
--- a/scipost/models.py
+++ b/scipost/models.py
@@ -285,7 +285,7 @@ class PrecookedEmail(models.Model):
 ######################
 
 class EditorialCollege(models.Model):
-    '''A SciPost Editorial College for a specific discipline.'''
+    """A SciPost Editorial College for a specific discipline."""
     discipline = models.CharField(max_length=255, unique=True)
 
     def __str__(self):
diff --git a/scipost/templates/scipost/about.html b/scipost/templates/scipost/about.html
index 240f766f7..1840b0a4d 100644
--- a/scipost/templates/scipost/about.html
+++ b/scipost/templates/scipost/about.html
@@ -125,22 +125,22 @@
 
 <hr>
 
-{% for college, codes in object_list %}
-    <h2 class="highlight" id="editorial_college_{{ college|lower }}">Editorial College ({{ college }})</h2>
+{% for discipline,fellowships in disciplines.items %}
+{#{% for college, codes in object_list %}#}
+    <h2 class="highlight" id="editorial_college_{{ discipline|lower }}">Editorial College ({{ discipline }})</h2>
 
-    {% if codes %}
     <div class="row">
         <div class="col-12">
-            <a href="#editorial_college_{{ college|lower }}" class="mx-2" data-toggle="toggle-show" data-target="#specializations-{{college|lower}}">Show Fellows by specialization</a>
-            <a href="#editorial_college_{{ college|lower }}" class="mx-2" style="display: none;" data-toggle="toggle-show" data-target="#specializations-{{college|lower}}">Show full list of Fellows</a>
-            <div id="specializations-{{college|lower}}" class="card bg-white border-default all-specializations mt-2" style="display: none">
+            <a href="#editorial_college_{{ discipline|lower }}" class="mx-2" data-toggle="toggle-show" data-target="#specializations-{{discipline|lower}}">Show Fellows by specialization</a>
+            <a href="#editorial_college_{{ discipline|lower }}" class="mx-2" style="display: none;" data-toggle="toggle-show" data-target="#specializations-{{discipline|lower}}">Show full list of Fellows</a>
+            <div id="specializations-{{ discipline|lower }}" class="card bg-white border-default all-specializations mt-2" style="display: none">
                 <div class="card-body">
                     <p class="text-muted mt-2">Hover to highlight or click to select</p>
 
                     <div class="row">
                         <div class="col-md-6">
-                            {% with total_count=codes|length %}
-                                {% for code in codes %}
+                            {% 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>
@@ -154,12 +154,11 @@
             </div>
         </div>
     </div>
-    {% endif %}
 
-    <div class="row search-contributors" data-contributors="{{ college|lower }}">
+    <div class="row search-contributors" data-contributors="{{ discipline|lower }}">
         <div class="col-12">
             <div class="card-columns">
-                {% for fellowship in college.current_fellows %}
+                {% for fellowship in fellowships.0 %}
                     <div class="card bg-white contributor mb-1">
                         {% include 'scipost/_contributor_short.html' with contributor=fellowship.contributor %}
                     </div>
diff --git a/scipost/views.py b/scipost/views.py
index 915df08f3..9e4ee6cb7 100644
--- a/scipost/views.py
+++ b/scipost/views.py
@@ -30,7 +30,8 @@ from guardian.decorators import permission_required
 from haystack.generic_views import SearchView
 
 from .constants import (
-    SCIPOST_SUBJECT_AREAS, subject_areas_raw_dict, SciPost_from_addresses_dict, NORMAL_CONTRIBUTOR)
+    SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS, subject_areas_raw_dict,
+    SciPost_from_addresses_dict, NORMAL_CONTRIBUTOR)
 from .decorators import has_contributor, is_contributor_user
 from .models import (
     Contributor, UnavailabilityPeriod, AuthorshipClaim, EditorialCollege,
@@ -43,6 +44,7 @@ from .utils import Utils, EMAIL_FOOTER, SCIPOST_SUMMARY_FOOTER, SCIPOST_SUMMARY_
 
 from affiliations.forms import AffiliationsFormset
 from colleges.permissions import fellowship_or_admin_required
+from colleges.models import Fellowship
 from commentaries.models import Commentary
 from comments.models import Comment
 from invitations.constants import STATUS_REGISTERED
@@ -1060,34 +1062,26 @@ def Fellow_activity_overview(request):
 
 
 class AboutView(ListView):
+    """Basic information page with stream of current regular Fellows."""
+
     model = EditorialCollege
     template_name = 'scipost/about.html'
-    queryset = EditorialCollege.objects.prefetch_related(
-                Prefetch('fellowships',
-                         queryset=EditorialCollegeFellowship.objects.active().select_related(
-                            'contributor__user').order_by('contributor__user__last_name'),
-                         to_attr='current_fellows'))
+    queryset = Fellowship.objects.none()
 
     def get_context_data(self, *args, **kwargs):
+        """Save Fellowships per discipline to the context."""
         context = super().get_context_data(*args, **kwargs)
-        object_list = []
-        for college in context['object_list']:
-            try:
-                spec_list = subject_areas_raw_dict[str(college)]
-            except KeyError:
-                spec_list = None
-            object_list.append((
-                college,
-                spec_list,
-            ))
-        context['object_list'] = object_list
+        context['disciplines'] = {}
+        for discipline in SCIPOST_DISCIPLINES:
+            qs = Fellowship.objects.active().regular().filter(
+                contributor__discipline=discipline[0])
+            if qs:
+                context['disciplines'][discipline[1]] = (qs, subject_areas_raw_dict[discipline[1]])
         return context
 
 
-def csrf_failure(request, reason=""):
-    """
-    Custom CSRF Failure. Informing admins via email as well.
-    """
+def csrf_failure(request, reason=''):
+    """CSRF Failure page with an admin mailing action."""
     # Filter out privacy data
     post_data = {}
     for key in request.POST.keys():
-- 
GitLab