add media items downloaded counter to sources list overview

This commit is contained in:
meeb 2021-02-19 14:37:56 +11:00
parent e3423bc2d2
commit 1e8711be51
2 changed files with 6 additions and 3 deletions

View File

@ -30,7 +30,7 @@
{% if source.has_failed %}
<span class="error-text"><i class="fas fa-exclamation-triangle"></i> <strong>Source has permanent failures</strong></span>
{% else %}
<strong>{{ source.media_count }}</strong> media items{% if source.delete_old_media and source.days_to_keep > 0 %}, keep {{ source.days_to_keep }} days of media{% endif %}
<strong>{{ source.media_count }}</strong> media items, <strong>{{ source.downloaded_count }}</strong> downloaded{% if source.delete_old_media and source.days_to_keep > 0 %}, keeping {{ source.days_to_keep }} days of media{% endif %}
{% endif %}
</a>
{% empty %}

View File

@ -10,7 +10,7 @@ from django.views.generic.detail import SingleObjectMixin
from django.http import HttpResponse
from django.urls import reverse_lazy
from django.db import IntegrityError
from django.db.models import Q, Count, Sum
from django.db.models import Q, Count, Sum, When, Case
from django.forms import ValidationError
from django.utils.text import slugify
from django.utils import timezone
@ -104,7 +104,10 @@ class SourcesView(ListView):
def get_queryset(self):
all_sources = Source.objects.all().order_by('name')
return all_sources.annotate(media_count=Count('media_source'))
return all_sources.annotate(
media_count=Count('media_source'),
downloaded_count=Count(Case(When(media_source__downloaded=True, then=1)))
)
def get_context_data(self, *args, **kwargs):
data = super().get_context_data(*args, **kwargs)