easier to just loop the bad links

main
eric 2023-05-09 15:58:49 -04:00
parent b69aeaeaa8
commit 4356f02b5e
2 changed files with 8 additions and 37 deletions

View File

@ -13,41 +13,14 @@ DOAB Link Checking Problems by Publisher
<th>Publisher</th>
<th>Number</th>
</tr>
{% for pub in pubs %}
{% for pub, numbad in pubs %}
<tr style="color:red">
<td> <a href="#{{ pub.pub | default:'*** no publisher name ***'| urlencode}}">{{ pub.pub | default:'*** no publisher name ***' }}</a> </td>
<td> {{ pub.bad_links.count }} </td>
<td> <a href="{% url 'publisher' pub %}">{{ pub | default:'*** no publisher name ***' }}</a> </td>
<td> {{ numbad }} </td>
</tr>
{% endfor %}
</table>
<h3>Problem links by publisher</h3>
<ul>
{% for pub in pubs %}
<li id={{ pub.pub | default:'*** no publisher name ***' | urlencode }}><h4>{{ pub.pub | default:'*** no publisher name ***'}}</h4>
{% for link in pub.bad_links.all %}
<table>
<tr>
<th>
<a href="{{ link.url }}">{{ link.url }}</a>
</th>
<tr>
<td>
<table>
{% for check in link.recent_checks %}
<tr>
<td>{{ check.created }}:</td>
<td style="color:red">{{ check.return_code }}</td>
<td>{{ check.content_type }}</td>
</tr>
{% endfor %}
</table>
</td>
</tr>
{% endfor %}
</table>
</li>
{% endfor %}
</ul>
</body>
</html>

View File

@ -85,16 +85,14 @@ class ProblemPublishersView(generic.TemplateView):
template_name = 'probpubs.html'
def get_context_data(self, **kwargs):
onepub = Link.objects.filter(items=OuterRef("pk"))[:1].values('items__publisher_name')
probpubs = {}
problinks = Link.objects.exclude(
recent_check__isnull=True).exclude(
recent_check__return_code__exact=200)
probpubs = problinks.annotate(pub=onepub).order_by('pub')
pubs = probpubs.values('pub').distinct()
numlinks = probpubs.count()
for publisher in pubs:
publisher['bad_links'] = probpubs.filter(pub=publisher['pub'])
return {'pubs': pubs}
for link in problinks:
pub = link.items.filter(status=1).first().publisher_name
probpubs[pub] = probpubs.get(pub, 0) + 1
return {'pubs': probpubs.items() }
class PublisherView(generic.TemplateView):