From beac9fec3de5fa66dfc80ed119c4bdd812e9e2c2 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 23 May 2022 12:03:51 +0200 Subject: [PATCH] Meta errors in alerts. --- requirements/requirements.txt | 2 +- src/alerts/admin.py | 5 ++++- src/alerts/migrations/0002_alert_comment.py | 18 ++++++++++++++++++ src/alerts/models.py | 16 +++++++++++++--- src/alerts/rules.py | 6 ++++++ src/documents/templates/documents/base.html | 3 +++ 6 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/alerts/migrations/0002_alert_comment.py diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 4bccc22a..0861384d 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -10,7 +10,7 @@ python-slugify python-docx==0.8.10 Wikidata==0.6.1 -librarian==2.4.1 +librarian==2.4.2 ## Django Django==3.2.12 diff --git a/src/alerts/admin.py b/src/alerts/admin.py index 3eda708d..0872f4da 100644 --- a/src/alerts/admin.py +++ b/src/alerts/admin.py @@ -2,4 +2,7 @@ from django.contrib import admin from .models import Alert -admin.site.register(Alert) +@admin.register(Alert) +class AlertAdmin(admin.ModelAdmin): + list_display = ['book', 'tag'] + list_filter = ['tag'] diff --git a/src/alerts/migrations/0002_alert_comment.py b/src/alerts/migrations/0002_alert_comment.py new file mode 100644 index 00000000..d3d9c5b1 --- /dev/null +++ b/src/alerts/migrations/0002_alert_comment.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2022-05-23 11:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('alerts', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='alert', + name='comment', + field=models.TextField(blank=True), + ), + ] diff --git a/src/alerts/models.py b/src/alerts/models.py index 268089ab..66d1bff7 100644 --- a/src/alerts/models.py +++ b/src/alerts/models.py @@ -7,6 +7,10 @@ from .rules import rules, rules_by_tag class Alert(models.Model): book = models.ForeignKey('documents.Book', models.CASCADE) tag = models.CharField(max_length=32) + comment = models.TextField(blank=True) + + def get_absolute_url(self): + return self.book.get_absolute_url() @property def rule(self): @@ -17,12 +21,18 @@ class Alert(models.Model): cls.objects.filter(book=book).delete() try: wlbook = book.wldocument(publishable=False, librarian2=True) - except: - cls.objects.create(book=book, tag='parse') + except Exception: + cls.objects.create(book=book, tag='parse', comment=str(e)) return + try: + meta = wlbook.meta + except Exception as e: + cls.objects.create(book=book, tag='meta', comment=str(e)) + return + for rule in rules: - if rule.check_meta(wlbook.meta): + if rule.check_meta(meta): print(rule.tag, book) cls.objects.create(book=book, tag=rule.tag) diff --git a/src/alerts/rules.py b/src/alerts/rules.py index c7903f1a..389dcbb4 100644 --- a/src/alerts/rules.py +++ b/src/alerts/rules.py @@ -12,6 +12,11 @@ class CheckParse(Check): description = _('Book parse error.') +class CheckMeta(Check): + tag = 'meta' + description = _('Metadata parse error.') + + class CheckCoverLocal(Check): tag = 'cover-local' description = _('Cover is not local') @@ -26,6 +31,7 @@ class CheckCoverLocal(Check): rules = [ CheckParse(), + CheckMeta(), CheckCoverLocal(), ] diff --git a/src/documents/templates/documents/base.html b/src/documents/templates/documents/base.html index 2d5fe8ea..ba28310a 100644 --- a/src/documents/templates/documents/base.html +++ b/src/documents/templates/documents/base.html @@ -40,6 +40,9 @@ {{ alert.book }}
{{ alert.rule.description }} + {% if alert.comment %} +
{{ alert.comment }} + {% endif %}
{% endfor %} -- 2.20.1