コード例 #1
0
    def callback(sxc):
        currid.inc()
        oc = orm.Node(
                id = currid.value,
                node_type = "comment",
                added_at = readTime(sxc['creationdate']),
                author_id = uidmap[sxc.get('userid', 1)],
                body = sxc['text'],
                parent_id = sxc.get('postid'),
                )

        if sxc.get('deletiondate', None):
            delete_action = orm.Action(
                    action_type = "delete",
                    user_id = uidmap[sxc['deletionuserid']],
                    action_date = readTime(sxc['deletiondate'])
                    )

            oc.author_id = uidmap[sxc['deletionuserid']]
            oc.save()

            delete_action.node = oc
            delete_action.save()

            add_post_state("deleted", oc, delete_action)
        else:
            oc.author_id = uidmap[sxc.get('userid', 1)]
            oc.save()

        create_action = orm.Action(
                action_type = "comment",
                user_id = oc.author_id,
                node = oc,
                action_date = oc.added_at
                )

        create_action.save()
        oc.save()

        posts.append(int(oc.id))
        mapping[int(sxc['id'])] = int(oc.id)
コード例 #2
0
    def callback(sxp):
        currid.inc()
        page = orm.Node(
                id = currid.value,
                node_type = "page",
                title = sxp['name'],
                body = b64decode(sxp['value']),
                extra = dbsafe_encode({
                'path': sxp['url'][1:],
                'mimetype': sxp['contenttype'],
                'template': (sxp['usemaster'] == "true") and "default" or "none",
                'render': "html",
                'sidebar': "",
                'sidebar_wrap': True,
                'sidebar_render': "html",
                'comments': False
                }),
                author_id = 1
                )

        page.save()
        registry[sxp['url'][1:]] = page.id

        create_action = orm.Action(
                action_type = "newpage",
                user_id = page.author_id,
                node = page
                )

        create_action.save()

        if sxp['active'] == "true" and sxp['contenttype'] == "text/html":
            pub_action = orm.Action(
                    action_type = "publish",
                    user_id = page.author_id,
                    node = page
                    )

            pub_action.save()
            add_post_state("published", page, pub_action)
コード例 #3
0
def node_import(row, is_merge, tag_merge, tags, nodes_map, users_map):

    ntags = []

    for t in row.get('tags').get_list('tag'):
        t = t.content()
        ntags.append(tags[tag_merge and tag_merge.get(t, t) or t])

    author = row.get('author').as_int()

    last_act = row.get('lastactivity')
    last_act_user = last_act.get('by').as_int(None)

    parent = row.get('parent').as_int(None)
    abs_parent = row.get('absparent').as_int(None)

    node = orm.Node(id=(not is_merge) and row.getc('id') or None,
                    node_type=row.getc('type'),
                    author_id=users_map.get(author, author),
                    added_at=row.get('date').as_datetime(),
                    parent_id=nodes_map.get(parent, parent),
                    abs_parent_id=nodes_map.get(abs_parent, abs_parent),
                    score=row.get('score').as_int(0),
                    last_activity_by_id=last_act_user
                    and users_map.get(last_act_user, last_act_user)
                    or last_act_user,
                    last_activity_at=last_act.get('at').as_datetime(None),
                    title=row.getc('title'),
                    body=row.getc('body'),
                    tagnames=" ".join([t.name for t in ntags]),
                    marked=row.get('marked').as_bool(),
                    extra_ref_id=row.get('extraRef').as_int(None),
                    extra_count=row.get('extraCount').as_int(0),
                    extra=row.get('extraData').as_pickled())

    node.save()

    nodes_map[row.get('id').as_int()] = node.id

    node.tags = ntags

    revisions = row.get('revisions')
    active = revisions.get_attr('active').as_int()

    if active == 0:
        active = orm.NodeRevision(
            author_id=node.author_id,
            body=row.getc('body'),
            node=node,
            revised_at=row.get('date').as_datetime(),
            revision=1,
            summary=_('Initial revision'),
            tagnames=" ".join([t.name for t in ntags]),
            title=row.getc('title'),
        )

        active.save()
    else:
        for r in revisions.get_list('revision'):
            author = row.get('author').as_int()

            rev = orm.NodeRevision(
                author_id=users_map.get(author, author),
                body=r.getc('body'),
                node=node,
                revised_at=r.get('date').as_datetime(),
                revision=r.get('number').as_int(),
                summary=r.getc('summary'),
                tagnames=" ".join(r.getc('tags').split(',')),
                title=r.getc('title'),
            )

            rev.save()
            if rev.revision == active:
                active = rev

    node.active_revision = active
    node.save()
コード例 #4
0
    def callback(sxpost):
        nodetype = (sxpost.get('posttypeid') == '1') and "nodetype" or "answer"

        post = orm.Node(
                node_type = nodetype,
                id = sxpost['id'],
                added_at = readTime(sxpost['creationdate']),
                body = sxpost['body'],
                score = sxpost.get('score', 0),
                author_id = sxpost.get('deletiondate', None) and 1 or uidmap[sxpost.get('owneruserid', 1)]
                )

        post.save()

        create_action = orm.Action(
                action_type = (nodetype == "nodetype") and "ask" or "answer",
                user_id = post.author_id,
                node = post,
                action_date = post.added_at
                )

        create_action.save()

        if sxpost.get('lasteditoruserid', None):
            revise_action = orm.Action(
                    action_type = "revise",
                    user_id = uidmap[sxpost.get('lasteditoruserid')],
                    node = post,
                    action_date = readTime(sxpost['lasteditdate']),
                    )

            revise_action.save()
            post.last_edited = revise_action

        if sxpost.get('communityowneddate', None):
            wikify_action = orm.Action(
                    action_type = "wikify",
                    user_id = 1,
                    node = post,
                    action_date = readTime(sxpost['communityowneddate'])
                    )

            wikify_action.save()
            add_post_state("wiki", post, wikify_action)

        if sxpost.get('lastactivityuserid', None):
            post.last_activity_by_id = uidmap[sxpost['lastactivityuserid']]
            post.last_activity_at = readTime(sxpost['lastactivitydate'])

        if sxpost.get('posttypeid') == '1': #question
            post.node_type = "question"
            post.title = sxpost['title']

            tagnames = sxpost['tags'].replace(u'ö', '-').replace(u'é', '').replace(u'à', '')
            post.tagnames = tagnames

            post.extra_count = sxpost.get('viewcount', 0)

            add_tags_to_post(post, tagmap)

        else:
            post.parent_id = sxpost['parentid']

        post.save()

        all.append(int(post.id))

        del post