Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

modified migration 92 to delet votes that are attributed to lost comm…

…ents, answers or questions
  • Loading branch information...
commit bb505fa941d85ddf6f260bde8fae02f05ac7d02b 1 parent adcad7a
@evgenyfadeev evgenyfadeev authored
Showing with 13 additions and 9 deletions.
  1. +13 −9 askbot/migrations/0092_postize_vote_and_activity.py
View
22 askbot/migrations/0092_postize_vote_and_activity.py
@@ -15,15 +15,19 @@ def forwards(self, orm):
message = "Connecting votes to posts"
num_votes = orm.Vote.objects.count()
for v in ProgressBar(orm.Vote.objects.iterator(), num_votes, message):
- if (v.content_type.app_label, v.content_type.model) == ('askbot', 'question'):
- v.voted_post = orm.Post.objects.get(self_question__id=v.object_id)
- elif (v.content_type.app_label, v.content_type.model) == ('askbot', 'answer'):
- v.voted_post = orm.Post.objects.get(self_answer__id=v.object_id)
- elif (v.content_type.app_label, v.content_type.model) == ('askbot', 'comment'):
- v.voted_post = orm.Post.objects.get(self_comment__id=v.object_id)
- else:
- raise ValueError('Unknown vote subject!')
- v.save()
+ try:
+ if (v.content_type.app_label, v.content_type.model) == ('askbot', 'question'):
+ v.voted_post = orm.Post.objects.get(self_question__id=v.object_id)
+ elif (v.content_type.app_label, v.content_type.model) == ('askbot', 'answer'):
+ v.voted_post = orm.Post.objects.get(self_answer__id=v.object_id)
+ elif (v.content_type.app_label, v.content_type.model) == ('askbot', 'comment'):
+ v.voted_post = orm.Post.objects.get(self_comment__id=v.object_id)
+ else:
+ raise ValueError('Unknown vote subject!')
+ v.save()
+ except orm.Post.DoesNotExist:
+ print TERM_RED_BOLD, 'Post of type=%s, id=%s does not exist!!!' % (v.content_type.model, v.object_id)
+ v.delete()
###

0 comments on commit bb505fa

Please sign in to comment.
Something went wrong with that request. Please try again.