1 from django.db import models
2 from django.dispatch import receiver
3 from dvcs.models import post_commit
4 from .rules import rules, rules_by_tag
7 class Alert(models.Model):
8 book = models.ForeignKey('documents.Book', models.CASCADE)
9 tag = models.CharField(max_length=32)
10 comment = models.TextField(blank=True)
12 def get_absolute_url(self):
13 return self.book.get_absolute_url()
17 return rules_by_tag[self.tag]
20 def validate_book(cls, book):
21 cls.objects.filter(book=book).delete()
23 wlbook = book.wldocument(publishable=False, librarian2=True)
24 except Exception as e:
25 cls.objects.create(book=book, tag='parse', comment=str(e))
30 except Exception as e:
31 cls.objects.create(book=book, tag='meta', comment=str(e))
35 if rule.check_meta(meta):
37 cls.objects.create(book=book, tag=rule.tag)
40 @receiver(post_commit)
41 def validate_post_commit(sender, **kwargs):
42 Alert.validate_book(sender.tree.book)