Permalink
Browse files

Removed threadedcomments_ng, no longer needed

  • Loading branch information...
1 parent 1facd36 commit 469e62c8196db508f4af8019bcc839581ab8e7b7 @HonzaKral HonzaKral committed Apr 1, 2009
Showing with 0 additions and 165 deletions.
  1. 0 threadedcomments_ng/__init__.py
  2. +0 −88 threadedcomments_ng/models.py
  3. +0 −77 threadedcomments_ng/tests.py
No changes.
@@ -1,88 +0,0 @@
-from django.db import models
-from django.template import Template, Context
-
-
-DIGITS = 10
-SEPARATOR = '/'
-
-
-class CommentManager(models.Manager):
- def iter_tree(self):
- """
- iterate through nodes and adds some magic properties to each of them
- representing opening list of children and closing it
- """
- it = self.all().iterator()
-
- # get the first item, this will fail if no items !
- old = it.next()
-
- # first item starts a new thread
- old.open = 1
- last = set()
- for c in it:
- # if this comment has a parent, store it's last child for future reference
- if old.last_child_id:
- last.add(old.last_child_id)
-
- # this is the last child, mark it
- if c.pk in last:
- c.last = True
-
- # increase the level
- if c.level > old.level:
- c.open = 1
-
- else: # c.level <= old.level
- # close some levels
- old.close = range(old.level - c.level)
-
- # new thread
- if old.root != c.root:
- # close even the top level
- old.close.append(len(old.close))
- # and start a new thread
- c.open = 1
- # empty the last set
- last = set()
- # iterate
- yield old
- old = c
-
- old.close = range(old.level)
- yield old
-
-class Comment(models.Model):
- parent = models.ForeignKey('self', null=True, blank=True, related_name='child_set')
- last_child = models.ForeignKey('self', null=True, blank=True)
- tree_path = models.TextField(editable=False)
-
- objects = CommentManager()
-
- def __unicode__(self):
- return self.tree_path
-
- class Meta:
- ordering = ('tree_path',)
-
- @property
- def level(self):
- return len(self.tree_path.split(SEPARATOR))
-
- @property
- def root(self):
- return self.tree_path.split(SEPARATOR)[0]
-
- def save(self, force_update=False, force_insert=False):
- super(Comment, self).save(force_update=force_update, force_insert=force_insert)
-
- tp = ''
- if self.parent:
- tp = self.parent.tree_path + SEPARATOR
- self.parent.last_child = self
- self.__class__.objects.filter(pk=self.parent_id).update(last_child=self)
-
- tree_path = tp + '%%0%dd' % DIGITS % self.pk
- self.tree_path = tree_path
- self.__class__.objects.filter(pk=self.pk).update(tree_path=tree_path)
-
@@ -1,77 +0,0 @@
-from django.test import TestCase
-from django.template import loader
-
-from threadedcomments_ng.models import Comment
-
-class SimpleTest(TestCase):
- fixtures = ['simple_tree']
-
- def test_open_and_close_match(self):
- level = 0
- for x in Comment.objects.iter_tree():
- level += getattr(x, 'open', 0)
- self.assertEqual(x.level, level)
- level -= len(getattr(x, 'close', []))
-
- self.assertEqual(0, level)
-
- def test_last_flags_set_correctly_only_on_last_sibling(self):
- # construct the tree
- nodes = {}
- for x in Comment.objects.all():
- nodes[x.pk] = (x, [])
- if x.parent_id:
- nodes[x.parent_id][1].append(x.pk)
-
- # check all the cmments
- for x in Comment.objects.iter_tree():
- if getattr(x, 'last', False):
- # last comments have a parent
- self.assertTrue(x.parent_id)
- par, siblings = nodes[x.parent_id]
-
- # and ar last in their child list
- self.assertTrue( x.pk in siblings )
- self.assertEqual(len(siblings)-1, siblings.index(x.pk) )
-
- def test_template(self):
- output = loader.render_to_string('sample_tree.html', {'comment_list': Comment.objects.iter_tree() })
-
-
- self.assertEqual(expected_html, sanitize_html(output))
-
-def sanitize_html(html):
- return '\n'.join(( i.strip() for i in html.split('\n') if i.strip() != '' ))
-expected_html = sanitize_html('''
-<ul>
- <li>
- 0000000001
- <ul>
- <li>
- 0000000001/0000000002
- <ul>
- <li>
- 0000000001/0000000002/0000000003
- </li>
- <li class="last">
- 0000000001/0000000002/0000000005
- </li>
- </ul>
- </li>
- <li class="last">
- 0000000001/0000000004
- <ul>
- <li class="last">
- 0000000001/0000000004/0000000006
- </li>
- </ul>
- </li>
- </ul>
- </li>
-</ul>
-<ul>
- <li>
- 0000000007
- </li>
-</ul>
-''')

0 comments on commit 469e62c

Please sign in to comment.