1
0
Fork 0
mirror of synced 2024-06-28 11:00:35 +12:00

fix: Refactor html functionality

This commit is contained in:
Cristian 2021-01-18 09:38:19 -05:00
parent e403d07a88
commit 891dd3b8a9
5 changed files with 57 additions and 45 deletions

View file

@ -3,7 +3,7 @@ __package__ = 'archivebox.core'
import uuid import uuid
from pathlib import Path from pathlib import Path
from typing import Dict, Optional, List from typing import Dict, Optional, List
from datetime import datetime from datetime import datetime, timedelta
from collections import defaultdict from collections import defaultdict
from django.db import models, transaction from django.db import models, transaction
@ -148,7 +148,6 @@ class Snapshot(models.Model):
output["history"] = self.get_history() output["history"] = self.get_history()
return output return output
def as_csv(self, cols: Optional[List[str]]=None, separator: str=',', ljust: int=0) -> str: def as_csv(self, cols: Optional[List[str]]=None, separator: str=',', ljust: int=0) -> str:
from ..index.csv import to_csv from ..index.csv import to_csv
return to_csv(self, cols=cols or self.field_names(), separator=separator, ljust=ljust) return to_csv(self, cols=cols or self.field_names(), separator=separator, ljust=ljust)
@ -167,6 +166,19 @@ class Snapshot(models.Model):
def bookmarked(self): def bookmarked(self):
return parse_date(self.timestamp) return parse_date(self.timestamp)
@cached_property
def bookmarked_date(self) -> Optional[str]:
from ..util import ts_to_date
max_ts = (datetime.now() + timedelta(days=30)).timestamp()
if self.timestamp and self.timestamp.replace('.', '').isdigit():
if 0 < float(self.timestamp) < max_ts:
return ts_to_date(datetime.fromtimestamp(float(self.timestamp)))
else:
return str(self.timestamp)
return None
@cached_property @cached_property
def is_archived(self) -> bool: def is_archived(self) -> bool:
from ..config import ARCHIVE_DIR from ..config import ARCHIVE_DIR

View file

@ -84,12 +84,6 @@ def snapshot_details_template(snapshot: Model) -> str:
from ..extractors.wget import wget_output_path from ..extractors.wget import wget_output_path
tags = snapshot.tags.all()
if len(tags) > 0:
tags = ",".join(list(tags.values_list("name", flat=True)))
else:
tags = "untagged"
return render_django_template(LINK_DETAILS_TEMPLATE, { return render_django_template(LINK_DETAILS_TEMPLATE, {
**snapshot.as_json(), **snapshot.as_json(),
**snapshot.canonical_outputs(), **snapshot.canonical_outputs(),
@ -103,7 +97,7 @@ def snapshot_details_template(snapshot: Model) -> str:
or (snapshot.domain if snapshot.is_archived else '') or (snapshot.domain if snapshot.is_archived else '')
) or 'about:blank', ) or 'about:blank',
'extension': snapshot.extension or 'html', 'extension': snapshot.extension or 'html',
'tags': tags, 'tags': snapshot.tags_str() or "untagged",
'size': printable_filesize(snapshot.archive_size) if snapshot.archive_size else 'pending', 'size': printable_filesize(snapshot.archive_size) if snapshot.archive_size else 'pending',
'status': 'archived' if snapshot.is_archived else 'not yet archived', 'status': 'archived' if snapshot.is_archived else 'not yet archived',
'status_color': 'success' if snapshot.is_archived else 'danger', 'status_color': 'success' if snapshot.is_archived else 'danger',

View file

@ -227,14 +227,14 @@
<thead> <thead>
<tr> <tr>
<th style="width: 100px;">Bookmarked</th> <th style="width: 100px;">Bookmarked</th>
<th style="width: 26vw;">Saved Link ({{num_links}})</th> <th style="width: 26vw;">Saved Link ({{num_snapshots}})</th>
<th style="width: 50px">Files</th> <th style="width: 50px">Files</th>
<th style="width: 16vw;whitespace:nowrap;overflow-x:hidden;">Original URL</th> <th style="width: 16vw;whitespace:nowrap;overflow-x:hidden;">Original URL</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for link in links %} {% for snapshot in snapshots %}
{% include 'main_index_row.html' with link=link %} {% include 'main_index_row.html' with snapshot=snapshot %}
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>

View file

@ -1,24 +1,30 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>Archived Sites</title> <title>Archived Sites</title>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1"> <meta
</head> charset="utf-8"
<body data-status="{{status}}"> name="viewport"
<table id="table-bookmarks"> content="width=device-width, initial-scale=1"
<thead> />
<tr class="thead-tr"> </head>
<th style="width: 100px;">Bookmarked</th> <body data-status="{{status}}">
<th style="width: 26vw;">Saved Link ({{num_links}})</th> <table id="table-bookmarks">
<th style="width: 50px">Files</th> <thead>
<th style="width: 16vw;whitespace:nowrap;overflow-x:hidden;">Original URL</th> <tr class="thead-tr">
</tr> <th style="width: 100px">Bookmarked</th>
</thead> <th style="width: 26vw">Saved Link ({{num_links}})</th>
<tbody> <th style="width: 50px">Files</th>
{% for link in links %} <th style="width: 16vw; whitespace: nowrap; overflow-x: hidden">
{% include "main_index_row.html" with link=link %} Original URL
{% endfor %} </th>
</tbody> </tr>
</table> </thead>
</body> <tbody>
</html> {% for snapshot in snapshots %}
{% include "main_index_row.html" with snapshot=snapshot %}
{% endfor %}
</tbody>
</table>
</body>
</html>

View file

@ -1,22 +1,22 @@
{% load static %} {% load static %}
<tr> <tr>
<td title="{{link.timestamp}}"> {% if link.bookmarked_date %} {{ link.bookmarked_date }} {% else %} {{ link.added }} {% endif %} </td> <td title="{{snapshot.timestamp}}"> {% if snapshot.bookmarked_date %} {{ snapshot.bookmarked_date }} {% else %} {{ snapshot.added }} {% endif %} </td>
<td class="title-col"> <td class="title-col">
{% if link.is_archived %} {% if snapshot.is_archived %}
<a href="archive/{{link.timestamp}}/index.html"><img src="archive/{{link.timestamp}}/favicon.ico" class="link-favicon" decoding="async"></a> <a href="archive/{{snapshot.timestamp}}/index.html"><img src="archive/{{snapshot.timestamp}}/favicon.ico" class="link-favicon" decoding="async"></a>
{% else %} {% else %}
<a href="archive/{{link.timestamp}}/index.html"><img src="{% static 'spinner.gif' %}" class="link-favicon" decoding="async"></a> <a href="archive/{{snapshot.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/{{snapshot.timestamp}}/{{snapshot.canonical_outputs.wget_path}}" title="{{snapshot.title}}">
<span data-title-for="{{link.url}}" data-archived="{{link.is_archived}}">{{link.title|default:'Loading...'}}</span> <span data-title-for="{{snapshot.url}}" data-archived="{{snapshot.is_archived}}">{{snapshot.title|default:'Loading...'}}</span>
<small style="float:right">{% if link.tags_str != None %} {{link.tags_str|default:''}} {% else %} {{ link.tags|default:'' }} {% endif %}</small> <small style="float:right">{% if snapshot.tags_str != None %} {{snapshot.tags_str|default:''}} {% else %} untagged {% endif %}</small>
</a> </a>
</td> </td>
<td> <td>
<a href="archive/{{link.timestamp}}/index.html">📄 <a href="archive/{{snapshot.timestamp}}/index.html">📄
<span data-number-for="{{link.url}}" title="Fetching any missing files...">{% if link.icons %} {{link.icons}} {% else %} {{ link.num_outputs}} {% endif %}<img src="{% static 'spinner.gif' %}" class="files-spinner" decoding="async"/></span> <span data-number-for="{{snapshot.url}}" title="Fetching any missing files...">{% if snapshot.icons %} {{snapshot.icons}} {% else %} {{ snapshot.num_outputs}} {% endif %}<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="{{snapshot.url}}">{{snapshot.url}}</a></td>
</tr> </tr>