Commits

Adam Knight committed 7920de6

Some Django 1.4 fixes

  • Participants
  • Parent commits 74487f9

Comments (0)

Files changed (2)

drupal_support/management/commands/convertdrupal.py

     return result
 
 class Command(BaseCommand):
-    # option_list = BaseCommand.option_list + (
+    option_list = BaseCommand.option_list + (
     #     make_option('--format', default='json', dest='format', help='Specifies the output serialization format for fixtures.'),
     #     make_option('--indent', default=None, dest='indent', type='int', help='Specifies the indent level to use when pretty-printing output'),
     #     make_option('-e', '--exclude', dest='exclude',action='append', default=[], help='App to exclude (use multiple --exclude to exclude multiple apps).'),
     #     make_option('-v', '--verbose', dest='verbose', action="store", default="0", type="choice", choices=['0','1','2'], help='Verbose output'),
-    # )
+        make_option(None,'--comments', dest='comments', action="store_true", default=True, help="Import comments (default)."),
+        make_option(None,'--no-comments', dest='comments', action="store_false", default=True, help="Do not import comments."),
+    )
     help = 'Convert Drupal 6 tables to SP objects.    The tables must be in the same database as SP.'
     # args = '[appname ...]'
     
     def handle(self, *app_labels, **options):
+	import_comments = options.get('comments', True)
         show_traceback = options.get('traceback', False)
         verbose = int(options.get('verbosity', 0))
         debug = (verbose == 2)
                         )
                         ch.save()
                         
-                        if debug: print " Added revision %s" % (ch.date_created)
+                        if debug: print " Added revision %s" % (ch.date_created,)
                 
                 # Bring over the comments
-                comments = self.get_comments_for_node(node)
+                if import_comments:
+                    comments = self.get_comments_for_node(node)
+                else:
+                    comments = []
+                
                 # if debug: print "  Comments:", comments.count()
                 for comment in comments:
                     if debug: print "  Importing comment: ", comment.thread, comment.subject
         But, that's okay.  Drupal required MySQL anyway, so do the conversion on a copy of the DB there, then
         migrate to whatever else you want to use.
         '''
-        # from django.db import connection
-        # cursor = connection.cursor()
-        
-        # cursor.execute("SELECT cid FROM comments as c WHERE nid = %s ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))", [node.nid])
-        # rows = cursor.fetchall()
-        # ids = [c[0] for c in rows]
-        # comments = DrupalComment.objects.filter(pk__in=ids)
-        raw_comments = DrupalComment.objects.using('drupal').raw("SELECT * FROM comments WHERE nid = %s ORDER BY SUBSTRING(comments.thread, 1, (LENGTH(comments.thread) - 1))", [node.nid])
+        raw_comments = DrupalComment.objects.db_manager('drupal').raw("SELECT * FROM comments WHERE nid = %s ORDER BY SUBSTRING(comments.thread, 1, (LENGTH(comments.thread) - 1))", [node.nid])
         comments = []
         for comment in raw_comments:
             comments.append(comment)
         ordering = ['-date_created', 'content_type', 'object_id']
     
     def __unicode__(self):
-        return "%s: %s" % (self.owner, self.field_name)
+        return u"%s: %s" % (self.owner, self.field_name)
     
     @classmethod
     def history(owner, field):