optimized problem publisher page

main
eric 2023-09-06 14:05:36 -04:00
parent a552feae3f
commit 4612b2162c
2 changed files with 6 additions and 14 deletions

View File

@ -20,8 +20,8 @@ DOAB Link Checking Problems by Publisher
</tr> </tr>
{% for pub in pubs %} {% for pub in pubs %}
<tr style="color:red"> <tr style="color:red">
<td> <a href="{% url 'publisher' pub.0 %}">{{ pub.0 }}</a> </td> <td> <a href="{% url 'publisher' pub.items__publisher_name %}">{{ pub.items__publisher_name }}</a> </td>
<td> {{ pub.1 }} </td> <td> {{ pub.items__publisher_name__count }} </td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -99,19 +99,11 @@ class ProblemPublishersView(generic.TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
probpubs = {} probpubs = {}
problinks = Link.objects.exclude( problinks = Link.objects.filter(live=True, recent_check__isnull=False).exclude(
recent_check__isnull=True).exclude(
recent_check__return_code__exact=200) recent_check__return_code__exact=200)
for link in problinks: pubnames = problinks.order_by('items__publisher_name').values(
first_item = link.items.filter(status=1).first() 'items__publisher_name').distinct().annotate(Count('items__publisher_name'))
if first_item: return {'pubs': pubnames}
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)}
class PublisherView(generic.TemplateView): class PublisherView(generic.TemplateView):