Skip to content

Commit

Permalink
Merge pull request #644 from tcely/patch-4
Browse files Browse the repository at this point in the history
Fix filesizeformat prefixes
  • Loading branch information
meeb authored Jan 31, 2025
2 parents 1c43315 + 4a484d9 commit 157f5aa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
10 changes: 5 additions & 5 deletions tubesync/sync/templates/sync/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}{% load humanize %}
{% extends 'base.html' %}{% load humanize %}{% load filters %}

{% block headtitle %}Dashboard{% endblock %}

Expand Down Expand Up @@ -57,9 +57,9 @@ <h3 class="truncate">{{ num_tasks }}</h3>
<div class="card dashcard">
<a href="{% url 'sync:media' %}">
<div class="card-content">
<h3 class="truncate">{{ disk_usage_bytes|filesizeformat }}</h3>
<h3 class="truncate">{{ disk_usage_bytes|bytesformat }}</h3>
<div class="desc truncate">{{ disk_usage_bytes|intcomma }} bytes</div>
<div class="truncate">Avg. <strong>{{ average_bytes_per_media|filesizeformat }}</strong> per media</div>
<div class="truncate">Avg. <strong>{{ average_bytes_per_media|bytesformat }}</strong> per media</div>
</div>
</a>
</div>
Expand Down Expand Up @@ -89,7 +89,7 @@ <h4 class="truncate">Largest downloads</h4>
{% for media in largest_downloads %}
<a href="{% url 'sync:media-item' pk=media.pk %}" class="collection-item">
<div class="truncate">{{ media.name }}</div>
<div class="truncate"><strong>{{ media.downloaded_filesize|filesizeformat }}</strong>{% if media.downloaded_format %} in {{ media.downloaded_format }}{% endif %} from &quot;{{ media.source.name }}&quot;</div>
<div class="truncate"><strong>{{ media.downloaded_filesize|bytesformat }}</strong>{% if media.downloaded_format %} in {{ media.downloaded_format }}{% endif %} from &quot;{{ media.source.name }}&quot;</div>
</a>
{% empty %}
<span class="collection-item">No media has been downloaded.</span>
Expand Down Expand Up @@ -125,7 +125,7 @@ <h2 class="truncate">Runtime information</h2>
</tr>
<tr title="Database connection used by TubeSync">
<td class="hide-on-small-only">Database</td>
<td><span class="hide-on-med-and-up">Database<br></span><strong>{{ database_connection }}{% if database_filesize %} {{ database_filesize|filesizeformat }}{% endif %}</strong></td>
<td><span class="hide-on-med-and-up">Database<br></span><strong>{{ database_connection }}{% if database_filesize %} ({{ database_filesize|bytesformat }}){% endif %}</strong></td>
</tr>
</table>
</div>
Expand Down
4 changes: 2 additions & 2 deletions tubesync/sync/templates/sync/media-item.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'base.html' %}{% load static %}{% load humanize %}
{% extends 'base.html' %}{% load static %}{% load humanize %}{% load filters %}

{% block headtitle %}Media - {{ media.key }}{% endblock %}

Expand Down Expand Up @@ -113,7 +113,7 @@ <h1 class="truncate">Media <strong>{{ media.key }}</strong> {{ download_state_ic
</td> </tr>
<tr title="Size of the file on disk">
<td class="hide-on-small-only">File size</td>
<td><span class="hide-on-med-and-up">File size<br></span><strong>{{ media.downloaded_filesize|filesizeformat }}</strong></td>
<td><span class="hide-on-med-and-up">File size<br></span><strong>{{ media.downloaded_filesize|bytesformat }}</strong></td>
</tr>
<tr title="Codecs used in the downloaded file">
<td class="hide-on-small-only">Downloaded codecs</td>
Expand Down
1 change: 1 addition & 0 deletions tubesync/sync/templatetags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

14 changes: 14 additions & 0 deletions tubesync/sync/templatetags/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import template
from django.template.defaultfilters import filesizeformat


register = template.Library()


@register.filter(is_safe=True)
def bytesformat(input):
output = filesizeformat(input)
if not (output and output.endswith('B', -1)):
return output
return output[: -1 ] + output[ -1 :].replace('B', 'iB', 1)

0 comments on commit 157f5aa

Please sign in to comment.