diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-03-09 01:20:36 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-03-09 01:20:36 -0500 |
commit | c813ea591905e90512f2f04c68d251da3eb77eaa (patch) | |
tree | 10d27c79d5b6ebe253c4f74517a95366f35719f7 /stackexchange/management/commands/load_stackexchange.py | |
parent | 1113085c74c7fec5012993a567c144fb84be6913 (diff) | |
download | askbot-c813ea591905e90512f2f04c68d251da3eb77eaa.tar.gz askbot-c813ea591905e90512f2f04c68d251da3eb77eaa.tar.bz2 askbot-c813ea591905e90512f2f04c68d251da3eb77eaa.zip |
in the middle of loading votes
Diffstat (limited to 'stackexchange/management/commands/load_stackexchange.py')
-rw-r--r-- | stackexchange/management/commands/load_stackexchange.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/stackexchange/management/commands/load_stackexchange.py b/stackexchange/management/commands/load_stackexchange.py index d2262b8d..5673b9f0 100644 --- a/stackexchange/management/commands/load_stackexchange.py +++ b/stackexchange/management/commands/load_stackexchange.py @@ -41,13 +41,24 @@ class X(object):# osqa_supported_id_providers = ( 'google','yahoo','aol','myopenid', - 'flickr','technorati',#todo: typo in code openidauth/authentication.py ! + 'flickr','technorati', 'wordpress','blogger','livejournal', 'claimid','vidoop','verisign', 'openidurl','facebook','local', 'twitter' #oauth is not on this list, b/c it has no own url ) + #map SE VoteType -> osqa.User vote method + #created methods with the same call structure in osqa.User + #User.<vote_method>(post, timestamp=None, cancel=False) + vote_actions = { + 'UpMod':'upvote', + 'DownMod':'downvote', + 'AcceptedByOriginator':'accept_answer', + 'Offensive','flag_post', + 'Favorite','toggle_favorite_question', + } + #these modes cannot be mixed exclusive_revision_modes = ( 'initial','edit','lock','unlock', @@ -82,6 +93,22 @@ class X(object):# 'Post Migrated':'migrate', 'Question Merged':'merge', } + @classmethod + def get_post(cls, se_post): + #todo: fix this hack - either in-memory id association table + #or use database to store these associations + post_type = se_post.post_type.name + if post_type == 'Question': + return osqa.Question.objects.get(id=QUESTION[se_post.id].id) + elif post_type == 'Answer': + return osqa.Answer.objects.get(id=ANSWER[se_post.id].id) + else: + raise Exception('unknown post type %s' % post_type) + + @classmethod + def get_user(cls, se_user): + #todo: same as get_post + return osqa.User.objects.get(id=USER[se_user.id].id) @classmethod def get_post_revision_group_types(cls, rev_group): @@ -212,6 +239,7 @@ class Command(BaseCommand): #transfer data into OSQA tables self.transfer_users() self.transfer_question_and_answer_activity() + self.transfer_question_view_counts() self.transfer_comments() self.transfer_badges() self.transfer_votes() @@ -433,8 +461,26 @@ class Command(BaseCommand): self._cleanup_badges() pass + def transfer_question_view_counts(self): + for se_q in se.Post.objects.filter(post_type__name='Question'): + q = X.get_post(se_q) + q.view_count = se_q.view_count + q.save() + + def transfer_votes(self): - pass + for v in se.Post2Vote.objects.all(): + vote_type = v.vote_type.name + if not vote_type in X.vote_actions: + continue + + u = X.get_user(v.user) + p = X.get_post(v.post) + m = X.vote_actions[vote_type] + vote_method = getattr(osqa.User, m['on']) + vote_method(u, p, timestamp = v.creation_date) + if v.deletion_date: + vote_method(u, p, timestamp = v.deletion_date, cancel=True) def transfer_favorites(self): pass |