From 4281f8c08e93626dc9aef4da82dce113071d347a Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Fri, 22 Feb 2019 11:21:53 +0100
Subject: [PATCH] Add Sponsors Board (== list of Contacts) to dashboard

---
 .../migrations/0008_auto_20190222_1120.py     | 19 +++++++
 organizations/models.py                       |  3 ++
 .../templates/organizations/dashboard.html    | 50 +++++++++++++++++++
 organizations/views.py                        |  3 +-
 4 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 organizations/migrations/0008_auto_20190222_1120.py

diff --git a/organizations/migrations/0008_auto_20190222_1120.py b/organizations/migrations/0008_auto_20190222_1120.py
new file mode 100644
index 000000000..afbad95fb
--- /dev/null
+++ b/organizations/migrations/0008_auto_20190222_1120.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.4 on 2019-02-22 10:20
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organizations', '0007_auto_20190221_0553'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='contact',
+            options={'ordering': ['user__last_name', 'user__first_name']},
+        ),
+    ]
diff --git a/organizations/models.py b/organizations/models.py
index e2d94df09..96f4ea39f 100644
--- a/organizations/models.py
+++ b/organizations/models.py
@@ -240,6 +240,9 @@ class Contact(models.Model):
     activation_key = models.CharField(max_length=40, blank=True)
     key_expires = models.DateTimeField(default=timezone.now)
 
+    class Meta:
+        ordering = ['user__last_name', 'user__first_name']
+
     def __str__(self):
         return '%s %s, %s' % (self.get_title_display(), self.user.last_name, self.user.first_name)
 
diff --git a/organizations/templates/organizations/dashboard.html b/organizations/templates/organizations/dashboard.html
index 9f21e8896..d6e1b8538 100644
--- a/organizations/templates/organizations/dashboard.html
+++ b/organizations/templates/organizations/dashboard.html
@@ -36,6 +36,9 @@ $(document).ready(function($) {
 	  <li class="nav-item btn btn-outline-secondary">
 	    <a href="#subsidies" class="nav-link" data-toggle="tab">Subsidies from your Orgs</a>
 	  </li>
+	  <li class="nav-item btn btn-outline-secondary">
+	    <a href="#board" class="nav-link" data-toggle="tab">Sponsors Board</a>
+	  </li>
 	</ul>
       </div>
     </div>
@@ -145,6 +148,53 @@ $(document).ready(function($) {
     </div>
   </div>
 
+  <div class="tab-pane" id="board" role="tabpanel">
+    <div class="row">
+      <div class="col-12">
+	<h2 class="highlight">Sponsors Board</h2>
+      </div>
+    </div>
+    <div class="row">
+      <div class="col-12">
+	<p>The Sponsors Board is composed of all registered Organization Contacts.</p>
+
+        <h3>Active Contacts</h3>
+	<table class="table">
+	  <thead class="thead-default">
+	    <tr>
+	      <th>Name</th>
+	      <th>Organization(s) / role(s)</th>
+	      {% if perms.scipost.can_manage_organizations %}
+	      <th>Account<br/>active?</th>
+	      {% endif %}
+	    </tr>
+	  </thead>
+	  <tbody>
+	    {% for contact in contacts %}
+	    <tr>
+	      <td>{{ contact }}</td>
+	      <td>
+		<ul class="list-group list-group-flush">
+		  {% for role in contact.roles.all %}
+		  <li class="list-group-item">{{ role.organization }} / {{ role.get_kind_display }}</li>
+		  {% empty %}
+		  <li class="list-group-item">No Organization found</li>
+		  {% endfor %}
+		</ul>
+	      </td>
+	      {% if perms.scipost.can_manage_organizations %}
+	      <td>{% if contact.user.is_active %}<i class="fa fa-check-circle text-success"></i>{% else %}<i class="fa fa-times-circle text-danger"></i>{% endif %}</td>
+	      {% endif %}
+	    </tr>
+	    {% empty %}
+	    <tr><td>No contact found</td></tr>
+	    {% endfor %}
+	  </tbody>
+	</table>
+      </div>
+    </div>
+  </div>
+
 </div>
 
 {% endblock content %}
diff --git a/organizations/views.py b/organizations/views.py
index d0e7e507d..e2412aa62 100644
--- a/organizations/views.py
+++ b/organizations/views.py
@@ -232,7 +232,8 @@ def dashboard(request):
         raise PermissionDenied
 
     context = {
-        'own_roles': request.user.org_contact.roles.all()
+        'own_roles': request.user.org_contact.roles.all(),
+        'contacts': Contact.objects.all()
     }
 
     return render(request, 'organizations/dashboard.html', context)
-- 
GitLab