Пример #1
0
    def forwards(self, orm):
        k_count = orm.KeyValue.objects.count()
        print "\nConverting %d keyvalue objects:" % k_count
        progress = ProgressBar(k_count)

        for kv in orm.KeyValue.objects.all():
            try:
                o = loads(kv.value.encode('utf-8'))
            except:
                o = kv.value

            kv.value = dbsafe_encode(o, compress_object=True)
            kv.save()
            progress.update()

        print "\n...done\n"

        a_count = orm.Action.objects.count()
        print "\nConverting %d actions extra fields:" % a_count
        progress = ProgressBar(a_count)

        for a in orm.Action.objects.all():
            a.extra = dbsafe_encode(a.extra, compress_object=True)
            a.save()
            progress.update()

        print "\n...done\n"
Пример #2
0
    def forwards(self, orm):
        k_count = orm.KeyValue.objects.count()
        print "\nConverting %d keyvalue objects:" % k_count
        progress = ProgressBar(k_count)

        for kv in orm.KeyValue.objects.all():
            try:
                o = loads(kv.value.encode("utf-8"))
            except:
                o = kv.value

            kv.value = dbsafe_encode(o, compress_object=True)
            kv.save()
            progress.update()

        print "\n...done\n"

        a_count = orm.Action.objects.count()
        print "\nConverting %d actions extra fields:" % a_count
        progress = ProgressBar(a_count)

        for a in orm.Action.objects.all():
            a.extra = dbsafe_encode(a.extra, compress_object=True)
            a.save()
            progress.update()

        print "\n...done\n"
Пример #3
0
    def callback(set):
        if unicode(set['name']) in sx2osqa_set_map:
            try:
                kv = orm.KeyValue.objects.get(key=sx2osqa_set_map[set['name']])
                kv.value = dbsafe_encode(html_decode(set['value']))
            except:
                kv = orm.KeyValue(
                        key = sx2osqa_set_map[set['name']],
                        value = dbsafe_encode(html_decode(set['value']))
                        )

            kv.save()
        else:
            sx_unknown[set['name']] = html_decode(set['value'])
Пример #4
0
    def callback(set):
        if unicode(set['name']) in sx2osqa_set_map:
            try:
                kv = orm.KeyValue.objects.get(key=sx2osqa_set_map[set['name']])
                kv.value = dbsafe_encode(html_decode(set['value']))
            except:
                kv = orm.KeyValue(
                        key = sx2osqa_set_map[set['name']],
                        value = dbsafe_encode(html_decode(set['value']))
                        )

            kv.save()
        else:
            sx_unknown[set['name']] = html_decode(set['value'])
Пример #5
0
def pages_import(dump, currid):
    currid = IdIncrementer(currid)
    registry = {}
    #sx_pages = readTable(dump, "FlatPages")

    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)

    readTable(dump, "FlatPages", callback)

    kv = orm.KeyValue(key='STATIC_PAGE_REGISTRY', value=dbsafe_encode(registry))
    kv.save()
Пример #6
0
def pages_import(dump, currid):
    currid = IdIncrementer(currid)
    registry = {}
    #sx_pages = readTable(dump, "FlatPages")

    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)

    readTable(dump, "FlatPages", callback)

    kv = orm.KeyValue(key='STATIC_PAGE_REGISTRY', value=dbsafe_encode(registry))
    kv.save()
Пример #7
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)
Пример #8
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)
Пример #9
0
def static_import(dump):
#sx_sets = readTable(dump, "ThemeTextResources")
    sx_unknown = {}

    def callback(set):
        if unicode(set['name']) in sx2osqa_set_map:
            try:
                kv = orm.KeyValue.objects.get(key=sx2osqa_set_map[set['name']])
                kv.value = dbsafe_encode(html_decode(set['value']))
            except:
                kv = orm.KeyValue(
                        key = sx2osqa_set_map[set['name']],
                        value = dbsafe_encode(html_decode(set['value']))
                        )

            kv.save()
        else:
            sx_unknown[set['name']] = html_decode(set['value'])

    readTable(dump, "ThemeTextResources", callback)

    unknown = orm.KeyValue(key='SXIMPORT_UNKNOWN_SETS', value=dbsafe_encode(sx_unknown))
    unknown.save()
Пример #10
0
def static_import(dump):
#sx_sets = readTable(dump, "ThemeTextResources")
    sx_unknown = {}

    def callback(set):
        if unicode(set['name']) in sx2osqa_set_map:
            try:
                kv = orm.KeyValue.objects.get(key=sx2osqa_set_map[set['name']])
                kv.value = dbsafe_encode(html_decode(set['value']))
            except:
                kv = orm.KeyValue(
                        key = sx2osqa_set_map[set['name']],
                        value = dbsafe_encode(html_decode(set['value']))
                        )

            kv.save()
        else:
            sx_unknown[set['name']] = html_decode(set['value'])

    readTable(dump, "ThemeTextResources", callback)

    unknown = orm.KeyValue(key='SXIMPORT_UNKNOWN_SETS', value=dbsafe_encode(sx_unknown))
    unknown.save()
Пример #11
0
    def callback(sxv):
        action = orm.Action(
                user_id=uidmap[sxv['userid']],
                action_date = readTime(sxv['creationdate']),
                )

        if not int(sxv['postid']) in posts: return
        node = orm.Node.objects.get(id=sxv['postid'])
        action.node = node

        if sxv['votetypeid'] == '1':
            answer = node
            question = orm.Node.objects.get(id=answer.parent_id)

            action.action_type = "acceptanswer"
            action.save()

            answer.marked = True

            question.extra_ref_id = answer.id

            answer.save()
            question.save()

        elif sxv['votetypeid'] in ('2', '3'):
            if not (action.node.id, action.user_id) in user2vote:
                user2vote.append((action.node.id, action.user_id))

                action.action_type = (sxv['votetypeid'] == '2') and "voteup" or "votedown"
                action.save()

                ov = orm.Vote(
                        node_id = action.node.id,
                        user_id = action.user_id,
                        voted_at = action.action_date,
                        value = sxv['votetypeid'] == '2' and 1 or -1,
                        action = action
                        )
                ov.save()
            else:
                action.action_type = "unknown"
                action.save()

        elif sxv['votetypeid'] in ('4', '12', '13'):
            action.action_type = "flag"
            action.save()

            of = orm.Flag(
                    node = action.node,
                    user_id = action.user_id,
                    flagged_at = action.action_date,
                    reason = '',
                    action = action
                    )

            of.save()

        elif sxv['votetypeid'] == '5':
            action.action_type = "favorite"
            action.save()

        elif sxv['votetypeid'] == '6':
            action.action_type = "close"
            action.extra = dbsafe_encode(close_reasons[sxv['comment']])
            action.save()

            node.marked = True
            node.save()

        elif sxv['votetypeid'] == '7':
            action.action_type = "unknown"
            action.save()

            node.marked = False
            node.save()

            remove_post_state("closed", node)

        elif sxv['votetypeid'] == '10':
            action.action_type = "delete"
            action.save()

        elif sxv['votetypeid'] == '11':
            action.action_type = "unknown"
            action.save()

            remove_post_state("deleted", node)

        else:
            action.action_type = "unknown"
            action.save()

        if sxv.get('targetrepchange', None):
            rep = orm.ActionRepute(
                    action = action,
                    date = action.action_date,
                    user_id = uidmap[sxv['targetuserid']],
                    value = int(sxv['targetrepchange'])
                    )

            rep.save()

        if sxv.get('voterrepchange', None):
            rep = orm.ActionRepute(
                    action = action,
                    date = action.action_date,
                    user_id = uidmap[sxv['userid']],
                    value = int(sxv['voterrepchange'])
                    )

            rep.save()

        if action.action_type in ("acceptanswer", "delete", "close"):
            state = {"acceptanswer": "accepted", "delete": "deleted", "close": "closed"}[action.action_type]
            add_post_state(state, node, action)
Пример #12
0
    def callback(sxv):
        action = orm.Action(
                user_id=uidmap[sxv['userid']],
                action_date = readTime(sxv['creationdate']),
                )

        if not int(sxv['postid']) in posts: return
        node = orm.Node.objects.get(id=sxv['postid'])
        action.node = node

        if sxv['votetypeid'] == '1':
            answer = node
            question = orm.Node.objects.get(id=answer.parent_id)

            action.action_type = "acceptanswer"
            action.save()

            answer.marked = True

            question.extra_ref_id = answer.id

            answer.save()
            question.save()

        elif sxv['votetypeid'] in ('2', '3'):
            if not (action.node.id, action.user_id) in user2vote:
                user2vote.append((action.node.id, action.user_id))

                action.action_type = (sxv['votetypeid'] == '2') and "voteup" or "votedown"
                action.save()

                ov = orm.Vote(
                        node_id = action.node.id,
                        user_id = action.user_id,
                        voted_at = action.action_date,
                        value = sxv['votetypeid'] == '2' and 1 or -1,
                        action = action
                        )
                ov.save()
            else:
                action.action_type = "unknown"
                action.save()

        elif sxv['votetypeid'] in ('4', '12', '13'):
            action.action_type = "flag"
            action.save()

            of = orm.Flag(
                    node = action.node,
                    user_id = action.user_id,
                    flagged_at = action.action_date,
                    reason = '',
                    action = action
                    )

            of.save()

        elif sxv['votetypeid'] == '5':
            action.action_type = "favorite"
            action.save()

        elif sxv['votetypeid'] == '6':
            action.action_type = "close"
            action.extra = dbsafe_encode(close_reasons[sxv['comment']])
            action.save()

            node.marked = True
            node.save()

        elif sxv['votetypeid'] == '7':
            action.action_type = "unknown"
            action.save()

            node.marked = False
            node.save()

            remove_post_state("closed", node)

        elif sxv['votetypeid'] == '10':
            action.action_type = "delete"
            action.save()

        elif sxv['votetypeid'] == '11':
            action.action_type = "unknown"
            action.save()

            remove_post_state("deleted", node)

        else:
            action.action_type = "unknown"
            action.save()

        if sxv.get('targetrepchange', None):
            rep = orm.ActionRepute(
                    action = action,
                    date = action.action_date,
                    user_id = uidmap[sxv['targetuserid']],
                    value = int(sxv['targetrepchange'])
                    )

            rep.save()

        if sxv.get('voterrepchange', None):
            rep = orm.ActionRepute(
                    action = action,
                    date = action.action_date,
                    user_id = uidmap[sxv['userid']],
                    value = int(sxv['voterrepchange'])
                    )

            rep.save()

        if action.action_type in ("acceptanswer", "delete", "close"):
            state = {"acceptanswer": "accepted", "delete": "deleted", "close": "closed"}[action.action_type]
            add_post_state(state, node, action)
Пример #13
0
def post_vote_import(dump, uidmap, posts):
    votes = readTable(dump, "Posts2Votes")
    close_reasons = dict([(r['id'], r['name']) for r in readTable(dump, "CloseReasons")])

    user2vote = []

    for sxv in votes:
        action = orm.Action(
            user_id=uidmap[sxv['userid']],
            action_date = readTime(sxv['creationdate']),
        )

        node = posts.get(int(sxv['postid']), None)
        if not node: continue
        action.node = node

        if sxv['votetypeid'] == '1':
            answer = node
            question = posts.get(int(answer.parent_id), None)

            action.action_type = "acceptanswer"
            action.save()

            answer.marked = True
            answer.extra_action = action

            question.extra_ref_id = answer.id

            answer.save()
            question.save()

        elif sxv['votetypeid'] in ('2', '3'):
            if not (action.node.id, action.user_id) in user2vote:
                user2vote.append((action.node.id, action.user_id))

                action.action_type = (sxv['votetypeid'] == '2') and "voteup" or "votedown"
                action.save()

                ov = orm.Vote(
                    node_id = action.node.id,
                    user_id = action.user_id,
                    voted_at = action.action_date,
                    value = sxv['votetypeid'] == '2' and 1 or -1,
                    action = action
                )
                ov.save()
            else:
                action.action_type = "unknown"
                action.save()

        elif sxv['votetypeid'] in ('4', '12', '13'):
            action.action_type = "flag"
            action.save()

            of = orm.Flag(
                node = action.node,
                user_id = action.user_id,
                flagged_at = action.action_date,
                reason = '',
                action = action
            )

            of.save()

        elif sxv['votetypeid'] == '5':
            action.action_type = "favorite"
            action.save()

        elif sxv['votetypeid'] == '6':
            action.action_type = "close"
            action.extra = dbsafe_encode(close_reasons[sxv['comment']])
            action.save()

            node.marked = True
            node.extra_action = action
            node.save()

        elif sxv['votetypeid'] == '7':
            action.action_type = "unknown"
            action.save()
            
            node.marked = False
            node.extra_action = None
            node.save()

        elif sxv['votetypeid'] == '10':
            action.action_type = "delete"
            action.save()

            node.deleted = action
            node.save()

        elif sxv['votetypeid'] == '11':
            action.action_type = "unknown"
            action.save()

            node.deleted = None
            node.save()

        else:
            action.action_type = "unknown"
            action.save()


        if sxv.get('targetrepchange', None):
            rep = orm.ActionRepute(
                action = action,
                date = action.action_date,
                user_id = uidmap[sxv['targetuserid']],
                value = int(sxv['targetrepchange'])
            )

            rep.save()

        if sxv.get('voterrepchange', None):
            rep = orm.ActionRepute(
                action = action,
                date = action.action_date,
                user_id = uidmap[sxv['userid']],
                value = int(sxv['voterrepchange'])
            )

            rep.save()