Start to reorganize views a little.
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 5 Jun 2020 22:24:37 +0000 (00:24 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 5 Jun 2020 22:24:37 +0000 (00:24 +0200)
20 files changed:
requirements.txt
src/archive/constants.py
src/archive/templates/archive/audiobook_list.html [new file with mode: 0644]
src/archive/templates/archive/base.html
src/archive/templates/archive/book.html
src/archive/templates/archive/file_managed.html
src/archive/templates/archive/file_new.html
src/archive/templates/archive/file_unmanaged.html
src/archive/templates/archive/list.html
src/archive/templates/archive/list_new.html
src/archive/templates/archive/list_published.html [deleted file]
src/archive/templates/archive/list_publishing.html
src/archive/templates/archive/list_unmanaged.html
src/archive/templates/archive/list_unpublished.html [deleted file]
src/archive/templates/archive/status.html [new file with mode: 0644]
src/archive/templates/pagination/pagination.html [new file with mode: 0644]
src/archive/templatetags/tags.py
src/archive/urls.py
src/archive/views.py
src/audiobooks/settings.py

index fe95850..c355845 100644 (file)
@@ -4,6 +4,7 @@ Django==3.0.6
 django-cas-ng==4.1.1
 django-bootstrap4==1.1.1
 django-pglocks==1.0.4
+fnp-django-pagination==2.2.4
 
 celery[redis]==4.4.2
 
index 3493e00..a5527ec 100644 (file)
@@ -1,8 +1,9 @@
 from django.utils.translation import gettext_lazy as _
 
+
 class status:
-    QUEUED = 1
-    WAITING = 10
+    WAITING = 1
+    QUEUED = 10
     ENCODING = 20
     TAGGING = 30
     CONVERTING_AUDIO = 40
@@ -14,8 +15,8 @@ class status:
     SETTING_THUMBNAIL = 110
 
     choices = [
-        (QUEUED, _('Queued')),
         (WAITING, _('Waiting')),
+        (QUEUED, _("Queued")),
         (ENCODING, _('Encoding')),
         (TAGGING, _('Tagging')),
         (CONVERTING_AUDIO, _('Converting audio')),
diff --git a/src/archive/templates/archive/audiobook_list.html b/src/archive/templates/archive/audiobook_list.html
new file mode 100644 (file)
index 0000000..1521b42
--- /dev/null
@@ -0,0 +1,73 @@
+{% extends "archive/list.html" %}
+{% load i18n %}
+{% load pagination_tags %}
+
+
+{% block menu-active-audiobooks %}active{% endblock %}
+
+
+{% block file-list-title %}
+  {% trans "Audiobooks" %}
+{% endblock %}
+
+
+{% block file-list-info %}
+{% endblock %}
+
+{% block file-list-wrapper %}
+  {% autopaginate object_list 50 %}
+  {{ block.super }}
+  {% paginate %}
+{% endblock %}
+
+
+{% block file-list %}
+  <thead>
+    <tr>
+      <th>Slug</th>
+      <th>{% trans "Title" %}</th>
+      <th>{% trans "YouTube volume" %}</th>
+      <th>MP3</th>
+      <th>Ogg</th>
+      <th>YouTube</th>
+    </tr>
+  </thead>
+  {% for audiobook in object_list %}
+    <tr>
+      <td>
+        {% if audiobook.slug %}
+          <a href="{% url "book" audiobook.slug %}">{{ audiobook.slug }}</a>
+        {% endif %}
+        <td>
+          <a href='{% url "file" audiobook.id %}'>{{ audiobook }}</a>
+        </td>
+        <td>
+          {{ audiobook.youtube_volume }}
+        </td>
+        <td>
+          {% if audiobook.mp3_status %}
+            <span class="badge badge-info">
+              MP3:
+              {{ audiobook.get_mp3_status_display }}
+            </span>
+          {% endif %}
+        </td>
+        <td>
+          {% if audiobooks.ogg_status_display %}
+            <span class="badge badge-info">
+              Ogg:
+              {{ audiobook.get_ogg_status_display }}
+            </span>
+          {% endif %}
+        </td>
+        <td>
+          {% if audiobooks.youtube_status %}
+            <span class="badge badge-info">
+              YT:
+              {{ audiobook.get_youtube_status_display }}
+            </span>
+          {% endif %}
+        </td>
+    </tr>
+  {% endfor %}
+{% endblock %}
index 9eeaf8c..f7e5ad7 100644 (file)
@@ -3,11 +3,10 @@
 
 {% block repo-zones-nav %}
   <ul class="nav nav-pills">
-    <li class="nav-item"><a class="nav-link{% if division == "new" %} active{% endif %}" href="{% url 'list_new' %}">{% trans "New" %}</a></li>
-    <li class="nav-item"><a class="nav-link{% if division == "unpublished" %} active{% endif %}" href="{% url 'list_unpublished' %}">{% trans "Unpublished" %}</a></li>
-    <li class="nav-item"><a class="nav-link{% if division == "publishing" %} active{% endif %}" href="{% url 'list_publishing' %}">{% trans "Publishing" %}</a></li>
-    <li class="nav-item"><a class="nav-link{% if division == "published" %} active{% endif %}" href="{% url 'list_published' %}">{% trans "Published" %}</a></li>
-    <li class="nav-item"><a class="nav-link{% if division == "unmanaged" %} active{% endif %}" href="{% url 'list_unmanaged' %}">{% trans "Archive" %}</a></li>
+    <li class="nav-item"><a class="nav-link {% block menu-active-audiobooks %}{% endblock %}" href="{% url "list_managed" %}">{% trans "Audiobooks" %}</a></li>
+    <li class="nav-item"><a class="nav-link {% block menu-active-publishing %}{% endblock %}" href="{% url 'list_publishing' %}">{% trans "Publishing" %}</a></li>
+    <li class="nav-item"><a class="nav-link {% block menu-active-new %}{% endblock %}" href="{% url 'list_new' %}">{% trans "New" %}</a></li>
+    <li class="nav-item"><a class="nav-link {% block menu-active-unmanaged %}{% endblock %}" href="{% url 'list_unmanaged' %}">{% trans "Archive" %}</a></li>
   </ul>
 
   <ul class="nav">
index fac3700..b3ead74 100644 (file)
@@ -1,28 +1,70 @@
 {% extends "archive/base.html" %}
+{% load i18n %}
+{% load tags %}
+
+
+{% block menu-active-audiobooks %}active{% endblock %}
+
 
 {% block content %}
   <div class="card mt-4">
     <div class="card-header">
-      <h2>Audiobooki</h2>
+      <h2>{{ object_list.0.book.title }}</h2>
     </div>
     <div class="card-body">
       <table class="table">
         <thead>
           <tr>
-            <th>?x</th>
+            <th>{% trans "Index" %}</th>
+            <th>{% trans "Title" %}</th>
+            <th>MP3</th>
+            <th>Ogg</th>
+            <th colspan="3">YouTube</th>
           </tr>
         </thead>
         <tbody>
-          {% for audiobook in object_list %}
-            <tr>
-              <td>{{ audiobook.index }}</td>
-              <td>
-                <a href="{% url 'file' audiobook.id %}">
-                  {{ audiobook.title }}
-                </a>
-              </td>
-            </tr>
-          {% endfor %}
+          {% with volumes=object_list.0.youtube_volume_count %}
+            {% for audiobook in object_list %}
+              <tr>
+                <td>{{ audiobook.index }}</td>
+                <td>
+                  <a href="{% url 'file' audiobook.id %}">
+                    {% if audiobook.part_name %}
+                      {{ audiobook.part_name }}
+                    {% else %}
+                      <em class="text-warning" title="ddd">
+                        ({{ audiobook }})
+                      </em>
+                      {% endif %}
+                  </a>
+                </td>
+                <td>{% status audiobook "mp3" %}</td>
+                <td>{% status audiobook "ogg" %}</td>
+                {% ifchanged audiobook.youtube_volume_index %}
+                  <td>
+                    {{ audiobook.youtube_volume_index }}/{{ volumes }}
+                  </td>
+                  <td>
+                    {{ audiobook.youtube_volume }}
+                  </td>
+                  <td>
+                    {% status audiobook "youtube" %}
+                  </td>
+                {% else  %}
+                  <td>
+                    –
+                  </td>
+                  <td>
+                    <span class="text-secondary">
+                      {{ audiobook.youtube_volume }}
+                    </span>
+                  </td>
+                  <td>
+                  </td>
+                {% endifchanged %}
+              </tr>
+            {% endfor %}
+          {% endwith %}
         </tbody>
       </table>
     </div>
index f08f951..ecb6292 100644 (file)
@@ -3,8 +3,11 @@
 {% load tags %}
 {% load bootstrap4 %}
 
-{% block content %}
 
+{% block menu-active-audiobooks %}active{% endblock %}
+
+
+{% block content %}
 
 
 {% for alert in alerts %}
index 9dc17d4..713525d 100644 (file)
@@ -1,6 +1,10 @@
 {% extends "archive/base.html" %}
 {% load i18n tags bootstrap4 %}
 
+
+{% block menu-active-new %}active{% endblock %}
+
+
 {% block content %}
 
 <div class="card mt-4">
index a05d556..742b280 100644 (file)
@@ -2,6 +2,10 @@
 {% load i18n %}
 {% load tags %}
 
+
+{% block menu-active-unmanaged %}active{% endblock %}
+
+
 {% block messages %}
     {% if err_exists %}
         <p>{% trans "File with same name already exists!" %}</p>
index 9d53422..7bb1515 100644 (file)
@@ -13,9 +13,9 @@
        {% block file-list-info %}{% endblock %}
     </div>
     {% block file-list-wrapper %}
-    <table class="table">
-      {% block file-list %}{% endblock %}
-    </table>
+      <table class="table">
+        {% block file-list %}{% endblock %}
+      </table>
     {% endblock %}
   </div>
 </div>
index 5e804ca..b7ca11d 100644 (file)
@@ -2,6 +2,10 @@
 {% load i18n %}
 
 
+{% block menu-active-new %}active{% endblock %}
+
+
+
 {% block file-list-title %}
     {% trans "New audiobooks" %}
 {% endblock %}
diff --git a/src/archive/templates/archive/list_published.html b/src/archive/templates/archive/list_published.html
deleted file mode 100644 (file)
index 04396f6..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-{% extends "archive/list.html" %}
-{% load i18n %}
-
-
-{% block file-list-title %}
-    {% trans "Published audiobooks" %}
-{% endblock %}
-
-
-{% block file-list-info %}
-{% endblock %}
-
-
-{% block file-list %}
-  {% for file in objects %}
-    <tr>
-      <td>
-        <a href='{% url "file" file.id %}'>{{ file }}</a>
-      </td>
-    </tr>
-  {% endfor %}
-{% endblock %}
index 83d631d..ad13504 100644 (file)
@@ -2,6 +2,9 @@
 {% load i18n %}
 
 
+{% block menu-active-publishing %}active{% endblock %}
+
+
 {% block file-list-title %}
     {% trans "Audiobooks being published" %}
 {% endblock %}
index 7ca92a1..599de32 100644 (file)
@@ -1,6 +1,10 @@
 {% extends "archive/list.html" %}
 {% load i18n %}
 
+
+{% block menu-active-unmanaged %}active{% endblock %}
+
+
 {% block file-list-title %}
     {% trans "Unmanaged archive" %}
 {% endblock %}
diff --git a/src/archive/templates/archive/list_unpublished.html b/src/archive/templates/archive/list_unpublished.html
deleted file mode 100644 (file)
index d51b66b..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-{% extends "archive/list.html" %}
-{% load i18n %}
-
-
-{% block file-list-title %}
-    {% trans "Unpublished audiobooks" %}
-{% endblock %}
-
-
-{% block file-list-info %}
-{% endblock %}
-
-
-{% block file-list %}
-  {% for file in objects %}
-    <tr>
-      <td>
-        <a href='{% url "file" file.id %}'>{{ file }}</a>
-      </td>
-      <td>
-        {% if file.mp3_published %}
-          <span class="text-success" title="{{ file.mp3_published }}">MP3</span>
-        {% else %}
-          {% if file.mp3_status %}
-            <span class="text-warning" title="{{ file.get_mp3_status_display }}">MP3</span>
-          {% endif %}
-            {% endif %}
-      </td>
-      <td>
-        {% if file.ogg_published %}
-          <span class="text-success" title="{{ file.ogg_published }}">Ogg</span>
-        {% else %}
-          {% if file.ogg_status %}
-            <span class="text-warning" title="{{ file.get_ogg_status_display }}">Ogg</span>
-          {% endif %}
-        {% endif %}
-      </td>
-    </tr>
-  {% endfor %}
-{% endblock %}
diff --git a/src/archive/templates/archive/status.html b/src/archive/templates/archive/status.html
new file mode 100644 (file)
index 0000000..2e8aa3b
--- /dev/null
@@ -0,0 +1,21 @@
+{% load i18n %}
+
+{% if published %}
+  {% if link %}
+    <a href="{{ link }}" target="_blank">
+  {% endif %}
+  <span class="badge badge-success" title="{{ format }}: {% trans "Published at" %} {{ published }} %}">
+    {% trans "OK" %}
+  </span>
+  {% if link %}
+    </a>
+  {% endif %}
+{% elif status %}
+  <span class="badge badge-info">
+    {{ status }}
+  </span>
+{% else %}
+  <span class="badge badge-secondary">
+   ––
+  </span>
+{% endif %}
diff --git a/src/archive/templates/pagination/pagination.html b/src/archive/templates/pagination/pagination.html
new file mode 100644 (file)
index 0000000..6aa12ad
--- /dev/null
@@ -0,0 +1,53 @@
+{% if is_paginated %}
+{% load i18n %}
+<nav aria-label="{% trans 'Pagination' %}" class="mt-4">
+  <ul class="pagination justify-content-center">
+    {% if page_obj.has_previous %}
+      <li class="page-item">
+        <a href="?page={{ page_obj.previous_page_number }}{{ getvars }}{{ hashtag }}" class="page-link">
+          {% trans "previous" %}
+        </a>
+      </li>
+    {% else %}
+      <li class="page-item disabled">
+        <span class="page-link">
+          {% trans "previous" %}
+        </span>
+      </li>
+    {% endif %}
+
+      {% for page in pages %}
+      {% if page %}
+      {% if page == page_obj.number %}
+    <li class="page-item active">
+      <span class="page-link">
+        {{ page }}
+      </span>
+    </li>
+    {% else %}
+    <li class="page-item">
+      <a href="?page={{ page }}{{ getvars }}{{ hashtag }}" class="page-link">
+        {{ page }}
+        </a>
+    </li>
+    {% endif %}
+    {% endif %}
+    {% endfor %}
+
+    {% if page_obj.has_next %}
+      <li class="page-item">
+        <a href="?page={{ page_obj.next_page_number }}{{ getvars }}{{ hashtag }}" class="page-link">
+          {% trans "next" %}
+        </a>
+      </li>
+    {% else %}
+      <li class="page-item disabled">
+        <span class="page-link">
+          {% trans "next" %}
+        </span>
+      </li>
+    {% endif %}
+  </ul>
+</nav>
+
+{% endif %}
index 8e208a6..c3dfa23 100755 (executable)
@@ -2,6 +2,7 @@ from django import template
 
 register = template.Library()
 
+
 @register.inclusion_tag('archive/tags/multiple_tags_table.html')
 def multiple_tags_table(tags, table=True):
     new_tags = {}
@@ -19,3 +20,17 @@ def tags_table(tags, table=True):
     if tags is None:
         tags = {}
     return locals()
+
+
+@register.inclusion_tag("archive/status.html")
+def status(audiobook, format):
+    if format == "youtube" and audiobook.youtube_id:
+        link = f"https://youtu.be/{audiobook.youtube_id}"
+    else:
+        link = None
+    return {
+        "published": getattr(audiobook, f"{format}_published"),
+        "status": getattr(audiobook, f"get_{format}_status_display")(),
+        "format": format,
+        "link": link,
+    }
index da1873c..4743227 100644 (file)
@@ -4,15 +4,11 @@ from django.views.generic import RedirectView
 from . import views
 
 urlpatterns = [
-    url(r'^$', RedirectView.as_view(url='new/')),
-
+    path("", views.AudiobookList.as_view(), name="list_managed"),
     url(r'^new/$', views.list_new, name="list_new"),
     url(r'^new/(.+)/$', views.file_new, name="file_new"),
     url(r'^move_to_archive/(.+)/$', views.move_to_archive, name="move_to_archive"),
-
-    url(r'^unpublished/$', views.list_unpublished, name="list_unpublished"),
     url(r'^publishing/$', views.list_publishing, name="list_publishing"),
-    url(r'^published/$', views.list_published, name="list_published"),
     path('book/<slug:slug>/', views.BookView.as_view(), name="book"),
     url(r'^file/(\d+)/$', views.file_managed, name="file"),
     url(r'^publish/(\d+)/$', views.publish, name="publish"),
@@ -21,7 +17,6 @@ urlpatterns = [
     url(r'^download/(\d+)\.(mp3|ogg|mkv)$', views.download, name="download"),
     url(r'^cancel/(\d+)/$', views.cancel_publishing, name="cancel_publishing"),
     url(r'^remove_to_archive/(\d+)/$', views.remove_to_archive, name="remove_to_archive"),
-
     url(r'^unmanaged/$', views.list_unmanaged, name="list_unmanaged"),
     url(r'^unmanaged/(.+)/$', views.file_unmanaged, name="file_unmanaged"),
     url(r'^move_to_new/(.+)/$', views.move_to_new, name="move_to_new"),
index 42acffc..f1b1c1b 100644 (file)
@@ -23,8 +23,6 @@ from archive.utils import all_files
 
 
 def list_new(request):
-    division = 'new'
-
     path = settings.NEW_PATH
     objects = sorted(all_files(path))
     return render(request, "archive/list_new.html", locals())
@@ -32,8 +30,6 @@ def list_new(request):
 
 @permission_required('archive.change_audiobook')
 def file_new(request, filename):
-    division = 'new'
-
     filepath = filename
     root_filepath = os.path.join(settings.NEW_PATH, filename)
     if request.POST:
@@ -212,16 +208,7 @@ def download(request, aid, which="source"):
     return response
 
 
-def list_unpublished(request):
-    division = 'unpublished'
-
-    objects = models.Audiobook.objects.filter(Q(mp3_published=None) | Q(ogg_published=None))
-    return render(request, "archive/list_unpublished.html", locals())
-
-
 def list_publishing(request):
-    division = 'publishing'
-
     objects = models.Audiobook.objects.exclude(
         mp3_status=None, ogg_status=None, youtube_status=None
     ).order_by("youtube_queued", "title")
@@ -241,11 +228,8 @@ def list_publishing(request):
     return render(request, "archive/list_publishing.html", locals())
 
 
-def list_published(request):
-    division = 'published'
-
-    objects = models.Audiobook.objects.exclude(Q(mp3_published=None) | Q(ogg_published=None))
-    return render(request, "archive/list_published.html", locals())
+class AudiobookList(ListView):
+    queryset = models.Audiobook.objects.all()
 
 
 @permission_required('archive.change_audiobook')
@@ -260,7 +244,6 @@ def file_managed(request, id):
             except IOError:
                 raise Http404
 
-    division = 'published' if audiobook.published() else 'unpublished'
     path = audiobook.source_file.path[len(settings.FILES_PATH):].lstrip('/')
 
     # for tags update
@@ -286,15 +269,11 @@ def file_managed(request, id):
 
 
 def list_unmanaged(request):
-    division = 'unmanaged'
-
     objects = sorted(all_files(settings.UNMANAGED_PATH))
     return render(request, "archive/list_unmanaged.html", locals())
 
 
 def file_unmanaged(request, filename):
-    division = 'unmanaged'
-
     tags = mutagen.File(os.path.join(settings.UNMANAGED_PATH, filename.encode('utf-8')))
     if not tags:
         tags = {}
@@ -307,4 +286,6 @@ class BookView(ListView):
     template_name = 'archive/book.html'
 
     def get_queryset(self):
-        return models.Audiobook.objects.filter(slug=self.kwargs['slug'])
+        return models.Audiobook.objects.filter(slug=self.kwargs["slug"]).order_by(
+            "index"
+        )
index ca3d16e..901da0f 100644 (file)
@@ -107,6 +107,7 @@ MIDDLEWARE = (
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django_cas_ng.middleware.CASMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
+    "fnp_django_pagination.middleware.PaginationMiddleware",
 )
 
 AUTHENTICATION_BACKENDS = (
@@ -128,10 +129,10 @@ INSTALLED_APPS = (
     # 'django.contrib.admindocs',
     'bootstrap4',
     'django_cas_ng',
-
     'apiclient',
     'archive',
     'youtube',
+    "fnp_django_pagination",
 )
 
 # A sample logging configuration. The only tangible logging