mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-09 12:21:57 -04:00
add icons to new public view
This commit is contained in:
parent
c50af04cce
commit
3048c0f6dc
4 changed files with 44 additions and 43 deletions
|
@ -13,6 +13,7 @@ from django.contrib.auth import get_user_model
|
|||
|
||||
from core.models import Snapshot
|
||||
from core.forms import AddLinkForm
|
||||
from core.utils import get_icons
|
||||
|
||||
from util import htmldecode, urldecode, ansi_to_html
|
||||
from logging_util import printable_filesize
|
||||
|
@ -93,34 +94,7 @@ class SnapshotAdmin(admin.ModelAdmin):
|
|||
) + mark_safe(f'<span class="tags">{tags}</span>')
|
||||
|
||||
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">🗜 </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):
|
||||
return format_html(
|
||||
|
|
36
archivebox/core/utils.py
Normal file
36
archivebox/core/utils.py
Normal file
|
@ -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">🗜 </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(),
|
||||
)
|
|
@ -10,6 +10,8 @@ from django.views.generic.list import ListView
|
|||
from django_datatables_view.base_datatable_view import BaseDatatableView
|
||||
|
||||
from core.models import Snapshot
|
||||
from core.utils import get_icons
|
||||
|
||||
|
||||
from ..index import load_main_index, load_main_index_meta
|
||||
from ..config import (
|
||||
|
@ -110,12 +112,12 @@ class LinkDetails(View):
|
|||
class PublicArchiveView(ListView):
|
||||
template = 'snapshot_list.html'
|
||||
model = Snapshot
|
||||
paginate_by = 50
|
||||
paginate_by = 100
|
||||
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
qs = super(PublicArchiveView, self).get_queryset(*args, **kwargs)
|
||||
for snapshot in qs:
|
||||
snapshot.canonical_outputs = snapshot.as_link().canonical_outputs()
|
||||
snapshot.icons = get_icons(snapshot)
|
||||
return qs
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
|
@ -125,17 +127,6 @@ class PublicArchiveView(ListView):
|
|||
else:
|
||||
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):
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
qs = super(PublicArchiveView, self).get_queryset(*args, **kwargs)
|
||||
|
|
|
@ -257,14 +257,14 @@
|
|||
{% else %}
|
||||
<a href="archive/{{link.timestamp}}/index.html"><img src="{% static 'spinner.gif' %}" class="link-favicon" decoding="async"></a>
|
||||
{% 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>
|
||||
<small style="float:right">{{link.tags|default:''}}</small>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<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>
|
||||
</td>
|
||||
<td style="text-align:left"><a href="{{link.url}}">{{link.url}}</a></td>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue