def import_comments(self, entry, comment_nodes):
        """
        Loops over comments nodes and import then
        in django_comments.
        """
        for comment_node in comment_nodes:
            is_pingback = comment_node.find(
                '{%s}comment_type' % WP_NS).text == PINGBACK
            is_trackback = comment_node.find(
                '{%s}comment_type' % WP_NS).text == TRACKBACK

            title = 'Comment #%s' % (comment_node.find(
                '{%s}comment_id' % WP_NS).text)
            self.write_out(' > %s... ' % title)

            content = comment_node.find(
                '{%s}comment_content' % WP_NS).text
            if not content:
                self.write_out(self.style.NOTICE('SKIPPED (unfilled)\n'))
                return

            submit_date = datetime.strptime(
                comment_node.find('{%s}comment_date_gmt' % WP_NS).text,
                '%Y-%m-%d %H:%M:%S')
            if settings.USE_TZ:
                submit_date = timezone.make_aware(submit_date,
                                                  pytz.timezone('GMT'))

            approvation = comment_node.find(
                '{%s}comment_approved' % WP_NS).text
            is_public = True
            is_removed = False
            if approvation != '1':
                is_removed = True
            if approvation == 'spam':
                is_public = False

            comment_dict = {
                'content_object': entry,
                'site': self.SITE,
                'user_name': comment_node.find(
                    '{%s}comment_author' % WP_NS).text[:50],
                'user_email': comment_node.find(
                    '{%s}comment_author_email' % WP_NS).text or '',
                'user_url': comment_node.find(
                    '{%s}comment_author_url' % WP_NS).text or '',
                'comment': content,
                'submit_date': submit_date,
                'ip_address': comment_node.find(
                    '{%s}comment_author_IP' % WP_NS).text or None,
                'is_public': is_public,
                'is_removed': is_removed, }
            comment = comments.get_model()(**comment_dict)
            comment.save()
            if is_pingback:
                comment.flags.create(
                    user=get_user_flagger(), flag=PINGBACK)
            if is_trackback:
                comment.flags.create(
                    user=get_user_flagger(), flag=TRACKBACK)

            self.write_out(self.style.ITEM('OK\n'))
        entry.comment_count = entry.comments.count()
        entry.pingback_count = entry.pingbacks.count()
        entry.trackback_count = entry.trackbacks.count()
        entry.save(force_update=True)
def import_comments ( self , entry , comment_nodes ) : for comment_node in comment_nodes : is_pingback = comment_node . find ( '{%s}comment_type' % WP_NS ) . text == PINGBACK is_trackback = comment_node . find ( '{%s}comment_type' % WP_NS ) . text == TRACKBACK title = 'Comment #%s' % ( comment_node . find ( '{%s}comment_id' % WP_NS ) . text ) self . write_out ( ' > %s... ' % title ) content = comment_node . find ( '{%s}comment_content' % WP_NS ) . text if not content : self . write_out ( self . style . NOTICE ( 'SKIPPED (unfilled)\n' ) ) return submit_date = datetime . strptime ( comment_node . find ( '{%s}comment_date_gmt' % WP_NS ) . text , '%Y-%m-%d %H:%M:%S' ) if settings . USE_TZ : submit_date = timezone . make_aware ( submit_date , pytz . timezone ( 'GMT' ) ) approvation = comment_node . find ( '{%s}comment_approved' % WP_NS ) . text is_public = True is_removed = False if approvation != '1' : is_removed = True if approvation == 'spam' : is_public = False comment_dict = { 'content_object' : entry , 'site' : self . SITE , 'user_name' : comment_node . find ( '{%s}comment_author' % WP_NS ) . text [ : 50 ] , 'user_email' : comment_node . find ( '{%s}comment_author_email' % WP_NS ) . text or '' , 'user_url' : comment_node . find ( '{%s}comment_author_url' % WP_NS ) . text or '' , 'comment' : content , 'submit_date' : submit_date , 'ip_address' : comment_node . find ( '{%s}comment_author_IP' % WP_NS ) . text or None , 'is_public' : is_public , 'is_removed' : is_removed , } comment = comments . get_model ( ) ( ** comment_dict ) comment . save ( ) if is_pingback : comment . flags . create ( user = get_user_flagger ( ) , flag = PINGBACK ) if is_trackback : comment . flags . create ( user = get_user_flagger ( ) , flag = TRACKBACK ) self . write_out ( self . style . ITEM ( 'OK\n' ) ) entry . comment_count = entry . comments . count ( ) entry . pingback_count = entry . pingbacks . count ( ) entry . trackback_count = entry . trackbacks . count ( ) entry . save ( force_update = True )
Loops over comments nodes and import then
        in django_comments.