optimized publisher list

main
eric 2023-09-06 15:25:36 -04:00
parent 13f30b7de8
commit 8836372d19
2 changed files with 6 additions and 9 deletions

View File

@ -11,13 +11,12 @@
<h2>
DOAB Linkchecking by Publisher
</h2>
<p>(number of books in parentheses)
<ul>
{% for publisher in publisher_list %}
<li><a href="{% url 'publisher' publisher.publisher_name|default:'*** no publisher name ***' %}">
{% if publisher.publisher_name %}{{publisher.publisher_name}}
{% else %}*** no publisher name ***
{% endif %}
</a> ({{publisher.item_count}})</li>
{{ publisher.publisher_name|default:'*** no publisher name ***' }}
</a> ({{ publisher.publisher_name__count }})</li>
{% endfor %}
</ul>
</div>

View File

@ -87,10 +87,9 @@ class PublishersView(generic.TemplateView):
template_name = 'publishers.html'
def get_context_data(self, **kwargs):
publishers = Item.objects.order_by('publisher_name').values('publisher_name').distinct()
for publisher in publishers:
publisher['item_count'] = Item.objects.filter(
publisher_name=publisher['publisher_name'], status=1).count()
items = Item.objects.filter(status=1)
publishers = items.order_by('publisher_name').values(
'publisher_name').distinct().annotate(Count('publisher_name'))
return {'publisher_list': publishers}
@ -98,7 +97,6 @@ class ProblemPublishersView(generic.TemplateView):
template_name = 'probpubs.html'
def get_context_data(self, **kwargs):
probpubs = {}
problinks = Link.objects.filter(live=True, recent_check__isnull=False).exclude(
recent_check__return_code__exact=200)
pubnames = problinks.order_by('items__publisher_name').values(