예제 #1
0
    def import_nodetypes(self, feed_nodetypes):
        """Import nodetypes"""
        for feed_nodetype in feed_nodetypes:
            self.write_out('> %s... ' % feed_nodetype.title)
            creation_date = datetime(*feed_nodetype.date_parsed[:6])
            slug = slugify(feed_nodetype.title)[:255]

            if Nodetype.objects.filter(
                    creation_date__year=creation_date.year,
                    creation_date__month=creation_date.month,
                    creation_date__day=creation_date.day,
                    slug=slug):
                self.write_out(
                    self.style.NOTICE('SKIPPED (already imported)\n'))
                continue

            metatypes = self.import_metatypes(feed_nodetype)
            nodetype_dict = {
                'title': feed_nodetype.title[:255],
                'content': feed_nodetype.description,
                'excerpt': feed_nodetype.get('summary'),
                'status': PUBLISHED,
                'creation_date': creation_date,
                'start_publication': creation_date,
                'last_update': datetime.now(),
                'slug': slug
            }

            if not nodetype_dict['excerpt'] and self.auto_excerpt:
                nodetype_dict['excerpt'] = truncate_words(
                    strip_tags(feed_nodetype.description), 50)
            if self.metatype_tag:
                nodetype_dict['tags'] = self.import_tags(metatypes)

            nodetype = Nodetype(**nodetype_dict)
            nodetype.save()
            nodetype.metatypes.add(*metatypes)
            nodetype.sites.add(self.SITE)

            if self.default_author:
                nodetype.authors.add(self.default_author)
            elif feed_nodetype.get('author_detail'):
                try:
                    user = User.objects.create_user(
                        slugify(feed_nodetype.author_detail.get('name')),
                        feed_nodetype.author_detail.get('email', ''))
                except IntegrityError:
                    user = User.objects.get(username=slugify(
                        feed_nodetype.author_detail.get('name')))
                nodetype.authors.add(user)

            self.write_out(self.style.ITEM('OK\n'))
예제 #2
0
    def import_nodetypes(self, feed_nodetypes):
        """Import nodetypes"""
        for feed_nodetype in feed_nodetypes:
            self.write_out('> %s... ' % feed_nodetype.title)
            creation_date = datetime(*feed_nodetype.date_parsed[:6])
            slug = slugify(feed_nodetype.title)[:255]

            if Nodetype.objects.filter(creation_date__year=creation_date.year,
                                    creation_date__month=creation_date.month,
                                    creation_date__day=creation_date.day,
                                    slug=slug):
                self.write_out(self.style.NOTICE(
                    'SKIPPED (already imported)\n'))
                continue

            metatypes = self.import_metatypes(feed_nodetype)
            nodetype_dict = {'title': feed_nodetype.title[:255],
                          'content': feed_nodetype.description,
                          'excerpt': feed_nodetype.get('summary'),
                          'status': PUBLISHED,
                          'creation_date': creation_date,
                          'start_publication': creation_date,
                          'last_update': datetime.now(),
                          'slug': slug}

            if not nodetype_dict['excerpt'] and self.auto_excerpt:
                nodetype_dict['excerpt'] = truncate_words(
                    strip_tags(feed_nodetype.description), 50)
            if self.metatype_tag:
                nodetype_dict['tags'] = self.import_tags(metatypes)

            nodetype = Nodetype(**nodetype_dict)
            nodetype.save()
            nodetype.metatypes.add(*metatypes)
            nodetype.sites.add(self.SITE)

            if self.default_author:
                nodetype.authors.add(self.default_author)
            elif feed_nodetype.get('author_detail'):
                try:
                    user = User.objects.create_user(
                        slugify(feed_nodetype.author_detail.get('name')),
                        feed_nodetype.author_detail.get('email', ''))
                except IntegrityError:
                    user = User.objects.get(
                        username=slugify(feed_nodetype.author_detail.get('name')))
                nodetype.authors.add(user)

            self.write_out(self.style.ITEM('OK\n'))
예제 #3
0
파일: nodetype.py 프로젝트: PhiTheta/ISON
 def setUp(self):
     params = {
         'title': 'My nodetype',
         'content': 'My content',
         'slug': 'my-nodetype'
     }
     self.nodetype = Nodetype(**params)
     self.original_debug = settings.DEBUG
     self.original_rendering = models_settings.MARKUP_LANGUAGE
     settings.DEBUG = False
예제 #4
0
    def import_posts(self):
        metatype = self.get_metatype()
        self.write_out(self.style.STEP('- Importing nodetypes\n'))
        for post in self.blogger_manager.get_posts(self.blogger_blog_id):
            creation_date = convert_blogger_timestamp(post.published.text)
            status = DRAFT if is_draft(post) else PUBLISHED
            title = post.title.text or ''
            content = post.content.text or ''
            slug = slugify(post.title.text or get_post_id(post))[:255]
            try:
                nodetype = Nodetype.objects.get(creation_date=creation_date,
                                                slug=slug)
                output = self.style.NOTICE(
                    '> Skipped %s (already migrated)\n' % nodetype)
            except Nodetype.DoesNotExist:
                nodetype = Nodetype(status=status,
                                    title=title,
                                    content=content,
                                    creation_date=creation_date,
                                    slug=slug)
                if self.default_author:
                    nodetype.author = self.default_author
                nodetype.tags = ','.join(
                    [slugify(cat.term) for cat in post.metatype])
                nodetype.last_update = convert_blogger_timestamp(
                    post.updated.text)
                nodetype.save()
                nodetype.sites.add(self.SITE)
                nodetype.metatypes.add(metatype)
                nodetype.authors.add(self.default_author)
                try:
                    self.import_comments(nodetype, post)
                except gdata_service.RequestError:
                    # comments not available for this post
                    pass
                output = self.style.ITEM(
                    '> Migrated %s + %s comments\n' %
                    (nodetype.title, len(Comment.objects.for_model(nodetype))))

            self.write_out(output)
예제 #5
0
    def import_posts(self):
        metatype = self.get_metatype()
        self.write_out(self.style.STEP('- Importing nodetypes\n'))
        for post in self.blogger_manager.get_posts(self.blogger_blog_id):
            creation_date = convert_blogger_timestamp(post.published.text)
            status = DRAFT if is_draft(post) else PUBLISHED
            title = post.title.text or ''
            content = post.content.text or ''
            slug = slugify(post.title.text or get_post_id(post))[:255]
            try:
                nodetype = Nodetype.objects.get(creation_date=creation_date,
                                          slug=slug)
                output = self.style.NOTICE('> Skipped %s (already migrated)\n'
                    % nodetype)
            except Nodetype.DoesNotExist:
                nodetype = Nodetype(status=status, title=title, content=content,
                              creation_date=creation_date, slug=slug)
                if self.default_author:
                    nodetype.author = self.default_author
                nodetype.tags = ','.join([slugify(cat.term) for
                                       cat in post.metatype])
                nodetype.last_update = convert_blogger_timestamp(
                    post.updated.text)
                nodetype.save()
                nodetype.sites.add(self.SITE)
                nodetype.metatypes.add(metatype)
                nodetype.authors.add(self.default_author)
                try:
                    self.import_comments(nodetype, post)
                except gdata_service.RequestError:
                    # comments not available for this post
                    pass
                output = self.style.ITEM('> Migrated %s + %s comments\n'
                    % (nodetype.title, len(Comment.objects.for_model(nodetype))))

            self.write_out(output)