From ae474dbd76c825c401c476256b3998a8ff4e4f0e Mon Sep 17 00:00:00 2001
From: Jorran de Wit <jorrandewit@outlook.com>
Date: Wed, 3 Apr 2019 20:44:25 +0200
Subject: [PATCH] Base

---
 journals/models.py                          |  6 +++
 journals/templates/journals/issue_list.html | 42 +++++++++++++++++++++
 journals/urls/general.py                    | 11 ++++++
 journals/views.py                           | 26 ++++++++++++-
 4 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100644 journals/templates/journals/issue_list.html

diff --git a/journals/models.py b/journals/models.py
index 19f916963..17d9ce34f 100644
--- a/journals/models.py
+++ b/journals/models.py
@@ -125,6 +125,12 @@ class Journal(models.Model):
     def has_issues(self):
         return self.structure in (ISSUES_AND_VOLUMES, ISSUES_ONLY)
 
+    @property
+    def get_latest_issue(self):
+        if not self.has_issues:
+            return None
+        return Issue.obejcts....
+
     @property
     def has_volumes(self):
         return self.structure in (ISSUES_AND_VOLUMES)
diff --git a/journals/templates/journals/issue_list.html b/journals/templates/journals/issue_list.html
new file mode 100644
index 000000000..169d2838e
--- /dev/null
+++ b/journals/templates/journals/issue_list.html
@@ -0,0 +1,42 @@
+{% extends 'scipost/_personal_page_base.html' %}
+
+{% block pagetitle %}{{block.super}}: Issues Admin{% endblock pagetitle %}
+
+{% block breadcrumb_items %}
+    {{block.super}}
+    <span class="breadcrumb-item active">Issues Admin</span>
+{% endblock %}
+
+{% block content %}
+
+
+<div class="row">
+  <div class="col-12">
+    <h1 class="highlight">Issues Admin</h1>
+    <a href="javascript:;">Create a new Issue</a>
+    <br><br>
+
+    <h3>Journals with their latest Issue</h3>
+    <table class="table">
+      <thead>
+        <tr>
+          <th>Journal</th>
+          <th>Latest Issue</th>
+          <th>Has active Issue?</th>
+        </tr>
+      </thead>
+      {% for journal in journals %}
+        {% if journal.has_issues %}
+          <tr>
+            <td>{{ journal.get_name_display }}</td>
+            <td></td>
+            <td><i class="fa fa-exclamation-triangle text-warning"></i> No.</td>
+          </tr>
+        {% endif %}
+      {% endfor %}
+    </table>
+  </div>
+</div>
+
+
+{% endblock %}
diff --git a/journals/urls/general.py b/journals/urls/general.py
index 87b194828..e8082bd4a 100644
--- a/journals/urls/general.py
+++ b/journals/urls/general.py
@@ -103,6 +103,17 @@ urlpatterns = [
         journals_views.add_associated_grant,
         name='add_associated_grant'),
 
+    url(r'^admin/issues/$',
+        journals_views.IssuesAdminListView.as_view(),
+        name='admin_issue_list'),
+    url(r'^admin/issues/add$',
+        journals_views.IssuesAdminAddView.as_view(),
+        name='add_issue'),
+    url(r'^admin/issues/(?P<id>[0-9]+)/$',
+        journals_views.IssuesAdminUpdateView.as_view(),
+        name='update_issue'),
+
+
     # Metadata handling
     url(r'^admin/(?P<doi_label>{regex})/metadata/crossref/create$'.format(
             regex=PUBLICATION_DOI_REGEX),
diff --git a/journals/views.py b/journals/views.py
index 436a1ec1d..528695ede 100644
--- a/journals/views.py
+++ b/journals/views.py
@@ -24,7 +24,7 @@ from django.http import Http404, HttpResponse
 from django.utils import timezone
 from django.utils.decorators import method_decorator
 from django.views.generic.detail import DetailView
-from django.views.generic.edit import UpdateView
+from django.views.generic.edit import CreateView, UpdateView
 from django.views.generic.list import ListView
 from django.shortcuts import get_object_or_404, get_list_or_404, render, redirect
 
@@ -177,6 +177,30 @@ class IssuesView(DetailView):
     template_name = 'journals/journal_issues.html'
 
 
+class IssuesAdminListView(PermissionsMixin, ListView):
+    """
+    List all Issues in the database for the admin.
+    """
+    model = Issue
+    permission_required = 'scipost.can_manage_issues'
+
+
+class IssuesAdminAddView(PermissionsMixin, CreateView):
+    """
+    List all Issues in the database for the admin.
+    """
+    model = Issue
+    permission_required = 'scipost.can_manage_issues'
+
+
+class IssuesAdminUpdateView(PermissionsMixin, UpdateView):
+    """
+    List all Issues in the database for the admin.
+    """
+    model = Issue
+    permission_required = 'scipost.can_manage_issues'
+
+
 def redirect_to_about(request, doi_label):
     journal = get_object_or_404(Journal, doi_label=doi_label)
     return redirect(
-- 
GitLab