changeset 537:eac0ce5e137d

Added a "fix-mode" for the potd comment importer command such that it will only create comments if they don't already exist.
author Brian Neal <bgneal@gmail.com>
date Sat, 31 Dec 2011 22:21:58 +0000
parents 763eae227302
children 97593a955291
files gpp/legacy/management/commands/import_old_potd_comments.py
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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,