def add_publishable(cls, category, publishable, score=None, pipe=None, commit=True): if score is None: score = CommentList(publishable.content_type, publishable.pk).count() # no comments yet, pass if not score: return pipe return super(MostCommentedListingHandler, cls).add_publishable(category, publishable, score, pipe=pipe, commit=commit)
def handle_noargs(self, **kwargs): CommentModel = comments.get_model() for c in CommentModel.objects.exclude( user__isnull=True).sort('submit_date').iterator(): fc = FlatComment(site_id=c.site_id, content_type_id=c.content_type_id, object_id=c.object_pk, user_id=c.user_id, submit_date=c.submit_date, content=c.comment, is_public=c.is_public and not c.is_removed) if fc.is_public: cl = CommentList(fc.content_type, fc.object_id) cl.post_comment(fc) sys.stdout.write('.') sys.stdout.flush() else: fc.save(force_insert=True) sys.stdout.write('X') sys.stdout.flush() sys.stdout.write('DONE\n') sys.stdout.flush()
def test_reversed_slice(self): comment_list = CommentList(self.content_type, 1, reversed=True) clist = range(11) tools.assert_equals(clist[0:4], comment_list[0:4]) tools.assert_equals(clist[2:6], comment_list[2:6]) tools.assert_equals(clist[2:60], comment_list[2:60]) tools.assert_equals(clist[3:], comment_list[3:])
def get_comment_list(self, context): reversed = show_reversed(context['request']) if isinstance(self.lookup, template.Variable): return CommentList.for_object(self.lookup.resolve(context), reversed) ct, obj_pk = map(lambda v: v.resolve(context), self.lookup) if isinstance(ct, int): ct = ContentType.objects.get_for_id(ct) return CommentList(ct, obj_pk, reversed)
def test_reversed_getitem(self): comment_list = CommentList(self.content_type, 1, reversed=True) for i, c in zip(xrange(11), xrange(11)): tools.assert_equals(c, comment_list[i])