Browse Source

add icons to new public view

apkallum 5 years ago
parent
commit
3048c0f6dc

+ 2 - 28
archivebox/core/admin.py

@@ -13,6 +13,7 @@ from django.contrib.auth import get_user_model
 
 
 from core.models import Snapshot
 from core.models import Snapshot
 from core.forms import AddLinkForm
 from core.forms import AddLinkForm
+from core.utils import get_icons
 
 
 from util import htmldecode, urldecode, ansi_to_html
 from util import htmldecode, urldecode, ansi_to_html
 from logging_util import printable_filesize
 from logging_util import printable_filesize
@@ -93,34 +94,7 @@ class SnapshotAdmin(admin.ModelAdmin):
         ) + mark_safe(f'<span class="tags">{tags}</span>')
         ) + mark_safe(f'<span class="tags">{tags}</span>')
 
 
     def files(self, obj):
     def files(self, obj):
-        link = obj.as_link()
-        canon = link.canonical_outputs()
-        out_dir = Path(link.link_dir)
-
-        link_tuple = lambda link, method: (link.archive_path, canon[method] or '', canon[method] and (out_dir / (canon[method] or 'notdone')).exists())
-
-        return format_html(
-            '<span class="files-icons" style="font-size: 1.2em; opacity: 0.8">'
-                '<a href="/{}/{}/" class="exists-{}" title="Wget clone">🌐 </a> '
-                '<a href="/{}/{}" class="exists-{}" title="PDF">📄</a> '
-                '<a href="/{}/{}" class="exists-{}" title="Screenshot">🖥 </a> '
-                '<a href="/{}/{}" class="exists-{}" title="HTML dump">🅷 </a> '
-                '<a href="/{}/{}/" class="exists-{}" title="WARC">🆆 </a> '
-                '<a href="/{}/{}" class="exists-{}" title="SingleFile">&#128476; </a>'
-                '<a href="/{}/{}/" class="exists-{}" title="Media files">📼 </a> '
-                '<a href="/{}/{}/" class="exists-{}" title="Git repos">📦 </a> '
-                '<a href="{}" class="exists-{}" title="Archive.org snapshot">🏛 </a> '
-            '</span>',
-            *link_tuple(link, 'wget_path'),
-            *link_tuple(link, 'pdf_path'),
-            *link_tuple(link, 'screenshot_path'),
-            *link_tuple(link, 'dom_path'),
-            *link_tuple(link, 'warc_path')[:2], any((out_dir / canon['warc_path']).glob('*.warc.gz')),
-            *link_tuple(link, 'singlefile_path'),
-            *link_tuple(link, 'media_path')[:2], any((out_dir / canon['media_path']).glob('*')),
-            *link_tuple(link, 'git_path')[:2], any((out_dir / canon['git_path']).glob('*')),
-            canon['archive_org_path'], (out_dir / 'archive.org.txt').exists(),
-        )
+        return get_icons(obj)
 
 
     def size(self, obj):
     def size(self, obj):
         return format_html(
         return format_html(

+ 36 - 0
archivebox/core/utils.py

@@ -0,0 +1,36 @@
+from pathlib import Path
+
+from django.utils.html import format_html
+
+from core.models import Snapshot
+
+
+def get_icons(snapshot: Snapshot) -> str:
+    link = snapshot.as_link()
+    canon = link.canonical_outputs()
+    out_dir = Path(link.link_dir)
+
+    link_tuple = lambda link, method: (link.archive_path, canon[method] or '', canon[method] and (out_dir / (canon[method] or 'notdone')).exists())
+
+    return format_html(
+            '<span class="files-icons" style="font-size: 1.2em; opacity: 0.8">'
+                '<a href="/{}/{}/" class="exists-{}" title="Wget clone">🌐 </a> '
+                '<a href="/{}/{}" class="exists-{}" title="PDF">📄</a> '
+                '<a href="/{}/{}" class="exists-{}" title="Screenshot">🖥 </a> '
+                '<a href="/{}/{}" class="exists-{}" title="HTML dump">🅷 </a> '
+                '<a href="/{}/{}/" class="exists-{}" title="WARC">🆆 </a> '
+                '<a href="/{}/{}" class="exists-{}" title="SingleFile">&#128476; </a>'
+                '<a href="/{}/{}/" class="exists-{}" title="Media files">📼 </a> '
+                '<a href="/{}/{}/" class="exists-{}" title="Git repos">📦 </a> '
+                '<a href="{}" class="exists-{}" title="Archive.org snapshot">🏛 </a> '
+            '</span>',
+            *link_tuple(link, 'wget_path'),
+            *link_tuple(link, 'pdf_path'),
+            *link_tuple(link, 'screenshot_path'),
+            *link_tuple(link, 'dom_path'),
+            *link_tuple(link, 'warc_path')[:2], any((out_dir / canon['warc_path']).glob('*.warc.gz')),
+            *link_tuple(link, 'singlefile_path'),
+            *link_tuple(link, 'media_path')[:2], any((out_dir / canon['media_path']).glob('*')),
+            *link_tuple(link, 'git_path')[:2], any((out_dir / canon['git_path']).glob('*')),
+            canon['archive_org_path'], (out_dir / 'archive.org.txt').exists(),
+        )

+ 4 - 13
archivebox/core/views.py

@@ -10,6 +10,8 @@ from django.views.generic.list import ListView
 from django_datatables_view.base_datatable_view import BaseDatatableView
 from django_datatables_view.base_datatable_view import BaseDatatableView
 
 
 from core.models import Snapshot
 from core.models import Snapshot
+from core.utils import get_icons
+
 
 
 from ..index import load_main_index, load_main_index_meta
 from ..index import load_main_index, load_main_index_meta
 from ..config import (
 from ..config import (
@@ -110,12 +112,12 @@ class LinkDetails(View):
 class PublicArchiveView(ListView):
 class PublicArchiveView(ListView):
     template = 'snapshot_list.html'
     template = 'snapshot_list.html'
     model = Snapshot
     model = Snapshot
-    paginate_by = 50
+    paginate_by = 100
 
 
     def get_queryset(self, *args, **kwargs): 
     def get_queryset(self, *args, **kwargs): 
         qs = super(PublicArchiveView, self).get_queryset(*args, **kwargs) 
         qs = super(PublicArchiveView, self).get_queryset(*args, **kwargs) 
         for snapshot in qs:
         for snapshot in qs:
-            snapshot.canonical_outputs = snapshot.as_link().canonical_outputs() 
+            snapshot.icons = get_icons(snapshot) 
         return qs
         return qs
 
 
     def get(self, *args, **kwargs):
     def get(self, *args, **kwargs):
@@ -125,17 +127,6 @@ class PublicArchiveView(ListView):
         else:
         else:
             return redirect(f'/admin/login/?next={self.request.path}')
             return redirect(f'/admin/login/?next={self.request.path}')
 
 
-# should we use it?
-class SnapshotDatatableView(BaseDatatableView):
-    model = Snapshot
-    columns = ['url', 'timestamp', 'title', 'tags', 'added']
-
-    def filter_queryset(self, qs):
-        sSearch = self.request.GET.get('sSearch', None)
-        if sSearch:
-            qs = qs.filter(Q(title__icontains=sSearch))
-        return qs
-
 class SearchResultsView(PublicArchiveView):
 class SearchResultsView(PublicArchiveView):
     def get_queryset(self, *args, **kwargs):
     def get_queryset(self, *args, **kwargs):
         qs = super(PublicArchiveView, self).get_queryset(*args, **kwargs) 
         qs = super(PublicArchiveView, self).get_queryset(*args, **kwargs) 

+ 2 - 2
archivebox/themes/default/core/snapshot_list.html

@@ -257,14 +257,14 @@
                             {% else %}
                             {% else %}
                                 <a href="archive/{{link.timestamp}}/index.html"><img src="{% static 'spinner.gif' %}" class="link-favicon" decoding="async"></a>
                                 <a href="archive/{{link.timestamp}}/index.html"><img src="{% static 'spinner.gif' %}" class="link-favicon" decoding="async"></a>
                             {% endif %}
                             {% endif %}
-                            <a href="archive/{{link.timestamp}}/{{link.canonical_outputs.wget_path}}" title="{{link.title}}">
+                            <a href="archive/{{link.timestamp}}/index.html" title="{{link.title}}">
                                 <span data-title-for="{{link.url}}" data-archived="{{link.is_archived}}">{{link.title|default:'Loading...'}}</span>
                                 <span data-title-for="{{link.url}}" data-archived="{{link.is_archived}}">{{link.title|default:'Loading...'}}</span>
                                 <small style="float:right">{{link.tags|default:''}}</small>
                                 <small style="float:right">{{link.tags|default:''}}</small>
                             </a>
                             </a>
                         </td>
                         </td>
                         <td>
                         <td>
                             <a href="archive/{{link.timestamp}}/index.html">📄 
                             <a href="archive/{{link.timestamp}}/index.html">📄 
-                                <span data-number-for="{{link.url}}" title="Fetching any missing files...">Entry to files <img src="{% static 'spinner.gif' %}" class="files-spinner" decoding="async"/></span>
+                                <span data-number-for="{{link.url}}" title="Fetching any missing files...">{{link.icons}} <img src="{% static 'spinner.gif' %}" class="files-spinner" decoding="async"/></span>
                             </a>
                             </a>
                         </td>
                         </td>
                         <td style="text-align:left"><a href="{{link.url}}">{{link.url}}</a></td>
                         <td style="text-align:left"><a href="{{link.url}}">{{link.url}}</a></td>