Meta errors in alerts.
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 23 May 2022 10:03:51 +0000 (12:03 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 23 May 2022 10:03:51 +0000 (12:03 +0200)
requirements/requirements.txt
src/alerts/admin.py
src/alerts/migrations/0002_alert_comment.py [new file with mode: 0644]
src/alerts/models.py
src/alerts/rules.py
src/documents/templates/documents/base.html

index 4bccc22..0861384 100644 (file)
@@ -10,7 +10,7 @@ python-slugify
 python-docx==0.8.10
 Wikidata==0.6.1
 
 python-docx==0.8.10
 Wikidata==0.6.1
 
-librarian==2.4.1
+librarian==2.4.2
 
 ## Django
 Django==3.2.12
 
 ## Django
 Django==3.2.12
index 3eda708..0872f4d 100644 (file)
@@ -2,4 +2,7 @@ from django.contrib import admin
 from .models import Alert
 
 
 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 (file)
index 0000000..d3d9c5b
--- /dev/null
@@ -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),
+        ),
+    ]
index 268089a..66d1bff 100644 (file)
@@ -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)
 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):
 
     @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)
         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
 
             return
 
+        try:
+            meta = wlbook.meta
+        except Exception as e:
+            cls.objects.create(book=book, tag='meta', comment=str(e))
+            return
+        
         for rule in rules:
         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)
 
                 print(rule.tag, book)
                 cls.objects.create(book=book, tag=rule.tag)
 
index c7903f1..389dcbb 100644 (file)
@@ -12,6 +12,11 @@ class CheckParse(Check):
     description = _('Book parse error.')
 
 
     description = _('Book parse error.')
 
 
+class CheckMeta(Check):
+    tag = 'meta'
+    description = _('Metadata parse error.')
+
+
 class CheckCoverLocal(Check):
     tag = 'cover-local'
     description = _('Cover is not local')
 class CheckCoverLocal(Check):
     tag = 'cover-local'
     description = _('Cover is not local')
@@ -26,6 +31,7 @@ class CheckCoverLocal(Check):
 
 rules = [
     CheckParse(),
 
 rules = [
     CheckParse(),
+    CheckMeta(),
     CheckCoverLocal(),
 ]
 
     CheckCoverLocal(),
 ]
 
index 2d5fe8e..ba28310 100644 (file)
@@ -40,6 +40,9 @@
               <a class="dropdown-item" href="{{ alert.book.get_absolute_url }}">
                 {{ alert.book }}<br>
                 {{ alert.rule.description }}
               <a class="dropdown-item" href="{{ alert.book.get_absolute_url }}">
                 {{ alert.book }}<br>
                 {{ alert.rule.description }}
+                {% if alert.comment %}
+                  <br><small>{{ alert.comment }}</small>
+                {% endif %}
               </a>
             {% endfor %}
           </div>
               </a>
             {% endfor %}
           </div>