librarian bump
[wolnelektury.git] / apps / lesmianator / models.py
index dce4b15..4b3daf8 100644 (file)
@@ -26,7 +26,7 @@ from catalogue.models import Book, Tag
 class Poem(models.Model):
     slug = models.SlugField(_('slug'), max_length=120, db_index=True)
     text = models.TextField(_('text'))
 class Poem(models.Model):
     slug = models.SlugField(_('slug'), max_length=120, db_index=True)
     text = models.TextField(_('text'))
-    created_by = models.ForeignKey(User)
+    created_by = models.ForeignKey(User, null=True)
     created_from = JSONField(_('extra information'), null=True, blank=True)
     created_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False)
     seen_at = models.DateTimeField(_('last view date'), auto_now_add=True, editable=False)
     created_from = JSONField(_('extra information'), null=True, blank=True)
     created_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False)
     seen_at = models.DateTimeField(_('last view date'), auto_now_add=True, editable=False)
@@ -147,11 +147,17 @@ class Continuations(models.Model):
     @classmethod
     def get(cls, sth):
         object_type = ContentType.objects.get_for_model(sth)
     @classmethod
     def get(cls, sth):
         object_type = ContentType.objects.get_for_model(sth)
+        should_keys = set([sth.id])
+        if isinstance(sth, Tag):
+            should_keys = set(b.pk for b in Book.tagged.with_any((sth,)))
         try:
             obj = cls.objects.get(content_type=object_type, object_id=sth.id)
             f = open(obj.pickle.path)
         try:
             obj = cls.objects.get(content_type=object_type, object_id=sth.id)
             f = open(obj.pickle.path)
-            conts = cPickle.load(f)
+            keys, conts = cPickle.load(f)
             f.close()
             f.close()
+            if set(keys) != should_keys:
+                obj.delete()
+                raise cls.DoesNotExist
             return conts
         except cls.DoesNotExist:
             if isinstance(sth, Book):
             return conts
         except cls.DoesNotExist:
             if isinstance(sth, Book):
@@ -162,7 +168,7 @@ class Continuations(models.Model):
                 raise NotImplemented('Lesmianator continuations: only Book and Tag supported')
 
             c = cls(content_object=sth)
                 raise NotImplemented('Lesmianator continuations: only Book and Tag supported')
 
             c = cls(content_object=sth)
-            c.pickle.save(sth.slug+'.p', ContentFile(cPickle.dumps(conts)))
+            c.pickle.save(sth.slug+'.p', ContentFile(cPickle.dumps((should_keys, conts))))
             c.save()
             return conts
 
             c.save()
             return conts