示例#1
0
def run(request, xml):
    tree = BeautifulStoneSoup(xml)
    for item in tree.findAll('item'):
        if item.find('wp:status').text == 'publish':
            if item.find('wp:post_type').text == 'post':
                title = item.find("title").text
                author = request.user
                article = articles_utils.article_create(title=title, author=author)
                article.rendered_pile = item.find("content:encoded").text
                article.is_published = True
                created = item.find('wp:post_date').text
                article.created = datetime.strptime(created, "%Y-%m-%d %H:%M:%S")
                article.updated = datetime.strptime(created, "%Y-%m-%d %H:%M:%S")
                if item.find('wp:comment_status').text == 'open':
                    article.enable_comments = True
                # article.pile.scraps()[0].delete()
                #                 scrap = scraps_utils.scrap_create("text-wysiwyg")
                #                 scrap_data = scrap.data_load()
                #                 scrap_data['content'] = article.rendered_pile
                #                 scrap.data_dump(scrap_data)
                #                 scrap.title = ""
                #                 scrap.is_enabled = True
                #                 scrap.save()
                #                 scraps_utils.scrap_repile(scrap.id, article.pile.id)
                article.save()
示例#2
0
def article_create(request, is_page=False):
    if request.method == 'POST':
        article_create_form = CreateArticleForm(request.POST)
        if article_create_form.is_valid():
            article_title = article_create_form.cleaned_data['title']
            article = utils.article_create(title=article_title, author=request.user, is_page=is_page)
            if is_page:
                return redirect('articles_admin_page_scrap_edit', article_id=article.id, scrap_id=article.pile.scraps()[0].id)
            else:
                return redirect('articles_admin_article_scrap_edit', article_id=article.id, scrap_id=article.pile.scraps()[0].id)
    if is_page:
        return redirect('articles_admin_pages_manage')
    else:
        return redirect('articles_admin_articles_manage')