From 4612b2162cfae5b985fd2c554322476836fbee69 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 6 Sep 2023 14:05:36 -0400 Subject: [PATCH] optimized problem publisher page --- doab_check/templates/probpubs.html | 4 ++-- doab_check/views.py | 16 ++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/doab_check/templates/probpubs.html b/doab_check/templates/probpubs.html index 9f14b45..1fb45f7 100644 --- a/doab_check/templates/probpubs.html +++ b/doab_check/templates/probpubs.html @@ -20,8 +20,8 @@ DOAB Link Checking Problems by Publisher {% for pub in pubs %} - {{ pub.0 }} - {{ pub.1 }} + {{ pub.items__publisher_name }} + {{ pub.items__publisher_name__count }} {% endfor %} diff --git a/doab_check/views.py b/doab_check/views.py index ba0fefa..a4e4954 100644 --- a/doab_check/views.py +++ b/doab_check/views.py @@ -99,19 +99,11 @@ class ProblemPublishersView(generic.TemplateView): def get_context_data(self, **kwargs): probpubs = {} - problinks = Link.objects.exclude( - recent_check__isnull=True).exclude( + problinks = Link.objects.filter(live=True, recent_check__isnull=False).exclude( recent_check__return_code__exact=200) - for link in problinks: - first_item = link.items.filter(status=1).first() - if first_item: - pub = first_item.publisher_name - probpubs[pub] = probpubs.get(pub, 0) + 1 - pubs = sorted(probpubs.items(), key=lambda x: x[0]) - def fixempty(publist): - for k, v in publist: - yield (NOPUBNAME if not k else k), v - return {'pubs': fixempty(pubs)} + pubnames = problinks.order_by('items__publisher_name').values( + 'items__publisher_name').distinct().annotate(Count('items__publisher_name')) + return {'pubs': pubnames} class PublisherView(generic.TemplateView):