# HG changeset patch # User Brian Neal # Date 1325370118 0 # Node ID eac0ce5e137d00f4ebd5e8d1dd59d86e79a890e6 # Parent 763eae2273023e5f4f2d03cf34f36b57d0a2a64d Added a "fix-mode" for the potd comment importer command such that it will only create comments if they don't already exist. diff -r 763eae227302 -r eac0ce5e137d gpp/legacy/management/commands/import_old_potd_comments.py --- a/gpp/legacy/management/commands/import_old_potd_comments.py Sat Dec 31 22:13:30 2011 +0000 +++ b/gpp/legacy/management/commands/import_old_potd_comments.py Sat Dec 31 22:21:58 2011 +0000 @@ -29,6 +29,8 @@ option_list = LabelCommand.option_list + ( optparse.make_option("-p", "--progress", action="store_true", help="Output a . after every 20 items to show progress"), + optparse.make_option("--fix-mode", action="store_true", + help="Only create comments if they don't exist already"), ) md_writer = MarkdownWriter() @@ -39,6 +41,7 @@ """ self.show_progress = options.get('progress') + self.fix_mode = options.get('fix_mode') self.users = {} try: @@ -67,6 +70,16 @@ the row and save it in the database. """ + comment_id = int(row['cid']) + ID_OFFSET + + if self.fix_mode: + try: + c = Comment.objects.get(pk=comment_id) + except Comment.DoesNotExist: + pass + else: + return + try: user = self._get_user(row['username'].decode('latin-1')) except User.DoesNotExist: @@ -83,7 +96,7 @@ return comment = Comment( - id=int(row['cid']) + ID_OFFSET, + id=comment_id, content_type=ContentType.objects.get_for_model(photo), object_id=photo.id, user=user,