From e8314f4fa77c876702d477fa7b35d25a235a9d7a Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 30 Mar 2023 14:35:15 -0400 Subject: [PATCH] add publisher reports --- doab_check/models.py | 4 +++ doab_check/templates/index.html | 3 +++ doab_check/templates/publisher.html | 39 ++++++++++++++++++++++++++++ doab_check/templates/publishers.html | 15 +++++++++++ doab_check/urls.py | 2 ++ doab_check/views.py | 23 +++++++++++++++- 6 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 doab_check/templates/publisher.html create mode 100644 doab_check/templates/publishers.html diff --git a/doab_check/models.py b/doab_check/models.py index a974670..5f481c4 100644 --- a/doab_check/models.py +++ b/doab_check/models.py @@ -21,6 +21,10 @@ class Item(models.Model): def __str__(self): return self.doab.split('/')[1] if '/' in self.doab else self.doab + @property + def url(self): + return f'https://directory.doabooks.org/handle/{self.doab}' + class Link(models.Model): ''' these are the links we're going to check ''' url = models.URLField(max_length=1024, unique=True) diff --git a/doab_check/templates/index.html b/doab_check/templates/index.html index d338872..84f7105 100644 --- a/doab_check/templates/index.html +++ b/doab_check/templates/index.html @@ -24,6 +24,9 @@ When a link is checked we record the status code returned by the web server. "40
  • View the list of host names we've checked.
  • +
  • +View the list of publishers whose links we've checked. +
  • We'll be adding more views of the link checking data as the project develops. diff --git a/doab_check/templates/publisher.html b/doab_check/templates/publisher.html new file mode 100644 index 0000000..6d4a2a6 --- /dev/null +++ b/doab_check/templates/publisher.html @@ -0,0 +1,39 @@ + + +DOAB Link Checking for {{ publisher.publisher }} + + +

    +DOAB Linkchecking for +{{ publisher.publisher }} ({{ items.count }} records) +

    + + + \ No newline at end of file diff --git a/doab_check/templates/publishers.html b/doab_check/templates/publishers.html new file mode 100644 index 0000000..42816c3 --- /dev/null +++ b/doab_check/templates/publishers.html @@ -0,0 +1,15 @@ + + +DOAB Publishers + + +

    +DOAB Linkchecking by Publisher +

    + + + \ No newline at end of file diff --git a/doab_check/urls.py b/doab_check/urls.py index a268cdc..3a5e5bb 100644 --- a/doab_check/urls.py +++ b/doab_check/urls.py @@ -11,4 +11,6 @@ urlpatterns = [ path('admin/', admin.site.urls), path('providers/', views.ProvidersView.as_view(), name='providers'), path('providers//', views.ProviderView.as_view(), name='provider'), + path('publishers/', views.PublishersView.as_view(), name='publishers'), + path('publishers//', views.PublisherView.as_view(), name='publisher'), ] diff --git a/doab_check/views.py b/doab_check/views.py index 0e1175d..469b9b2 100644 --- a/doab_check/views.py +++ b/doab_check/views.py @@ -6,7 +6,7 @@ from django.shortcuts import get_object_or_404, render from django.urls import reverse from django.views import generic -from .models import Link +from .models import Item, Link class ProvidersView(generic.TemplateView): @@ -29,3 +29,24 @@ class ProviderView(generic.TemplateView): provider['link_count'] = provider_links.count() return {'provider': provider, 'links': provider_links} + +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']).count() + return {'publisher_list': publishers} + +class PublisherView(generic.TemplateView): + template_name = 'publisher.html' + + def get_context_data(self, **kwargs): + pub = kwargs['publisher'] + publisher = {'publisher': pub} + publisher_items = Item.objects.filter(publisher_name=pub) + publisher['link_count'] = publisher_items.count() + + return {'publisher': publisher, 'items': publisher_items}