Add first alerts.
[redakcja.git] / src / alerts / rules.py
diff --git a/src/alerts/rules.py b/src/alerts/rules.py
new file mode 100644 (file)
index 0000000..c7903f1
--- /dev/null
@@ -0,0 +1,35 @@
+import re
+from django.utils.translation import gettext_lazy as _
+
+
+class Check:
+    def check_meta(self, meta):
+        return False
+
+
+class CheckParse(Check):
+    tag = 'parse'
+    description = _('Book parse error.')
+
+
+class CheckCoverLocal(Check):
+    tag = 'cover-local'
+    description = _('Cover is not local')
+
+    def check_meta(self, meta):
+        print(meta)
+        if meta.cover_source is None:
+            print('no cover_source')
+            return False
+        return not re.match(r'https?://redakcja.wolnelektury.pl/cover/image/', meta.cover_source)
+
+
+rules = [
+    CheckParse(),
+    CheckCoverLocal(),
+]
+
+rules_by_tag = {
+    r.tag: r
+    for r in rules
+}