def create_and_activate_revision(post): rev = orm.NodeRevision( author_id = post.author_id, body = post.body, node_id = post.id, revised_at = post.added_at, revision = 1, summary = 'Initial revision', tagnames = post.tagnames, title = post.title, ) rev.save() post.active_revision_id = rev.id post.save()
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()