def migrate_legacy_comments(): from ella_flatcomments.register import comment_posted CommentModel = comments.get_model() if not CommentModel._meta.installed: return migrated_id = FlatComment.objects.all().aggregate( Max('id'))['id__max'] or 0 cnt = 0 for c in CommentModel.objects.exclude( user__isnull=True).order_by('id').filter( id__gt=migrated_id).iterator(): fc = FlatComment( id=c.pk, site_id=c.site_id, content_type_id=c.content_type_id, object_id=c.object_pk, submit_date=c.submit_date, user=c.user, comment=c.comment, is_public=c.is_public and not c.is_removed, ) fc.save(force_insert=True) if fc.is_public: redis.lpush(fc._comment_list()._key, c.pk) comment_posted(fc) cnt += 1 return cnt
def migrate_legacy_comments(): from ella_flatcomments.register import comment_posted CommentModel = comments.get_model() if not CommentModel._meta.installed: return migrated_id = FlatComment.objects.all().aggregate(Max('id'))['id__max'] or 0 cnt = 0 for c in CommentModel.objects.exclude(user__isnull=True).order_by('id').filter(id__gt=migrated_id).iterator(): fc = FlatComment( id=c.pk, site_id=c.site_id, content_type_id=c.content_type_id, object_id=c.object_pk, submit_date=c.submit_date, user=c.user, comment=c.comment, is_public=c.is_public and not c.is_removed, ) fc.save(force_insert=True) if fc.is_public: redis.lpush(fc._comment_list()._key, c.pk) comment_posted(fc) cnt += 1 return cnt
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 _get_comment(self, commit=False, **kwargs): defaults = dict(content_type=self.content_type, object_id=self.content_object.pk, user=self.user, comment='') defaults.update(kwargs) c = FlatComment(**defaults) if commit: c.save() return c
def _get_comment(self, commit=False, **kwargs): defaults = dict( content_type=self.content_type, object_id=self.content_object.pk, user=self.user, comment='' ) defaults.update(kwargs) c = FlatComment(**defaults) if commit: c.save() return c
def migrate_legacy_comments(): CommentModel = comments.get_model() if not CommentModel._meta.installed: return cnt = 0 for c in CommentModel.objects.exclude(user__isnull=True).order_by("submit_date").iterator(): fc = FlatComment( site_id=c.site_id, content_type_id=c.content_type_id, object_id=c.object_pk, submit_date=c.submit_date, user=c.user, comment=c.comment, is_public=c.is_public and not c.is_removed, ) fc.post() cnt += 1 return cnt
def migrate_legacy_comments(): CommentModel = comments.get_model() if not CommentModel._meta.installed: return cnt = 0 for c in CommentModel.objects.exclude(user__isnull=True).order_by('submit_date').iterator(): fc = FlatComment( site_id=c.site_id, content_type_id=c.content_type_id, object_id=c.object_pk, submit_date=c.submit_date, user=c.user, comment=c.comment, is_public=c.is_public and not c.is_removed, ) fc.post() cnt += 1 return cnt
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()