예제 #1
0
def new_page(request):
    page = Page(
             request.form['title'],
             request.form['content'],
             request.form['excerpt'],
             category_id=request.form['cat_id'])
    page.status = 'draft'
    page.request_path = request.form['request_path']

    draft_tags = request.form['tags'].strip()
    if draft_tags:
        page.set_meta('draft_tags', draft_tags)

    page.save()

    return page
def import_pages(wp_pages, wp_tags_dict, wp_comments_dict, wp_categories_dict):
    def print_status(npk):
        if npk % 10 == 0: flush_write("(%d)" % npk)
        else:             flush_write('.')

    skip_paths = ['/sitemap', '/feedback', '/post-archive'] 
    skip_titles_re = re.compile('continuity')

    flush_write("Importing pages, comments, tags, urlmaps, blogpages and rss.\n")
    for npk, wp_page in enumerate1(wp_pages):
        print_status(npk)

        if skip_titles_re.search(wp_page.post_title):
            continue

        parsed = urlparse(wp_page.guid)
        path = parsed.path.rstrip('/')
        if path:
            if path in skip_paths:
                continue

        post_date=wp_page.post_date
        if post_date:
            post_date = post_date-timedelta(hours=3)            # 3 hr diff in my wp config
        post_modified=wp_page.post_modified
        if post_modified:
            post_modified = post_modified-timedelta(hours=3)    # same
        cm_page = Page(wp_page.post_title, wp_page.post_content, wp_page.post_excerpt, 
                       post_date, post_modified)
        if wp_page.post_status == 'draft':
            cm_page.status = 'draft'
        elif wp_page.post_status == 'publish':
            if wp_page.post_type == 'page':
                cm_page.status = 'page'
            elif wp_page.post_type == 'post':
                cm_page.status = 'post'
        import_page_views(wp_page, cm_page)
        import_page_tags(wp_page, cm_page, wp_tags_dict)
        import_page_category(wp_page, cm_page, wp_categories_dict)
        Revision(cm_page, 'first import').save()
        cm_page.save() # to generate cm_page.page_id
        import_page_comments(wp_page, cm_page.page_id, wp_comments_dict)
        generate_urlmap(wp_page, cm_page.page_id)
        insert_blogpage(wp_page, cm_page)
        insert_rss(wp_page, cm_page)
    flush_write("Done.\n")