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)
13 return rules_by_tag[self.tag]
16 def validate_book(cls, book):
17 cls.objects.filter(book=book).delete()
19 wlbook = book.wldocument(publishable=False, librarian2=True)
21 cls.objects.create(book=book, tag='parse')
25 if rule.check_meta(wlbook.meta):
27 cls.objects.create(book=book, tag=rule.tag)
30 @receiver(post_commit)
31 def validate_post_commit(sender, **kwargs):
32 Alert.validate_book(sender.tree.book)