示例#1
0
    def create_post(self, entry):

        channel_slug = CATEGORY_EFE.get(
            str(entry.entry_category_code).strip().zfill(8)
        )

        # log for debug
        if not channel_slug:
            msg = "{e.id} - {e.entry_category_code} not match category_efe \n"
            open("/tmp/debug_feeds.log", "a").write(
                msg.format(e=entry)
            )

        channel = self.get_channel_by_slug(channel_slug) or entry.channel

        self.verbose_print(channel_slug)
        self.verbose_print(entry.entry_category_code)

        slug = slugify(entry.entry_title + "-" + entry.pub_time_str)[:150]
        if Post.objects.filter(channel=channel,
                               slug=slug,
                               site=entry.site).exists():
            # slug = str(random.getrandbits(8)) + "-" + slug
            self.verbose_print("Post slug exists")
            # do not create duplicates
            return

        post = Post(
            title=entry.entry_title[:150],
            slug=slug,
            content=entry.entry_content,
            channel=channel,
            site=entry.site,
            user=entry.user,
            show_on_root_channel=True,
            published=True,
            hat=entry.hat,
            tags=entry.tags,
            date_insert=entry.entry_published_time,
            date_available=entry.entry_published_time
        )

        if self.feed.group:
            post.source = self.feed.group.name

        post.save()

        self.verbose_print(post.tags)
        entry.post_created = True
        entry.save()

        self.verbose_print(u"Post {p.id}- {p.title} - {p.slug} created".format(p=post))

        return post
示例#2
0
    def create_post(self, entry):

        channel_slug = CATEGORY_EFE.get(
            str(entry.entry_category_code).strip().zfill(8))

        # log for debug
        if not channel_slug:
            msg = "{e.id} - {e.entry_category_code} not match category_efe \n"
            open("/tmp/debug_feeds.log", "a").write(msg.format(e=entry))

        channel = self.get_channel_by_slug(channel_slug) or entry.channel

        self.verbose_print(channel_slug)
        self.verbose_print(entry.entry_category_code)

        slug = slugify(entry.entry_title + "-" + entry.pub_time_str)[:150]
        if Post.objects.filter(channel=channel, slug=slug,
                               site=entry.site).exists():
            # slug = str(random.getrandbits(8)) + "-" + slug
            self.verbose_print("Post slug exists")
            # do not create duplicates
            return

        post = Post(title=entry.entry_title[:150],
                    slug=slug,
                    content=entry.entry_content,
                    channel=channel,
                    site=entry.site,
                    user=entry.user,
                    show_on_root_channel=True,
                    published=True,
                    hat=entry.hat,
                    tags=entry.tags,
                    date_insert=entry.entry_published_time,
                    date_available=entry.entry_published_time)

        if self.feed.group:
            post.source = self.feed.group.name

        post.save()

        self.verbose_print(post.tags)
        entry.post_created = True
        entry.save()

        self.verbose_print(
            u"Post {p.id}- {p.title} - {p.slug} created".format(p=post))

        return post
示例#3
0
    def create_post(self, entry):
        # match category X channel
        channel_slug = CATEGORY_BRASIL.get(self.feed.source_url)
        channel = self.get_channel_by_slug(channel_slug) or entry.channel
        self.verbose_print(channel_slug)

        slug = slugify(entry.entry_title + "-" + entry.pub_time_str)[:150]
        if Post.objects.filter(channel=channel,
                               slug=slug,
                               site=entry.site).exists():
            # slug = str(random.getrandbits(8)) + "-" + slug
            self.verbose_print("Post slug exists")
            # do not create duplicates
            return

        post = Post(
            title=entry.entry_title[:150],
            slug=slug,
            content=entry.entry_content or entry.entry_description,
            channel=channel,
            site=entry.site,
            user=entry.user,
            show_on_root_channel=True,
            published=self.feed.publish_entries,
            # hat=entry.hat,
            tags=entry.tags,
            date_insert=entry.entry_published_time,
            date_available=entry.entry_published_time
        )

        if self.feed.group:
            post.source = self.feed.group.name

        post.save()

        entry.post_created = True
        entry.save()

        self.verbose_print(
            "Post {p.id}- {p.title} - {p.slug} created".format(p=post))

        return post
示例#4
0
    def create_post(self, entry):
        # match category X channel
        channel_slug = CATEGORY_BRASIL.get(self.feed.source_url)
        channel = self.get_channel_by_slug(channel_slug) or entry.channel
        self.verbose_print(channel_slug)

        slug = slugify(entry.entry_title + "-" + entry.pub_time_str)[:150]
        if Post.objects.filter(channel=channel, slug=slug,
                               site=entry.site).exists():
            # slug = str(random.getrandbits(8)) + "-" + slug
            self.verbose_print("Post slug exists")
            # do not create duplicates
            return

        post = Post(
            title=entry.entry_title[:150],
            slug=slug,
            content=entry.entry_content or entry.entry_description,
            channel=channel,
            site=entry.site,
            user=entry.user,
            show_on_root_channel=True,
            published=True,
            # hat=entry.hat,
            tags=entry.tags,
            date_insert=entry.entry_published_time,
            date_available=entry.entry_published_time)

        if self.feed.group:
            post.source = self.feed.group.name

        post.save()

        entry.post_created = True
        entry.save()

        self.verbose_print(
            u"Post {p.id}- {p.title} - {p.slug} created".format(p=post))

        return post
示例#5
0
def create_post(request, post_id):
    entry = Entry.objects.get(pk=int(post_id))
    post = Post(
        title=entry.entry_title,
        slug=slugify(entry.entry_title),
        content=entry.entry_content,
        channel=entry.entry_feed.channel or get_tmp_channel(request.user or entry.user),
        site=entry.site,
        user=request.user or entry.user,
        show_on_root_channel=True,
        published=False,
        hat=entry.hat,
    )

    try:
        post.save()
    except:
        post.slug = u"{0}-{1}".format(post.slug[:100], random.getrandbits(32))
        post.save()

    entry.post_created = True
    entry.save()

    return redirect('/admin/articles/post/{}/'.format(post.pk))