django 1.3, comments on books, last activity log, some minor changes
[redakcja.git] / apps / wiki / models.py
index 4dc7017..28fdab8 100644 (file)
@@ -28,6 +28,7 @@ class Book(models.Model):
 
     parent = models.ForeignKey('self', null=True, blank=True, verbose_name=_('parent'), related_name="children")
     parent_number = models.IntegerField(_('parent number'), null=True, blank=True, db_index=True)
+    last_published = models.DateTimeField(null=True, editable=False)
 
     _list_html = models.TextField(editable=False, null=True)
 
@@ -78,18 +79,14 @@ class Book(models.Model):
             self.save(reset_list_html=False)
         return mark_safe(self._list_html)
 
-    @staticmethod
-    def publish_tag():
-        return dvcs_models.Tag.get('publish')
-
-    def materialize(self, tag=None):
+    def materialize(self, publishable=True):
         """ 
             Get full text of the document compiled from chunks.
             Takes the current versions of all texts
-            or versions most recently tagged by a given tag.
+            or versions most recently tagged for publishing.
         """
-        if tag:
-            changes = [chunk.last_tagged(tag) for chunk in self]
+        if publishable:
+            changes = [chunk.publishable() for chunk in self]
         else:
             changes = [chunk.head for chunk in self]
         if None in changes:
@@ -160,7 +157,7 @@ class Chunk(dvcs_models.Document):
     book = models.ForeignKey(Book, editable=False)
     number = models.IntegerField()
     slug = models.SlugField()
-    comment = models.CharField(max_length=255)
+    comment = models.CharField(max_length=255, blank=True)
 
     class Meta:
         unique_together = [['book', 'number'], ['book', 'slug']]
@@ -180,11 +177,13 @@ class Chunk(dvcs_models.Document):
             return cls.objects.get(book__slug=slug, slug=chunk)
 
     def pretty_name(self):
-        return "%s, %s (%d/%d)" % (self.book.title, self.comment, 
-                self.number, len(self.book))
-
-    def publishable(self):
-        return self.last_tagged(Book.publish_tag())
+        title = self.book.title
+        if self.comment:
+            title += ", %s" % self.comment
+        count = len(self.book)
+        if count > 1:
+            title += " (%d/%d)" % (self.number, len(self.book))
+        return title
 
     def split(self, slug, comment='', creator=None):
         """ Create an empty chunk after this one """
@@ -194,6 +193,11 @@ class Chunk(dvcs_models.Document):
                 creator=creator, slug=slug, comment=comment)
         return new_chunk
 
+    def list_html(self):
+        _list_html = render_to_string('wiki/chunk_list_item.html',
+                {'chunk': self})
+        return mark_safe(_list_html)
+
     @staticmethod
     def listener_saved(sender, instance, created, **kwargs):
         if instance.book: