]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/migrations/0018_comments_to_node.py
#OSQA-603, fixing the badges count calculation error. After the update of the count...
[osqa.git] / forum / migrations / 0018_comments_to_node.py
index 1b10aee18b7f080484fadff8a1bc6b5d920bfc63..808bb0e191ac10c6cf3ae3e761aa725df5e6054a 100644 (file)
@@ -12,6 +12,8 @@ class Migration(DataMigration):
         print "\nConverting %d comments:" % c_count\r
         progress = ProgressBar(c_count)\r
 \r
+        id_map = {}\r
+\r
         for c in orm.Comment.objects.all():\r
             node = orm.Node(\r
                 node_type='comment',\r
@@ -31,6 +33,8 @@ class Migration(DataMigration):
             )\r
             node.save()\r
 \r
+            id_map[c.id] = node\r
+\r
             revision = orm.NodeRevision(\r
                 summary="Initial revsion",\r
                 revision=1,\r
@@ -59,6 +63,26 @@ class Migration(DataMigration):
             progress.update()\r
 \r
         print "\n...done\n"\r
+\r
+        ctype = orm['contenttypes.ContentType'].objects.get(name="comment").id\r
+        ntype = orm['contenttypes.ContentType'].objects.get(name="node").id\r
+\r
+        #Converting activity\r
+        activities = orm.Activity.objects.filter(content_type__id=ctype)\r
+        activity_count = activities.count()\r
+        print "Converting %d activity references:" % activity_count\r
+        progress = ProgressBar(activity_count)\r
+\r
+        for a in activities:\r
+            node = id_map.get(a.object_id, None)\r
+            if node:\r
+                a.content_type_id = ntype\r
+                a.object_id = node.id\r
+                a.save()\r
+\r
+            progress.update()\r
+\r
+        print "\n...done\n"\r
     \r
     \r
     def backwards(self, orm):\r