From 57599f18d67755c7d94fb4d8d67808667e7fc820 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Tue, 23 Jan 2018 10:56:13 +0000
Subject: [PATCH] add django tables 2 and basic table layout

---
 opentech/apply/dashboard/tables.py                  | 11 +++++++++++
 .../dashboard/templates/dashboard/dashboard.html    | 13 ++-----------
 opentech/apply/dashboard/views.py                   |  7 +++++++
 opentech/settings/base.py                           |  1 +
 requirements.txt                                    |  1 +
 5 files changed, 22 insertions(+), 11 deletions(-)
 create mode 100644 opentech/apply/dashboard/tables.py

diff --git a/opentech/apply/dashboard/tables.py b/opentech/apply/dashboard/tables.py
new file mode 100644
index 000000000..0d568c685
--- /dev/null
+++ b/opentech/apply/dashboard/tables.py
@@ -0,0 +1,11 @@
+import django_tables2 as tables
+from opentech.apply.funds.models import ApplicationSubmission
+
+
+class DashboardTable(tables.Table):
+    submit_time = tables.DateColumn(verbose_name="Submitted")
+    page = tables.Column(verbose_name="Fund")
+
+    class Meta:
+        model = ApplicationSubmission
+        fields = ('title', 'page', 'submit_time')
diff --git a/opentech/apply/dashboard/templates/dashboard/dashboard.html b/opentech/apply/dashboard/templates/dashboard/dashboard.html
index d95e40df8..b78c4c5bd 100644
--- a/opentech/apply/dashboard/templates/dashboard/dashboard.html
+++ b/opentech/apply/dashboard/templates/dashboard/dashboard.html
@@ -1,17 +1,8 @@
 {% extends "base.html" %}
+{% load render_table from django_tables2 %}
 
 {% block content %}
 <h1>Recieved Content</h1>
 <h3>Track and explore recent submissions</h3>
-<table>
-{% for submission in applicationsubmission_list %}
-    <tr>
-        <td>
-            {{ submission.title }}
-        </td>
-    </tr>
-{% empty %}
-    There are no submissions to review.
-{% endfor %}
-</table>
+{% render_table object_list %}
 {% endblock %}
diff --git a/opentech/apply/dashboard/views.py b/opentech/apply/dashboard/views.py
index c303a7717..8a14705f4 100644
--- a/opentech/apply/dashboard/views.py
+++ b/opentech/apply/dashboard/views.py
@@ -2,7 +2,14 @@ from django.views.generic import ListView
 
 from opentech.apply.funds.models import ApplicationSubmission
 
+from .tables import DashboardTable
+
 
 class DashboardView(ListView):
     model = ApplicationSubmission
     template_name = 'dashboard/dashboard.html'
+
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context['object_list'] = DashboardTable(context['object_list'])
+        return context
diff --git a/opentech/settings/base.py b/opentech/settings/base.py
index 8ba4b2de0..7405abda9 100644
--- a/opentech/settings/base.py
+++ b/opentech/settings/base.py
@@ -56,6 +56,7 @@ INSTALLED_APPS = [
     'django_extensions',
     'captcha',
     'wagtailcaptcha',
+    'django_tables2',
 
     'django.contrib.admin',
     'django.contrib.auth',
diff --git a/requirements.txt b/requirements.txt
index 83d06ba2b..82b3f5cac 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,6 +13,7 @@ wagtail_factories==0.3.0
 flake8
 
 social_auth_app_django==2.1.0
+django-tables2=1.17.1
 
 # Production dependencies
 dj-database-url==0.4.1
-- 
GitLab